new accessors
parent
eb209a723a
commit
0e80ac5460
|
@ -17,11 +17,6 @@ HELP: <rect> ( loc dim -- rect )
|
||||||
|
|
||||||
{ <zero-rect> <rect> <extent-rect> } related-words
|
{ <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
|
HELP: rect-bounds
|
||||||
{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
|
{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
|
||||||
{ $description "Outputs the location and dimensions of a rectangle." } ;
|
{ $description "Outputs the location and dimensions of a rectangle." } ;
|
||||||
|
|
|
@ -7,6 +7,9 @@ IN: math.geometry.rect
|
||||||
|
|
||||||
TUPLE: rect loc dim ;
|
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 ;
|
: init-rect ( rect -- rect ) { 0 0 } clone >>loc { 0 0 } clone >>dim ;
|
||||||
|
|
||||||
: <rect> ( loc dim -- rect ) rect boa ;
|
: <rect> ( loc dim -- rect ) rect boa ;
|
||||||
|
@ -17,6 +20,10 @@ M: array rect-loc ;
|
||||||
|
|
||||||
M: array rect-dim drop { 0 0 } ;
|
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-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
|
||||||
|
|
||||||
: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
|
: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
|
||||||
|
|
Loading…
Reference in New Issue