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.spherical.twod;
18  
19  import java.util.Collections;
20  
21  import org.apache.commons.numbers.core.Precision;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  
25  class BoundarySource2STest {
26  
27      private static final double TEST_EPS = 1e-10;
28  
29      private static final Precision.DoubleEquivalence TEST_PRECISION =
30              Precision.doubleEquivalenceOfEpsilon(TEST_EPS);
31  
32      @Test
33      void testToList() {
34          // act
35          final BoundarySource2S src = BoundarySource2S.of(
36              GreatCircles.arcFromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION),
37              GreatCircles.arcFromPoints(Point2S.PLUS_J, Point2S.PLUS_K, TEST_PRECISION)
38          );
39  
40          // act
41          final BoundaryList2S list = src.toList();
42  
43          // assert
44          Assertions.assertEquals(2, list.count());
45      }
46  
47      @Test
48      void testToList_noBoundaries() {
49          // act
50          final BoundarySource2S src = BoundarySource2S.of();
51  
52          // act
53          final BoundaryList2S list = src.toList();
54  
55          // assert
56          Assertions.assertEquals(0, list.count());
57      }
58  
59      @Test
60      void testToTree() {
61          // act
62          final BoundarySource2S src = BoundarySource2S.of(
63                  GreatCircles.arcFromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION));
64  
65          // act
66          final RegionBSPTree2S tree = src.toTree();
67  
68          // assert
69          Assertions.assertEquals(3, tree.count());
70          Assertions.assertFalse(tree.isFull());
71          Assertions.assertFalse(tree.isEmpty());
72      }
73  
74      @Test
75      void testToTree_noBoundaries() {
76          // act
77          final BoundarySource2S src = BoundarySource2S.of(Collections.emptyList());
78  
79          // act
80          final RegionBSPTree2S tree = src.toTree();
81  
82          // assert
83          Assertions.assertEquals(1, tree.count());
84          Assertions.assertFalse(tree.isFull());
85          Assertions.assertTrue(tree.isEmpty());
86      }
87  }