Skip to content

Instantly share code, notes, and snippets.

@lispm
Last active February 4, 2019 09:31
Show Gist options
  • Select an option

  • Save lispm/5366ec74b6f7ac358063a6adba217bf7 to your computer and use it in GitHub Desktop.

Select an option

Save lispm/5366ec74b6f7ac358063a6adba217bf7 to your computer and use it in GitHub Desktop.
(defun make (pts &key closed)
(let ((n (length pts)))
(if (< n 4) (error "must have at least 4 pts."))
(let ((apts (make-dfloat-array n)))
(loop
for p in pts
for i from 0
do
(destructuring-bind (x y)
p
(setf (aref apts i 0) x)
(setf (aref apts i 1) y)))
(make-bzspl :n n
:pts apts
:select-pts (if closed
#'-select-pts-closed
#'-select-pts-open)
:get-seg (if closed
#'-get-seg-closed
#'-get-seg-open)
:closed closed))))
; &aux arguments help removing one level of LET indentation
; ASSERT can be used for the check
; LOOP: can destructure
; LOOP: if variables are independent, use AND instead of FOR
; SETF allows multiple forms
(defun make (pts &key closed &aux (n (length pts)))
(assert (>= n 4) (n) "must have at least 4 pts. has ~a." n)
(let ((apts (make-dfloat-array n)))
(loop for (x y) in pts and i from 0 do
(setf (aref apts i 0) x
(aref apts i 1) y))
(make-bzspl :n n
:pts apts
:select-pts (if closed
#'-select-pts-closed
#'-select-pts-open)
:get-seg (if closed
#'-get-seg-closed
#'-get-seg-open)
:closed closed)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment