Skip to content

Commit

Permalink
extract function to CoordinateConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
svencc committed Mar 6, 2024
1 parent 8c21eee commit d795767
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 1
* add forest heatmap
* support scaling!
* TODO >>> extract to 3d-2d converter (_3dZTo2dY ....)
* extract forest colors to MapScheme
* /api/v1/configuration/map-tools/resources/forest?mapName= tooks way too long; does it already make use of the resource_name, class_name and prefab_name tables?
* cache forest and/or spatialForestMap

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.recom.commons.calculator;

import lombok.NoArgsConstructor;

@NoArgsConstructor
public class CoordinateConverter {

public double threeDeeZToTwoDeeY(
final double y,
final int demHeight,
final double stepSize
) {
return demHeight * stepSize - y;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.recom.commons.map.rasterizer;

import com.recom.commons.calculator.CoordinateConverter;
import com.recom.commons.calculator.d8algorithm.D8AlgorithmForForestMap;
import com.recom.commons.map.MapComposer;
import com.recom.commons.map.rasterizer.configuration.LayerOrder;
Expand Down Expand Up @@ -29,6 +30,8 @@
@RequiredArgsConstructor
public class ForestMapRasterizer implements MapLayerRasterizer {

@NonNull
private final CoordinateConverter coordinateConverter;
@NonNull
private final MapComposer mapComposer;
@NonNull
Expand Down Expand Up @@ -109,7 +112,7 @@ public void render(@NonNull MapComposerWorkPackage workPackage) {
forestEntities.forEach(forestItem -> {
final int x = Round.halfUp(forestItem.getCoordinateX().doubleValue() / stepSize);

final double normalizedYCoordinate = _3dZTo2dY(forestItem.getCoordinateY().doubleValue(), demHeight, stepSize);
final double normalizedYCoordinate = coordinateConverter.threeDeeZToTwoDeeY(forestItem.getCoordinateY().doubleValue(), demHeight, stepSize);
final int y = Round.halfUp(normalizedYCoordinate / stepSize);

if (x >= 0 && x < demWidth && y >= 0 && y < demHeight) {
Expand All @@ -125,17 +128,4 @@ public void render(@NonNull MapComposerWorkPackage workPackage) {
}
}





// TODO >>> extract to 3d-2d converter
public double _3dXTo2dX(final double x,final int demWidth, final double stepSize) {
return demWidth * stepSize - x;
}

public double _3dZTo2dY(final double y, final int demHeight, final double stepSize) {
return demHeight * stepSize - y;
}

}

0 comments on commit d795767

Please sign in to comment.