Perpendicular implements Predicate<Field<T>> { @Override public boolean resolve(final Field<T> field) { if (field instanceof MetricSpaceField<?>) { final Double degrees = new VectsDegrees<>( this.first, this.second ).resolve(((MetricSpaceField<T>) field).product()).doubleValue(); final double error = 1.e-6; return Math.abs(degrees - Math.PI / 2) < error || Math.abs(degrees + Math.PI / 2) < error; } else { throw new UnsupportedOperationException( String.format("Field %s is not a metric space field", field) ); } } Perpendicular(final Line<T> first, final Line<T> second);  Perpendicular(final Vect<T> first, final Vect<T> second); @Override boolean resolve(final Field<T> field);  }
@Test public void resolvesTrueIfPerp() { final Line<Double> any = new RandomLine<>(); MatcherAssert.assertThat( new Perpendicular<>(any, new PerpLine<>(any)).resolve(new Decimal()), Matchers.is(true) ); }
@Test public void resolvesfalseIfParallel() { final Line<Double> any = new RandomLine<>(); MatcherAssert.assertThat( new Perpendicular<>( any, new ParallelLine<>(any) ).resolve(new Decimal()), Matchers.is(false) ); }
@Test public void acceptsLinesOrVects() { final Line<Double> any = new RandomLine<>(); MatcherAssert.assertThat( new Perpendicular<>( any.direction(), new PerpLine<>(any).direction() ).resolve(new Decimal()), Matchers.is(true) ); }