Skip to content

Commit 0695bfc

Browse files
committed
FEAT: pair's area accessor
1 parent 4486562 commit 0695bfc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/core/t-pair.c

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@
146146
if (IS_WORD(sel = pvs->select)) {
147147
if (VAL_WORD_CANON(sel) == SYM_X) n = 1;
148148
else if (VAL_WORD_CANON(sel) == SYM_Y) n = 2;
149+
else if (VAL_WORD_CANON(sel) == SYM_AREA) {
150+
if (pvs->setval) return PE_BAD_SET;
151+
SET_DECIMAL(pvs->store, llabs(VAL_PAIR_X(pvs->value) * VAL_PAIR_Y(pvs->value)));
152+
return PE_USE;
153+
}
149154
else return PE_BAD_SELECT;
150155
}
151156
else if (IS_INTEGER(sel) || IS_DECIMAL(sel)) {

src/tests/units/pair-test.r3

+7
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,11 @@ Rebol [
278278

279279
===end-group===
280280

281+
===start-group=== "pair area accessor"
282+
--test-- "pair/area"
283+
p: 10x20 --assert 200.0 = try [p/area]
284+
p: -10x20 --assert 200.0 = try [p/area]
285+
--assert all [error? e: try [p/area: 100] e/id = 'bad-path-set]
286+
===end-group===
287+
281288
~~~end-file~~~

0 commit comments

Comments
 (0)