View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.geometry.core.partitioning;
18  
19  import org.apache.commons.geometry.core.Transform;
20  import org.apache.commons.geometry.core.partitioning.test.TestLine;
21  import org.apache.commons.geometry.core.partitioning.test.TestPoint2D;
22  import org.apache.commons.numbers.core.Precision;
23  import org.junit.jupiter.api.Assertions;
24  import org.junit.jupiter.api.Test;
25  
26  class AbstractHyperplaneTest {
27  
28      @Test
29      void testGetPrecision() {
30          // arrange
31          final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-1);
32          final StubHyperplane hyper = new StubHyperplane(precision);
33  
34          // act/assert
35          Assertions.assertSame(precision, hyper.getPrecision());
36      }
37  
38      @Test
39      void testClassify() {
40          // arrange
41          final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-1);
42          final StubHyperplane hyper = new StubHyperplane(precision);
43  
44          // act/assert
45          Assertions.assertEquals(HyperplaneLocation.MINUS, hyper.classify(new TestPoint2D(1, 1)));
46  
47          Assertions.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, 0.09)));
48          Assertions.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, 0)));
49          Assertions.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, -0.09)));
50  
51          Assertions.assertEquals(HyperplaneLocation.PLUS, hyper.classify(new TestPoint2D(1, -1)));
52      }
53  
54      @Test
55      void testContains() {
56          // arrange
57          final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-1);
58          final StubHyperplane hyper = new StubHyperplane(precision);
59  
60          // act/assert
61          Assertions.assertFalse(hyper.contains(new TestPoint2D(1, 1)));
62  
63          Assertions.assertTrue(hyper.contains(new TestPoint2D(1, 0.09)));
64          Assertions.assertTrue(hyper.contains(new TestPoint2D(1, 0)));
65          Assertions.assertTrue(hyper.contains(new TestPoint2D(1, -0.09)));
66  
67          Assertions.assertFalse(hyper.contains(new TestPoint2D(1, -1)));
68      }
69  
70      private static class StubHyperplane extends AbstractHyperplane<TestPoint2D> {
71  
72          StubHyperplane(final Precision.DoubleEquivalence precision) {
73              super(precision);
74          }
75  
76          @Override
77          public double offset(final TestPoint2D point) {
78              return TestLine.X_AXIS.offset(point);
79          }
80  
81          @Override
82          public TestPoint2D project(final TestPoint2D point) {
83              return null;
84          }
85  
86          @Override
87          public Hyperplane<TestPoint2D> reverse() {
88              return null;
89          }
90  
91          @Override
92          public Hyperplane<TestPoint2D> transform(final Transform<TestPoint2D> transform) {
93              return null;
94          }
95  
96          @Override
97          public boolean similarOrientation(final Hyperplane<TestPoint2D> other) {
98              return false;
99          }
100 
101         @Override
102         public HyperplaneConvexSubset<TestPoint2D> span() {
103             return null;
104         }
105     }
106 }