From 5107c975a2526d62dca963c523a9e4c4c9c80734 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sun, 20 Jul 2008 04:23:43 -0500 Subject: [PATCH] math.geometry.rect: add geometry methods --- extra/math/geometry/rect/rect.factor | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/extra/math/geometry/rect/rect.factor b/extra/math/geometry/rect/rect.factor index 51f42c22ca..c04d4011b2 100644 --- a/extra/math/geometry/rect/rect.factor +++ b/extra/math/geometry/rect/rect.factor @@ -1,13 +1,15 @@ -USING: kernel arrays math.vectors ; +USING: kernel arrays math.vectors math.geometry ; IN: math.geometry.rect -TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ; +TUPLE: rect loc dim ; -: ( -- rect ) rect new ; +: init-rect ( rect -- rect ) { 0 0 } clone { 0 0 } clone ; -C: rect +: ( loc dim -- rect ) rect boa ; + +: ( -- rect ) rect new init-rect ; M: array rect-loc ; @@ -40,3 +42,8 @@ M: array rect-dim drop { 0 0 } ; : rect-union ( rect1 rect2 -- newrect ) (rect-union) ; +M: rect width ( rect -- width ) dim>> first ; +M: rect height ( rect -- height ) dim>> second ; + +M: rect set-x! ( rect x -- rect ) over loc>> set-first ; +M: rect set-y! ( rect y -- rect ) over loc>> set-second ; \ No newline at end of file