diff options
Diffstat (limited to 'sly/math/vector.scm')
-rw-r--r-- | sly/math/vector.scm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/sly/math/vector.scm b/sly/math/vector.scm index cc03e4e..52e8c70 100644 --- a/sly/math/vector.scm +++ b/sly/math/vector.scm @@ -34,7 +34,8 @@ polar2 vx vy vz vw vmap v+ v- v* vdot vcross - magnitude normalize vlerp) + magnitude normalize vlerp + anchor-vector) #:replace (magnitude)) (define-record-type <vector2> @@ -174,3 +175,29 @@ element of the 2D/3D/4D vector V." (vector4 (/ x m) (/ y m) (/ z m) (/ w m))))))) (define vlerp (make-lerp v+ v*)) + +(define (anchor-vector width height anchor) + "Create an anchor point vector from the description ANCHOR within +the rectangular defined by WIDTH and HEIGHT. Valid values for ANCHOR +are: 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right', +'top-center', 'bottom-center', or any 2D vector. When ANCHOR is a 2D +vector, the return value is simply the same vector." + (match anchor + ((? vector2? anchor) + anchor) + ('center + (vector2 (/ width 2) + (/ height 2))) + ('top-left + (vector2 0 height)) + ('top-right + (vector2 width height)) + ('bottom-left + (vector2 0 0)) + ('bottom-right + (vector2 width 0)) + ('top-center + (vector2 (/ width 2) height)) + ('bottom-center + (vector2 (/ width 2) 0)) + (_ (error "Invalid anchor type: " anchor)))) |