github-advanced-security[bot] commented on code in PR #884:
URL: 
https://github.com/apache/incubator-baremaps/pull/884#discussion_r1725780229


##########
baremaps-dem/src/test/java/org/apache/baremaps/dem/HillShadeRenderer.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.dem;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.nio.file.Path;
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+public class HillShadeRenderer extends JFrame {
+
+  private BufferedImage originalImage;
+  private double[] grid;
+  private JSlider altitudeSlider;
+  private JSlider azimuthSlider;
+  private JSlider scaleSlider;
+  private JCheckBox isSimpleCheckbox;
+  private JLabel imageLabel;
+  private JLabel altitudeLabel;
+  private JLabel azimuthLabel;
+  private JLabel scaleLabel;
+
+  public HillShadeRenderer() throws IOException {
+    super("Hillshade Display");
+    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+    // Load the image
+    originalImage = ImageIO.read(
+        Path.of("")
+            .toAbsolutePath()
+            
.resolveSibling("baremaps/baremaps-dem/src/test/resources/fuji.png")
+            .toAbsolutePath().toFile());
+    grid = ElevationUtils.imageToGrid(originalImage, 
ElevationUtils::pixelToElevationNormal);
+
+    // Create UI components
+    altitudeSlider = new JSlider(JSlider.VERTICAL, 0, 90, 45);
+    azimuthSlider = new JSlider(JSlider.VERTICAL, 0, 360, 315);
+    scaleSlider = new JSlider(JSlider.HORIZONTAL, 1, 100, 10); // Scale from 
0.1 to 10.0
+    isSimpleCheckbox = new JCheckBox("Simple Algorithm", true);
+    imageLabel = new JLabel();
+    altitudeLabel = new JLabel("Sun Altitude: 45°");
+    azimuthLabel = new JLabel("Sun Azimuth: 315°");
+    scaleLabel = new JLabel("Scale: 1.0");
+
+    // Set up sliders
+    altitudeSlider.setMajorTickSpacing(15);
+    altitudeSlider.setPaintTicks(true);
+    altitudeSlider.setPaintLabels(true);
+
+    azimuthSlider.setMajorTickSpacing(45);
+    azimuthSlider.setPaintTicks(true);
+    azimuthSlider.setPaintLabels(true);
+
+    scaleSlider.setMajorTickSpacing(10);
+    scaleSlider.setPaintTicks(true);
+    scaleSlider.setPaintLabels(true);
+
+    // Add listeners
+    ChangeListener listener = new ChangeListener() {
+      public void stateChanged(ChangeEvent e) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [ChangeListener.stateChanged](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1546)



##########
baremaps-dem/src/main/java/org/apache/baremaps/dem/ContourTracer.java:
##########
@@ -0,0 +1,399 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.dem;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.locationtech.jts.geom.*;
+import org.locationtech.jts.geom.util.GeometryTransformer;
+import org.locationtech.jts.operation.linemerge.LineMerger;
+
+/**
+ * Provides methods for generating contour lines and contour polygons from 
digital elevation models
+ * (DEMs).
+ */
+public class ContourTracer {
+
+  private static final GeometryFactory GEOMETRY_FACTORY = new 
GeometryFactory();
+
+  private static final double EPSILON = 1e-10;
+
+  private final double[] grid;
+
+  private final int width;
+
+  private final int height;
+
+  private final boolean normalize;
+
+  private final boolean polygonize;
+
+  /**
+   * Constructs a new ContourTracer with the specified grid, width, height, 
normalization, and
+   * polygonization options.
+   *
+   * @param grid The grid of elevation values
+   * @param width The width of the grid
+   * @param height The height of the grid
+   * @param normalize Whether to normalize the coordinates
+   * @param polygonize Whether to polygonize the contours
+   */
+  public ContourTracer(double[] grid, int width, int height, boolean normalize,
+      boolean polygonize) {
+    this.grid = Arrays.copyOf(grid, grid.length);
+    this.width = width;
+    this.height = height;
+    this.normalize = normalize;
+    this.polygonize = polygonize;
+  }
+
+  /**
+   * Generates isolines for a given grid at a specific level.
+   *
+   * @param level The elevation level for which to generate isolines
+   * @return A list of LineString objects representing the isolines
+   */
+  public List<Geometry> traceContours(double level) {
+    validateInput(grid, width, height);
+
+    // Process each cell in the grid to generate segments
+    List<LineString> cells = new ArrayList<>();
+    for (int y = 0; y < height - 1; y++) {
+      for (int x = 0; x < width - 1; x++) {
+        cells.addAll(processCell(level, x, y));
+      }
+    }
+
+    // Merge the cells
+    LineMerger cellMerger = new LineMerger();
+    cellMerger.add(cells);
+    List<Geometry> contours = new 
ArrayList<>(cellMerger.getMergedLineStrings());
+
+    // Polygonize the lines
+    if (polygonize) {
+      contours = contours.stream()
+          .map(Geometry::getCoordinates)
+          .map(GEOMETRY_FACTORY::createPolygon)
+          .map(Geometry.class::cast)
+          .toList();
+    }
+
+    // Normalize the coordinates
+    if (normalize) {
+      NormalizationTransformer transformer = new NormalizationTransformer();
+      contours = contours.stream()
+          .map(geometry -> transformer.transform(geometry.copy()))
+          .toList();
+    }
+
+    return contours;
+  }
+
+  /**
+   * Generates contour for a given range of elevation levels.
+   *
+   * @param start The starting elevation level (inclusive)
+   * @param end The ending elevation level (exclusive)
+   * @param interval The interval between elevation levels
+   * @return A list of contour geometries
+   */
+  public List<Geometry> traceContours(int start, int end, int interval) {
+    validateInput(grid, width, height);
+    List<Geometry> contours = new ArrayList<>();
+    for (int level = start; level < end; level += interval) {
+      contours.addAll(traceContours(level));
+    }
+    return contours;
+  }
+
+  private static void validateInput(double[] grid, int width, int height) {
+    if (grid == null || grid.length == 0) {
+      throw new IllegalArgumentException("Grid array cannot be null or empty");
+    }
+    if (width <= 0 || height <= 0) {
+      throw new IllegalArgumentException("Width and height must be positive");
+    }
+    if (grid.length != width * height) {
+      throw new IllegalArgumentException("Grid array length does not match 
width * height");
+    }
+  }
+
+  @SuppressWarnings("squid:S3776")
+  private List<LineString> processCell(double level, int x, int y) {
+    List<LineString> segments = new ArrayList<>();
+
+    boolean htb = polygonize && y == height - 2;
+    boolean hrb = polygonize && x == width - 2;
+    boolean hbb = polygonize && y == 0;
+    boolean hlb = polygonize && x == 0;
+
+    Coordinate tlc = new Coordinate(x, y + 1.0);
+    Coordinate tmc = interpolateCoordinate(level, x, y + 1, x + 1, y + 1);
+    Coordinate trc = new Coordinate(x + 1.0, y + 1.0);
+    Coordinate mrc = interpolateCoordinate(level, x + 1, y, x + 1, y + 1);
+    Coordinate brc = new Coordinate(x + 1.0, y);
+    Coordinate bmc = interpolateCoordinate(level, x, y, x + 1, y);
+    Coordinate blc = new Coordinate(x, y);
+    Coordinate mlc = interpolateCoordinate(level, x, y, x, y + 1);
+
+    double tlv = grid[y * width + x];
+    double trv = grid[y * width + (x + 1)];
+    double brv = grid[(y + 1) * width + (x + 1)];
+    double blv = grid[(y + 1) * width + x];
+    double avg = (tlv + trv + brv + blv) / 4.0;

Review Comment:
   ## Unread local variable
   
   Variable 'double avg' is never read.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1547)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to