charts.lines: add calc-y

char-rename
Alexander Iljin 2017-01-13 01:58:52 +03:00 committed by John Benediktsson
parent 8510b351cf
commit fb2538a946
2 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,10 @@ USING: tools.test charts.lines charts.lines.private ;
IN: charts.lines.tests
{ -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
{ 3 } [ -2/3 1 { 1 3 } calc-y ] unit-test
{ 5 } [ -2/3 -2 { 1 3 } calc-y ] unit-test
{ 3 } [ -2/3 1 { -2 5 } calc-y ] unit-test
{ 5 } [ -2/3 -2 { -2 5 } calc-y ] unit-test
{ { } }
[ { } { } clip-data ] unit-test

View File

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