charts.lines: add clip-data tests, fix implementation of left-cut-x

char-rename
Alexander Iljin 2017-01-21 22:24:04 +03:00 committed by John Benediktsson
parent 6fee00014f
commit df3d0ec8a5
2 changed files with 42 additions and 2 deletions

View File

@ -257,4 +257,44 @@ IN: charts.lines.tests
} clip-data
] unit-test
! TODO: add tests where after search there is no adjustment necessary, so that extra adjustment would take bad elements. Also, add tests for sequences fully outside the range.
! no points within the viewport, complete calculation
{
{ { 1 1 } { 4 4 } }
} [
{ { 1 4 } { 1 4 } }
{ { 0 0 } { 5 5 } } clip-data
] unit-test
! no points within the viewport, complete calculation
{
{ { 1 4 } { 4 1 } }
} [
{ { 1 4 } { 1 4 } }
{ { 0 5 } { 5 0 } } clip-data
] unit-test
! no points within the viewport, complete calculation
{
{ { 1 3 } { 4 3 } }
} [
{ { 1 4 } { 1 4 } }
{ { 0 3 } { 5 3 } } clip-data
] unit-test
! all data are to the left of viewport
{
{ }
} [
{ { 1 4 } { 1 4 } }
{ { -1 0 } { 0 1 } { 0.5 1 } } clip-data
] unit-test
! all data are to the right of viewport
{
{ }
} [
{ { 1 4 } { 1 4 } }
{ { 4.5 0 } { 5 1 } { 6 1 } } clip-data
] unit-test
! TODO: add tests where after search there is no adjustment necessary, so that extra adjustment would take bad elements.

View File

@ -71,7 +71,7 @@ ALIAS: y second
! pairs is <= xmin, and if the first is < xmin, then the second is
! > xmin. Otherwise the first one would be = xmin.
: left-cut-x ( xmin pairs -- seq )
2dup first x < [
2dup first x > [
[ dupd first2 y-at 2array ] keep rest-slice swap prefix
] [
nip