Skip to content

Commit af74140

Browse files
committed
Fix sonar issues
1 parent e4543b2 commit af74140

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

baremaps-cli/src/main/java/org/apache/baremaps/cli/raster/Hillshade.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
208208
return ByteBuffer.wrap(baos.toByteArray());
209209
}
210210
} catch (IOException e) {
211-
throw new RuntimeException(e);
211+
throw new TileStoreException(e);
212212
}
213213
}
214214

@@ -231,9 +231,7 @@ public void close() throws Exception {
231231
public class HillShadeTileResource {
232232

233233
private static final Logger logger =
234-
LoggerFactory.getLogger(org.apache.baremaps.server.TileResource.class);
235-
236-
// public static final String TILE_ENCODING = "gzip";
234+
LoggerFactory.getLogger(HillShadeTileResource.class);
237235

238236
public static final String TILE_TYPE = "image/png";
239237

@@ -253,7 +251,6 @@ public HttpResponse tile(@Param("z") int z, @Param("x") int x, @Param("y") int y
253251
if (blob != null) {
254252
var headers = ResponseHeaders.builder(200)
255253
.add(CONTENT_TYPE, TILE_TYPE)
256-
// .add(CONTENT_ENCODING, TILE_ENCODING)
257254
.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
258255
.build();
259256
byte[] bytes = new byte[blob.remaining()];
@@ -297,16 +294,11 @@ public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
297294
for (int level = -10000; level < 10000; level += 100) {
298295
var contours = new ContourTracer(grid, image.getWidth(), image.getHeight(), false, false)
299296
.traceContours(level);
300-
301297
for (var contour : contours) {
302-
303298
contour = AffineTransformation
304299
.translationInstance(-4, -4)
305300
.scale(16, 16)
306301
.transform(contour);
307-
308-
// contour = new ChaikinSmoother(2, 0.25).transform(contour);
309-
310302
features.add(new Feature(level, Map.of("level", String.valueOf(level)), contour));
311303
}
312304
}
@@ -320,7 +312,7 @@ public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
320312
gzip.close();
321313
return ByteBuffer.wrap(baos.toByteArray());
322314
} catch (IOException e) {
323-
throw new RuntimeException(e);
315+
throw new TileStoreException(e);
324316
}
325317

326318
}

baremaps-cli/src/main/java/org/apache/baremaps/cli/raster/Raster.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@Command(name = "raster", description = "Raster processing commands.",
2626
subcommands = {Hillshade.class},
2727
sortOptions = false)
28+
@SuppressWarnings("squid:S106")
2829
public class Raster implements Runnable {
2930

3031
@Override

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private static void validateInput(double[] grid, int width, int height) {
132132
}
133133
}
134134

135+
@SuppressWarnings("squid:S3776")
135136
private List<LineString> processCell(double level, int x, int y) {
136137
List<LineString> segments = new ArrayList<>();
137138

@@ -140,11 +141,11 @@ private List<LineString> processCell(double level, int x, int y) {
140141
boolean hbb = polygonize && y == 0;
141142
boolean hlb = polygonize && x == 0;
142143

143-
Coordinate tlc = new Coordinate(x, y + 1);
144+
Coordinate tlc = new Coordinate(x, y + 1.0);
144145
Coordinate tmc = interpolateCoordinate(level, x, y + 1, x + 1, y + 1);
145-
Coordinate trc = new Coordinate(x + 1, y + 1);
146+
Coordinate trc = new Coordinate(x + 1.0, y + 1.0);
146147
Coordinate mrc = interpolateCoordinate(level, x + 1, y, x + 1, y + 1);
147-
Coordinate brc = new Coordinate(x + 1, y);
148+
Coordinate brc = new Coordinate(x + 1.0, y);
148149
Coordinate bmc = interpolateCoordinate(level, x, y, x + 1, y);
149150
Coordinate blc = new Coordinate(x, y);
150151
Coordinate mlc = interpolateCoordinate(level, x, y, x, y + 1);
@@ -351,6 +352,9 @@ private List<LineString> processCell(double level, int x, int y) {
351352
segments.add(createSegment(blc, tlc));
352353
}
353354
}
355+
default -> {
356+
// No segments
357+
}
354358
}
355359

356360
return segments;

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
package org.apache.baremaps.raster.elevation;
1919

2020
import java.awt.image.BufferedImage;
21+
import java.util.function.DoubleToIntFunction;
2122
import java.util.function.Function;
23+
import java.util.function.IntToDoubleFunction;
2224

2325
/**
2426
* Provides utility methods for processing raster images, particularly for elevation data.
@@ -39,15 +41,16 @@ private ElevationUtils() {
3941
* @return A double array representing the elevation grid
4042
*/
4143
public static double[] imageToGrid(BufferedImage image,
42-
Function<Integer, Double> pixelToElevation) {
44+
IntToDoubleFunction pixelToElevation) {
4345
validateImage(image);
4446
int width = image.getWidth();
4547
int height = image.getHeight();
4648
double[] grid = new double[width * height];
4749

4850
for (int y = 0; y < height; y++) {
4951
for (int x = 0; x < width; x++) {
50-
grid[y * width + x] = pixelToElevation.apply(image.getRGB(x, y));
52+
int rgb = image.getRGB(x, y);
53+
grid[y * width + x] = pixelToElevation.applyAsDouble(rgb);
5154
}
5255
}
5356

@@ -63,13 +66,14 @@ public static double[] imageToGrid(BufferedImage image,
6366
* @return A BufferedImage representing the elevation data
6467
*/
6568
public static BufferedImage gridToImage(double[] grid, int width, int height,
66-
Function<Double, Integer> elevationToPixel) {
69+
DoubleToIntFunction elevationToPixel) {
6770
validateGrid(grid, width, height);
6871
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
6972

7073
for (int y = 0; y < height; y++) {
7174
for (int x = 0; x < width; x++) {
72-
image.setRGB(x, y, elevationToPixel.apply(grid[y * width + x]));
75+
double elevation = grid[y * width + x];
76+
image.setRGB(x, y, elevationToPixel.applyAsInt(elevation));
7377
}
7478
}
7579

@@ -90,7 +94,7 @@ public static double pixelToElevationTerrarium(int rgb) {
9094
return (r * 256 + g + b / 256) - 32768;
9195
}
9296

93-
private static int elevationToPixel(double elevation) {
97+
public static int elevationToPixel(double elevation) {
9498
int value = (int) ((elevation + ELEVATION_OFFSET) * 10.0);
9599
int r = (value >> 16) & 0xFF;
96100
int g = (value >> 8) & 0xFF;

0 commit comments

Comments
 (0)