charts.lines: add calc-line-slope

char-rename
Alexander Iljin 2017-01-12 21:57:05 +03:00 committed by John Benediktsson
parent cdc321cd93
commit 8510b351cf
2 changed files with 6 additions and 2 deletions

View File

@ -1,8 +1,10 @@
! Copyright (C) 2017 Alexander Ilin.
USING: tools.test charts.lines ;
USING: tools.test charts.lines charts.lines.private ;
IN: charts.lines.tests
{ -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
{ { } }
[ { } { } clip-data ] unit-test

View File

@ -2,7 +2,7 @@
USING: accessors arrays binary-search charts
combinators.short-circuit kernel locals math math.order
math.statistics opengl opengl.gl sequences
math.statistics math.vectors opengl opengl.gl sequences
specialized-arrays.instances.alien.c-types.float ui.gadgets
ui.render ;
IN: charts.lines
@ -61,6 +61,8 @@ TUPLE: line < gadget color data ;
! [ [ second ] dip second-in-bounds? ]
! } 2&& ;
: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
: clip-by-first ( min,max pairs -- pairs' )
2dup first-in-bounds? [
[ dup first ] dip [ search-first? not ] keep