1   /* Copyright 2013-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.rugged.raster;
18  
19  import org.hipparchus.util.FastMath;
20  import org.orekit.bodies.GeodeticPoint;
21  
22  public class CliffsElevationUpdater implements TileUpdater {
23  
24      private GeodeticPoint point1;
25      private GeodeticPoint point2;
26      private double        top;
27      private double        bottom;
28      private double        size;
29      private int           n;
30  
31      public CliffsElevationUpdater(GeodeticPoint point1, GeodeticPoint point2,
32                                    double top, double bottom,
33                                    double size, int n) {
34          this.point1 = point1;
35          this.point2 = point2;
36          this.top    = top;
37          this.bottom = bottom;
38          this.size   = size;
39          this.n      = n;
40      }
41  
42      public void updateTile(double latitude, double longitude, UpdatableTile tile) {
43          
44          double step         = size / (n - 1);
45          double minLatitude  = size * FastMath.floor(latitude  / size);
46          double minLongitude = size * FastMath.floor(longitude / size);
47          double x2Mx1        = point2.getLongitude() - point1.getLongitude();
48          double y2My1        = point2.getLatitude()  - point1.getLatitude();
49          tile.setGeometry(minLatitude, minLongitude, step, step, n, n);
50          for (int i = 0; i < n; ++i) {
51              double cellLatitude = minLatitude + i * step;
52              for (int j = 0; j < n; ++j) {
53                  double cellLongitude = minLongitude + j * step;
54                  double xMx1  = cellLongitude - point1.getLongitude();
55                  double yMy1  = cellLatitude  - point1.getLatitude();
56                  if (yMy1 * x2Mx1 > xMx1 * y2My1) {
57                      // left side of the point1 to point2 track
58                      tile.setElevation(i, j, top);
59                  } else {
60                      // right side of the point1 to point2 track
61                      tile.setElevation(i, j, bottom);
62                  }
63              }
64          }
65      }
66  
67  }