new accessors

db4
Doug Coleman 2008-09-01 22:46:49 -05:00
parent eb209a723a
commit 0e80ac5460
2 changed files with 7 additions and 5 deletions

View File

@ -17,11 +17,6 @@ HELP: <rect> ( loc dim -- rect )
{ <zero-rect> <rect> <extent-rect> } related-words
HELP: set-rect-dim ( dim rect -- )
{ $values { "dim" "a pair of integers" } { "rect" rect } }
{ $description "Modifies the dimensions of a rectangle." }
{ $side-effects "rect" } ;
HELP: rect-bounds
{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
{ $description "Outputs the location and dimensions of a rectangle." } ;

View File

@ -7,6 +7,9 @@ IN: math.geometry.rect
TUPLE: rect loc dim ;
GENERIC: rect-loc ( obj -- loc )
GENERIC: rect-dim ( obj -- dim )
: init-rect ( rect -- rect ) { 0 0 } clone >>loc { 0 0 } clone >>dim ;
: <rect> ( loc dim -- rect ) rect boa ;
@ -17,6 +20,10 @@ M: array rect-loc ;
M: array rect-dim drop { 0 0 } ;
M: rect rect-loc loc>> ;
M: rect rect-dim dim>> ;
: rect-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;