(defmethod carpet-append ((this carpet) (rect image-rectangle))
(destructuring-bind (rect-width . rect-height)
(rectangle-size rect)
(destructuring-bind (bitmap-width . bitmap-height)
(carpet-size this)
(if this
(iter:iter
(iter:with min-area = (* (+ bitmap-width rect-width)
(+ bitmap-height rect-height)))
(iter:with min-pos = nil)
(iter:for pos in (awailable-positions this))
(iter:for test-area = (try-fit rect pos (carpet-bitmap this)))
(when (and test-area (< test-area min-area))
(setf min-pos pos))
(iter:finally
(let ((new-carpet
(make-carpet
:bitmap (make-array
(list (+ (car min-pos) rect-width)
(+ (cdr min-pos) rect-height))
:element-type 'bit)
:rectangles (cons rect (carpet-rectangles this)))))
(copy-bitmap-state this new-carpet)
(setf (rectangle-position rect) min-pos)
(place-image new-carpet rect)
(return new-carpet))))
(make-carpet
:bitmap (make-array
(list rect-width rect-height)
:element-type 'bit)
:rectangles (list rect))))))
image-rectangle
并且carpet
是结构。
当这个方法被这样调用时:
(carpet-append
nil
#s(image-rectangle
:position (0 . 0)
:size (48 . 76)
:file "/home/wvxvw/projects/spritesheet/test-images/test-0.png"))
我得到一个:
#<SIMPLE-ERROR "~@<There is no applicable method for the generic function ~2I~_~S~
~I~_when called with arguments ~2I~_~S.~:>"
它是这样的吗?也许有一些方法可以让它接受nil
作为一个论点?我将如何指定只有类型nil
和carpet
适用的参数?