]> gitweb.factorcode.org Git - factor.git/commitdiff
charts.lines: add calc-x
authorAlexander Iljin <ajsoft@yandex.ru>
Fri, 13 Jan 2017 20:29:08 +0000 (23:29 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 17 Apr 2017 20:54:50 +0000 (13:54 -0700)
lines/lines-tests.factor
lines/lines.factor

index 907cfa495e85d388eb90314dab663bc4d157298c..64e6eb0a7b83ebdbfe0687e921b711fd4f215a96 100644 (file)
@@ -12,6 +12,10 @@ IN: charts.lines.tests
 { 3 } [ 1 { 1 3 } { -2 5 } 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
+{ 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
 { 1 2 } [ { 1 2 } last2 ] unit-test
index b703607edbbce579d8d7ecaf644a7d6da91e6012..7dd288944bde5dbbfe337ddb7d9eed5b09e59182 100644 (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 + ;
+: calc-x ( slope y point -- x ) first2 swap [ - swap / ] dip + ;
 : y-at ( x point1 point2 -- y ) dupd calc-line-slope -rot calc-y ;
 : last2 ( seq -- penultimate ultimate ) 2 tail* first2 ;