Skip to content

Commit

Permalink
FEAT: pair's area accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Oct 9, 2022
1 parent 4486562 commit 0695bfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/t-pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
if (IS_WORD(sel = pvs->select)) {
if (VAL_WORD_CANON(sel) == SYM_X) n = 1;
else if (VAL_WORD_CANON(sel) == SYM_Y) n = 2;
else if (VAL_WORD_CANON(sel) == SYM_AREA) {
if (pvs->setval) return PE_BAD_SET;
SET_DECIMAL(pvs->store, llabs(VAL_PAIR_X(pvs->value) * VAL_PAIR_Y(pvs->value)));
return PE_USE;
}
else return PE_BAD_SELECT;
}
else if (IS_INTEGER(sel) || IS_DECIMAL(sel)) {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/units/pair-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,11 @@ Rebol [

===end-group===

===start-group=== "pair area accessor"
--test-- "pair/area"
p: 10x20 --assert 200.0 = try [p/area]
p: -10x20 --assert 200.0 = try [p/area]
--assert all [error? e: try [p/area: 100] e/id = 'bad-path-set]
===end-group===

~~~end-file~~~

0 comments on commit 0695bfc

Please sign in to comment.