-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from svencc/feature/map-zoom
Feature/map zoom
- Loading branch information
Showing
121 changed files
with
779 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...com/rendertools/calculator/ARGBColor.java → ...m/recom/commons/calculator/ARGBColor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
libs/commons/src/main/java/com/recom/commons/calculator/TrigonometricCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.recom.commons.calculator; | ||
|
||
public class TrigonometricCalculator { | ||
|
||
public static double calculateRadiantBetweenPoints( | ||
final double x1, | ||
final double y1, | ||
final double x2, | ||
final double y2 | ||
) { | ||
final double deltaX = x2 - x1; | ||
final double deltaY = y2 - y1; | ||
|
||
return Math.atan2(deltaY, deltaX); | ||
} | ||
|
||
public static double calculateDistanceBetweenPoints( | ||
final double x1, | ||
final double y1, | ||
final double x2, | ||
final double y2 | ||
) { | ||
final double deltaX = x2 - x1; | ||
final double deltaY = y2 - y1; | ||
|
||
return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
libs/commons/src/main/java/com/recom/commons/math/Round.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.recom.commons.math; | ||
|
||
public class Round { | ||
|
||
public static int halfUp(final double number) { | ||
final int integerComponent = (int) Math.floor(number); | ||
final double decimalComponent = number - integerComponent; | ||
|
||
if (decimalComponent >= 0.5) { | ||
return integerComponent + 1; | ||
} else { | ||
return integerComponent; | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
libs/commons/src/main/java/com/recom/commons/math/Sign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.recom.commons.math; | ||
|
||
public class Sign { | ||
|
||
public static int of(final int number) { | ||
if (number > 0) { | ||
return 1; | ||
} else if (number < 0) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
public static int of(final double number) { | ||
if (number > 0) { | ||
return 1; | ||
} else if (number < 0) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...tools/rasterizer/HeightMapDescriptor.java → ...mmons/rasterizer/HeightMapDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
libs/commons/src/main/java/com/recom/commons/rasterizer/HeightmapScaler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.recom.commons.rasterizer; | ||
|
||
import com.recom.commons.calculator.ARGBCalculator; | ||
import lombok.NonNull; | ||
|
||
public class HeightmapScaler { | ||
|
||
|
||
public int[] scaleMap( | ||
@NonNull final HeightMapDescriptor heightMapDescriptor, | ||
final int scale, | ||
final int[] originalHeightMap | ||
) { | ||
final int originalHeight = heightMapDescriptor.getHeightMap().length; | ||
final int originalWidth = heightMapDescriptor.getHeightMap()[0].length; | ||
|
||
if (Math.abs(scale) == 1 || scale == 0) { | ||
return originalHeightMap; | ||
} else if (scale > 1) { | ||
final int scaledHeight = heightMapDescriptor.getHeightMap().length * scale; | ||
final int scaledWidth = heightMapDescriptor.getHeightMap()[0].length * scale; | ||
|
||
final int[] scaledMap = new int[scaledHeight * scaledWidth]; | ||
for (int x = 0; x < originalHeight; x++) { | ||
for (int z = 0; z < originalWidth; z++) { | ||
final int color = originalHeightMap[x + z * originalWidth]; | ||
for (int scaledPixelX = 0; scaledPixelX < scale; scaledPixelX++) { | ||
for (int scaledPixelZ = 0; scaledPixelZ < scale; scaledPixelZ++) { | ||
scaledMap[(x * scale + scaledPixelX) + (z * scale + scaledPixelZ) * scaledWidth] = color; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return scaledMap; | ||
} else { | ||
// Nearest Neighbour Downsampling: https://en.wikipedia.org/wiki/Image_scaling | ||
final int absScale = Math.abs(scale); | ||
final int scaledHeight = heightMapDescriptor.getHeightMap().length / absScale; | ||
final int scaledWidth = heightMapDescriptor.getHeightMap()[0].length / absScale; | ||
|
||
final int[] scaledMap = new int[scaledHeight * scaledWidth]; | ||
for (int x = 0; x < scaledHeight; x++) { | ||
for (int z = 0; z < scaledWidth; z++) { | ||
int alphaComponentSum = 0; | ||
int redComponentSum = 0; | ||
int greenComponentSum = 0; | ||
int blueComponentSum = 0; | ||
for (int scaledPixelX = 0; scaledPixelX < absScale; scaledPixelX++) { | ||
for (int scaledPixelZ = 0; scaledPixelZ < absScale; scaledPixelZ++) { | ||
alphaComponentSum += ARGBCalculator.getAlphaComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); | ||
redComponentSum += ARGBCalculator.getRedComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); | ||
greenComponentSum += ARGBCalculator.getGreenComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); | ||
blueComponentSum += ARGBCalculator.getBlueComponent(originalHeightMap[(x * absScale + scaledPixelX) + (z * absScale + scaledPixelZ) * originalWidth]); | ||
} | ||
} | ||
final int scalePow = (int) Math.pow(absScale, 2); | ||
alphaComponentSum /= scalePow; | ||
redComponentSum /= scalePow; | ||
greenComponentSum /= scalePow; | ||
blueComponentSum /= scalePow; | ||
|
||
scaledMap[x + z * scaledWidth] = ARGBCalculator.compose(alphaComponentSum, redComponentSum, greenComponentSum, blueComponentSum); | ||
} | ||
} | ||
|
||
return scaledMap; | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
libs/commons/src/main/java/com/recom/commons/units/PixelCoordinate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.recom.commons.units; | ||
|
||
import com.recom.commons.units.calc.ScalingTool; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
@Builder | ||
public class PixelCoordinate { | ||
|
||
private int x; | ||
private int y; | ||
|
||
public static PixelCoordinate of( | ||
final int x, | ||
final int y | ||
) { | ||
return new PixelCoordinate(x, y); | ||
} | ||
|
||
public static PixelCoordinate of( | ||
final double x, | ||
final double y | ||
) { | ||
return new PixelCoordinate((int) x, (int) y); | ||
} | ||
|
||
@NonNull | ||
public PixelCoordinate scaled(final int scaleFactor) { | ||
return PixelCoordinate.of(ScalingTool.scaleDimension(getX(), scaleFactor), ScalingTool.scaleDimension(getY(), scaleFactor)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.