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.geometry.core.precision.DoublePrecisionContext;
23  import org.apache.commons.geometry.core.precision.EpsilonDoublePrecisionContext;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  public class AbstractHyperplaneTest {
28  
29      @Test
30      public void testGetPrecision() {
31          // arrange
32          final DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-1);
33          final StubHyperplane hyper = new StubHyperplane(precision);
34  
35          // act/assert
36          Assert.assertSame(precision, hyper.getPrecision());
37      }
38  
39      @Test
40      public void testClassify() {
41          // arrange
42          final DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-1);
43          final StubHyperplane hyper = new StubHyperplane(precision);
44  
45          // act/assert
46          Assert.assertEquals(HyperplaneLocation.MINUS, hyper.classify(new TestPoint2D(1, 1)));
47  
48          Assert.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, 0.09)));
49          Assert.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, 0)));
50          Assert.assertEquals(HyperplaneLocation.ON, hyper.classify(new TestPoint2D(1, -0.09)));
51  
52          Assert.assertEquals(HyperplaneLocation.PLUS, hyper.classify(new TestPoint2D(1, -1)));
53      }
54  
55      @Test
56      public void testContains() {
57          // arrange
58          final DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-1);
59          final StubHyperplane hyper = new StubHyperplane(precision);
60  
61          // act/assert
62          Assert.assertFalse(hyper.contains(new TestPoint2D(1, 1)));
63  
64          Assert.assertTrue(hyper.contains(new TestPoint2D(1, 0.09)));
65          Assert.assertTrue(hyper.contains(new TestPoint2D(1, 0)));
66          Assert.assertTrue(hyper.contains(new TestPoint2D(1, -0.09)));
67  
68          Assert.assertFalse(hyper.contains(new TestPoint2D(1, -1)));
69      }
70  
71      public static class StubHyperplane extends AbstractHyperplane<TestPoint2D> {
72  
73          public StubHyperplane(final DoublePrecisionContext precision) {
74              super(precision);
75          }
76  
77          @Override
78          public double offset(final TestPoint2D point) {
79              return TestLine.X_AXIS.offset(point);
80          }
81  
82          @Override
83          public TestPoint2D project(final TestPoint2D point) {
84              return null;
85          }
86  
87          @Override
88          public Hyperplane<TestPoint2D> reverse() {
89              return null;
90          }
91  
92          @Override
93          public Hyperplane<TestPoint2D> transform(final Transform<TestPoint2D> transform) {
94              return null;
95          }
96  
97          @Override
98          public boolean similarOrientation(final Hyperplane<TestPoint2D> other) {
99              return false;
100         }
101 
102         @Override
103         public HyperplaneConvexSubset<TestPoint2D> span() {
104             return null;
105         }
106     }
107 }