3
(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-rectanglecarpetは構造体です。

このメソッドが次のように呼び出された場合:

(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が適用可能な引数のみを指定するにはどうすればよいですか?

4

1 に答える 1

8

carpetクラスと、を含むarglistがある場合image-rectangle、引数はこれらのクラスまたはそのサブクラスの方が適切です。NIL引数がクラスであると宣言されている場合、を渡すことはできませんcarpet

したがって(if this、意味がありません。カーペットオブジェクトに合格し、他に合格できない場合、テストthisは常に真になります。

NILオブジェクトと長方形のメソッドを記述したい場合は、クラスNULLを使用できます。

(defmethod carpet-append ((this null) (rect image-rectangle))
   ...)

CLOSにはORやANDのようなクラスコンビネータがないため、それぞれの場合にメソッドを作成する必要があります。

于 2013-01-04T17:15:29.073 に答える