3 (in-package #:vecto-geometry
)
5 (defclass transform-matrix
()
32 (defmethod print-object ((matrix transform-matrix
) stream
)
33 (print-unreadable-object (matrix stream
:type t
)
34 (format stream
"~F ~F ~F ~F ~F ~F"
42 (defun transform-matrix (a b c d e f
)
43 (make-instance 'transform-matrix
51 (defvar *identity-matrix
* (make-instance 'transform-matrix
))
53 (defmacro transform-matrix-bind
(lambda-list matrix
&body body
)
54 (when (/= (length lambda-list
) 6)
55 (error "Bad lambda-list for MATRIX-BIND: 6 arguments required"))
57 (slots '(x-scale y-skew x-skew y-scale x-offset y-offset
)))
58 `(let ((,mat
,matrix
))
59 (let (,@(loop for slot in slots
60 for var in lambda-list
61 collect
(list var
`(,slot
,mat
))))
64 (defgeneric transform-function
(transform-matrix)
65 (:method
((matrix transform-matrix
))
66 (transform-matrix-bind (a b c d e f
)
71 (point (+ (* a x
) (* c y
) e
)
72 (+ (* b x
) (* d y
) f
)))))))
74 (defgeneric transform
(point matrix
)
75 (:method
(point (matrix transform-matrix
))
76 (funcall (transform-function matrix
) point
)))
78 (defmethod mul ((m1 transform-matrix
) (m2 transform-matrix
))
79 (transform-matrix-bind (a b c d e f
)
81 (transform-matrix-bind (a* b
* c
* d
* e
* f
*)
83 (transform-matrix (+ (* a a
*)
98 (defun translation-matrix (tx ty
)
99 (transform-matrix 1 0 0 1 tx ty
))
101 (defun scaling-matrix (sx sy
)
102 (transform-matrix sx
0 0 sy
0 0))
104 (defun rotation-matrix (theta)
105 (let ((cos (cos theta
))
107 (transform-matrix cos sin
(- sin
) cos
0 0)))
109 (defun skewing-matrix (alpha beta
)
110 (transform-matrix 1 (tan alpha
) (tan beta
) 1 0 0))