PointInLine implements Predicate<Field<T>> { @Override public boolean resolve(final Field<T> field) { final Scalar<T> xcoor = this.point.coords()[0]; final Predicate<Field<T>> result; if (new Vertical<>(this.line).resolve(field)) { result = new Equals<>(xcoor, this.line.point().coords()[0]); } else { result = new Equals<>( this.point.coords()[1], new LinePointOrdinate<T>(this.line, xcoor) ); } return result.resolve(field); } PointInLine(final Vect<T> point, final Line<T> line); @Override boolean resolve(final Field<T> field);  }
@Test public void resolvesTrueWhenInLine() { final Line<Double> line = new RandomLine<>(); MatcherAssert.assertThat( new PointInLine<>( new InLinePoint<>(line), line ).resolve(new Decimal()), Matchers.is(true) ); }
@Test public void resolvesFalseWhenOutLine() { final Line<Double> line = new RandomLine<>(); final XyPoint<Double> point = new InLinePoint<>(line); MatcherAssert.assertThat( new PointInLine<>( new XyPoint<>(point.xcoor(), new Different<>(point.ycoor())), line ).resolve(new Decimal()), Matchers.is(false) ); }
@Test public void resolvesTrueWhenInVerticalLine() { final Line<Double> line = new VerticalLine<>(); MatcherAssert.assertThat( new PointInLine<>( new InLinePoint<>(line), line ).resolve(new Decimal()), Matchers.is(true) ); }
@Test public void resolvesFalseWhenOutVerticalLine() { final Line<Double> line = new VerticalLine<>(); final XyPoint<Double> point = new InLinePoint<>(line); MatcherAssert.assertThat( new PointInLine<>( new XyPoint<>(new Different<>(point.xcoor()), point.ycoor()), line ).resolve(new Decimal()), Matchers.is(false) ); }