Skip to content

Commit 80a92db

Browse files
committed
Fix issues detected by sonar
1 parent 9ba78e7 commit 80a92db

File tree

10 files changed

+26
-64
lines changed

10 files changed

+26
-64
lines changed

baremaps-raster/src/main/java/org/apache/baremaps/raster/elevation/ElevationUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static double pixelToElevationTerrarium(int rgb) {
9090
int r = (rgb >> 16) & 0xFF;
9191
int g = (rgb >> 8) & 0xFF;
9292
int b = rgb & 0xFF;
93-
return (r * 256 + g + b / 256) - 32768;
93+
return (r * 256.0 + g + b / 256.0) - 32768.0;
9494
}
9595

9696
public static int elevationToPixel(double elevation) {

baremaps-raster/src/main/java/org/apache/baremaps/raster/elevation/HillshadeCalculator.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@ public double[] calculate(double sunAltitude, double sunAzimuth) {
5454
return calculateHillshade(sunAltitude, sunAzimuth);
5555
}
5656

57-
/**
58-
* Generates a hillshade effect on the given DEM.
59-
*
60-
* @param sunAltitude The sun's altitude in degrees
61-
* @param sunAzimuth The sun's azimuth in degrees
62-
* @return An array representing the hillshade effect
63-
*/
64-
public double[] calculate(double sunAltitude, double sunAzimuth, double scale, boolean isSimple) {
65-
validateInput(dem, width, height, sunAltitude, sunAzimuth);
66-
return calculateHillshade(sunAltitude, sunAzimuth);
67-
}
68-
69-
/**
70-
* Generates an enhanced hillshade effect on the given DEM.
71-
*
72-
* @param sunAltitude The sun's altitude in degrees
73-
* @param sunAzimuth The sun's azimuth in degrees
74-
* @return An array representing the enhanced hillshade effect
75-
*/
76-
public double[] calculateEnhanced(double sunAltitude, double sunAzimuth) {
77-
validateInput(dem, width, height, sunAltitude, sunAzimuth);
78-
return calculateHillshade(sunAltitude, sunAzimuth);
79-
}
80-
8157
private static void validateInput(double[] dem, int width, int height, double sunAltitude,
8258
double sunAzimuth) {
8359
if (dem == null || dem.length == 0) {
@@ -112,7 +88,8 @@ private double[] calculateHillshade(double sunAltitude, double sunAzimuth) {
11288
int left = Math.max(x - 1, 0);
11389
int right = Math.min(x + 1, width - 1);
11490

115-
double dzdx, dzdy;
91+
double dzdx;
92+
double dzdy;
11693
if (isSimple) {
11794
dzdx = (dem[y * width + right] - dem[y * width + left]) / 2.0;
11895
dzdy = (dem[bottom * width + x] - dem[top * width + x]) / 2.0;

baremaps-raster/src/main/java/org/apache/baremaps/raster/elevation/RasterUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import java.awt.image.BufferedImage;
2222

2323
public class RasterUtils {
24+
25+
private RasterUtils() {
26+
// Private constructor to prevent instantiation
27+
}
28+
2429
public static BufferedImage resizeImage(
2530
BufferedImage originalImage, int targetWidth, int targetHeight) {
2631
Image resultingImage =

baremaps-raster/src/main/java/org/apache/baremaps/raster/martini/Martini.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public Martini(int gridSize) {
5454
this.baseCoords = new int[this.numTriangles * 4];
5555
for (int i = 0; i < this.numTriangles; i++) {
5656
int id = i + 2;
57-
int ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;
57+
int ax = 0;
58+
int ay = 0;
59+
int bx = 0;
60+
int by = 0;
61+
int cx = 0;
62+
int cy = 0;
5863
if ((id & 1) != 0) {
5964
bx = by = cx = tileSize;
6065
} else {

baremaps-raster/src/test/java/org/apache/baremaps/raster/elevation/ChaikinSmootherTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ void smoothLineString() {
3434
new Coordinate(1, 1),
3535
});
3636
Geometry smoothedLineString = new ChaikinSmoother(2, 0.25).transform(lineString);
37-
System.out.println(smoothedLineString);
37+
assertEquals("LINESTRING (0 0, 0.375 0.375, 0.625 0.625, 0.75 0.75, 1 1)",
38+
smoothedLineString.toString());
3839
}
39-
40-
41-
4240
}

baremaps-raster/src/test/java/org/apache/baremaps/raster/elevation/ContourRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public void paint(Graphics g) {
9696
g.drawImage(image, 10, 10, null);
9797

9898
g.setColor(Color.RED);
99-
for (Geometry contour : contour) {
100-
List<Point> points = Stream.of(contour.getCoordinates())
99+
for (Geometry geometry : contour) {
100+
List<Point> points = Stream.of(geometry.getCoordinates())
101101
.map(p -> new Point((int) p.getX() + 10, (int) p.getY() + 10))
102102
.toList();
103103
for (int i = 0; i < points.size() - 1; i++) {

baremaps-raster/src/test/java/org/apache/baremaps/raster/elevation/ContourTracerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.locationtech.jts.io.ParseException;
2929
import org.locationtech.jts.io.WKTReader;
3030

31-
public class ContourTracerTest {
31+
class ContourTracerTest {
3232

3333
@Test
3434
@DisplayName("Test grid normalization")

baremaps-raster/src/test/java/org/apache/baremaps/raster/elevation/HillshadeCalculatorTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,4 @@ void testHillShadeOutputRange() {
122122
assertTrue(value >= 0 && value <= 255, "Hillshade value should be between 0 and 255");
123123
}
124124
}
125-
126-
@Test
127-
@DisplayName("Test hillShadeEnhanced output range")
128-
void testHillShadeEnhancedOutputRange() {
129-
double[] dem = new double[100];
130-
for (int i = 0; i < dem.length; i++) {
131-
dem[i] = Math.random() * 1000;
132-
}
133-
int width = 10;
134-
int height = 10;
135-
double sunAltitude = 45;
136-
double sunAzimuth = 315;
137-
138-
double[] result =
139-
new HillshadeCalculator(dem, width, height, 1, true).calculate(sunAltitude, sunAzimuth);
140-
141-
for (double value : result) {
142-
assertTrue(value >= 0 && value <= 255, "Hillshade value should be between 0 and 255");
143-
}
144-
}
145125
}

baremaps-raster/src/test/java/org/apache/baremaps/raster/martini/MartiniTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import javax.imageio.ImageIO;
2525
import org.junit.jupiter.api.Test;
2626

27-
public class MartiniTest {
27+
class MartiniTest {
2828

2929
@Test
30-
public void generateAMesh() throws IOException {
30+
void generateAMesh() throws IOException {
3131
var png = ImageIO.read(
3232
Path.of("")
3333
.toAbsolutePath()

baremaps-server/src/main/resources/raster/hillshade.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,21 @@
6060
'type': 'line',
6161
'source': 'contourSource',
6262
'source-layer': 'elevation',
63-
'layout': {},
63+
'layout': {
64+
'line-join': 'round',
65+
'line-cap': 'round',
66+
},
6467
'paint': {
6568
'line-color': '#f00',
6669
'line-width': 1,
6770
},
68-
layout: {
69-
'line-join': 'round',
70-
'line-cap': 'round',
71-
},
7271
},
7372
],
7473
},
7574
maxZoom: 18,
7675
maxPitch: 85
7776
}));
78-
79-
// map.showTileBoundaries = true;
80-
77+
8178
map.addControl(
8279
new maplibregl.NavigationControl({
8380
visualizePitch: false,

0 commit comments

Comments
 (0)