Advertisement
Guest User

box.lisp

a guest
Jun 25th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.27 KB | None | 0 0
  1.  
  2.  
  3. (defclass box ()
  4.   ((location :accessor location :initarg :location :initform (vector 0 0))
  5.    (dimensions :accessor dimensions :initarg :dimensions :initform (vector 1 1))))
  6.  
  7. (defmethod x ((b box))
  8.   (aref (location b) 0))
  9.  
  10. (defmethod y ((b box))
  11.   (aref (location b) 1))
  12.  
  13. (defmethod (setf x) (new-val (b box))
  14.   (setf (aref (location b) 0) new-value))
  15.  
  16. (defmethod (setf y) (new-val (b box))
  17.   (setf (aref (location b) 1) new-value))
  18.  
  19. (defmethod width ((b box))
  20.   (aref (dimensions b) 0))
  21.  
  22. (defmethod height ((b box))
  23.   (aref (dimensions b) 1))
  24.  
  25. (defmethod (setf width) (new-val (b box))
  26.   (setf (aref (dimensions b) 0)
  27.         new-val))
  28.  
  29. (defmethod (setf height) (new-val (b box))
  30.   (setf (aref (dimensions b) 1)
  31.         new-val))
  32.  
  33. (defmethod (setf half-width) (new-val (b box))
  34.   (setf (width b) (* new-val 2.0)))
  35.  
  36. (defmethod (setf half-height) (new-val (b box))
  37.   (setf (height b) (* new-val 2.0)))
  38.  
  39. (defmethod half-width ((b box))
  40.   (* (width b) .5))
  41.  
  42. (defmethod half-height ((b box))
  43.   (* (height b) .5))
  44.  
  45. ;;; Edge Positions
  46. ;; SETFing an edge does not change dimension, rather it repositions the box
  47. (defmethod left ((b box))
  48.   (- (x b)
  49.      (half-width b)))
  50.  
  51. (defmethod (setf left) (new-val (b box))
  52.   (setf (x b)
  53.         (+ (half-width b) new-val)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement