1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS 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.orekit.models.earth.tessellation;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.bodies.GeodeticPoint;
23  
24  import static org.hamcrest.MatcherAssert.assertThat;
25  import static org.orekit.OrekitMatchers.geodeticPointCloseTo;
26  
27  public class TileTest {
28  
29      @Test
30      public void testCenteredSquare() {
31          double angle = 0.25;
32          GeodeticPoint v0 = new GeodeticPoint(-angle, -angle, 100.0);
33          GeodeticPoint v1 = new GeodeticPoint(-angle, +angle, 100.0);
34          GeodeticPoint v2 = new GeodeticPoint(+angle, -angle, 100.0);
35          GeodeticPoint v3 = new GeodeticPoint(+angle, +angle, 100.0);
36          Tile tile = new Tile(v0, v1, v2, v3);
37          assertThat(tile.getVertices()[0], geodeticPointCloseTo(v0, 1.0e-9));
38          assertThat(tile.getVertices()[1], geodeticPointCloseTo(v1, 1.0e-9));
39          assertThat(tile.getVertices()[2], geodeticPointCloseTo(v2, 1.0e-9));
40          assertThat(tile.getVertices()[3], geodeticPointCloseTo(v3, 1.0e-9));
41          assertThat(tile.getVertices()[3], geodeticPointCloseTo(v3, 1.0e-9));
42  
43          assertThat(tile.getInterpolatedPoint(0, 0), geodeticPointCloseTo(v0, 1.0e-9));
44          assertThat(tile.getInterpolatedPoint(1, 0), geodeticPointCloseTo(v1, 1.0e-9));
45          assertThat(tile.getInterpolatedPoint(1, 1), geodeticPointCloseTo(v2, 1.0e-9));
46          assertThat(tile.getInterpolatedPoint(0, 1), geodeticPointCloseTo(v3, 1.0e-9));
47  
48          assertThat(tile.getCenter(),
49                     geodeticPointCloseTo(new GeodeticPoint(0.0, 0.0, 100.0), 1.0e-9));
50  
51      }
52  
53      @Test
54      public void testPoleCentered() {
55          double latitude = 0.25;
56          GeodeticPoint v0 = new GeodeticPoint(latitude, 0.0 * FastMath.PI, 100.0);
57          GeodeticPoint v1 = new GeodeticPoint(latitude, 0.5 * FastMath.PI, 200.0);
58          GeodeticPoint v2 = new GeodeticPoint(latitude, 1.0 * FastMath.PI, 300.0);
59          GeodeticPoint v3 = new GeodeticPoint(latitude, 1.5 * FastMath.PI, 200.0);
60          Tile tile = new Tile(v0, v1, v2, v3);
61          assertThat(tile.getVertices()[0], geodeticPointCloseTo(v0, 1.0e-9));
62          assertThat(tile.getVertices()[1], geodeticPointCloseTo(v1, 1.0e-9));
63          assertThat(tile.getVertices()[2], geodeticPointCloseTo(v2, 1.0e-9));
64          assertThat(tile.getVertices()[3], geodeticPointCloseTo(v3, 1.0e-9));
65          assertThat(tile.getVertices()[3], geodeticPointCloseTo(v3, 1.0e-9));
66  
67          assertThat(tile.getInterpolatedPoint(0, 0), geodeticPointCloseTo(v0, 1.0e-9));
68          assertThat(tile.getInterpolatedPoint(1, 0), geodeticPointCloseTo(v1, 1.0e-9));
69          assertThat(tile.getInterpolatedPoint(1, 1), geodeticPointCloseTo(v2, 1.0e-9));
70          assertThat(tile.getInterpolatedPoint(0, 1), geodeticPointCloseTo(v3, 1.0e-9));
71  
72          Assertions.assertEquals(0.5 * FastMath.PI, tile.getCenter().getLatitude(), 1.0e-9);
73  
74      }
75  
76  }