charts.lines: add last2

char-rename
Alexander Iljin 2017-01-13 10:56:22 +03:00 committed by John Benediktsson
parent fb2538a946
commit c9def10dde
2 changed files with 6 additions and 0 deletions

View File

@ -9,6 +9,11 @@ IN: charts.lines.tests
{ 3 } [ -2/3 1 { -2 5 } calc-y ] unit-test
{ 5 } [ -2/3 -2 { -2 5 } calc-y ] unit-test
{ 2 3 } [ { 1 2 3 } last2 ] unit-test
{ 1 2 } [ { 1 2 } last2 ] unit-test
[ { 1 } last2 ] must-fail
[ { } last2 ] must-fail
{ { } }
[ { } { } clip-data ] unit-test

View File

@ -63,6 +63,7 @@ TUPLE: line < gadget color data ;
: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
: calc-y ( slope x point -- y ) first2 [ - * ] dip + ;
: last2 ( seq -- penultimate ultimate ) 2 tail* first2 ;
: clip-by-first ( min,max pairs -- pairs' )
2dup first-in-bounds? [