From fb2538a946263baed3dfce1776243cfdb5557303 Mon Sep 17 00:00:00 2001 From: Alexander Iljin Date: Fri, 13 Jan 2017 01:58:52 +0300 Subject: [PATCH] charts.lines: add calc-y --- lines/lines-tests.factor | 4 ++++ lines/lines.factor | 1 + 2 files changed, 5 insertions(+) diff --git a/lines/lines-tests.factor b/lines/lines-tests.factor index 6361ca6350..c2d693016b 100644 --- a/lines/lines-tests.factor +++ b/lines/lines-tests.factor @@ -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 diff --git a/lines/lines.factor b/lines/lines.factor index f8e0700cca..3e9c7a21d2 100644 --- a/lines/lines.factor +++ b/lines/lines.factor @@ -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? [