charts.lines: add calc-x

char-rename
Alexander Iljin 2017-01-13 23:29:08 +03:00 committed by John Benediktsson
parent d3e671565f
commit e645990eed
2 changed files with 5 additions and 0 deletions

View File

@ -12,6 +12,10 @@ IN: charts.lines.tests
{ 3 } [ 1 { 1 3 } { -2 5 } y-at ] unit-test { 3 } [ 1 { 1 3 } { -2 5 } y-at ] unit-test
{ 1 } [ 4 { -2 5 } { 1 3 } y-at ] unit-test { 1 } [ 4 { -2 5 } { 1 3 } y-at ] unit-test
{ 0.0 } [ 5.5 { -2 5 } { 1 3 } y-at ] unit-test { 0.0 } [ 5.5 { -2 5 } { 1 3 } y-at ] unit-test
{ 1 } [ -2/3 3 { 1 3 } calc-x ] unit-test
{ -2 } [ -2/3 5 { 1 3 } calc-x ] unit-test
{ 1 } [ -2/3 3 { -2 5 } calc-x ] unit-test
{ -2 } [ -2/3 5 { -2 5 } calc-x ] unit-test
{ 2 3 } [ { 1 2 3 } last2 ] unit-test { 2 3 } [ { 1 2 3 } last2 ] unit-test
{ 1 2 } [ { 1 2 } last2 ] unit-test { 1 2 } [ { 1 2 } last2 ] unit-test

View File

@ -63,6 +63,7 @@ TUPLE: line < gadget color data ;
: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ; : calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
: calc-y ( slope x point -- y ) first2 [ - * ] dip + ; : calc-y ( slope x point -- y ) first2 [ - * ] dip + ;
: calc-x ( slope y point -- x ) first2 swap [ - swap / ] dip + ;
: y-at ( x point1 point2 -- y ) dupd calc-line-slope -rot calc-y ; : y-at ( x point1 point2 -- y ) dupd calc-line-slope -rot calc-y ;
: last2 ( seq -- penultimate ultimate ) 2 tail* first2 ; : last2 ( seq -- penultimate ultimate ) 2 tail* first2 ;