Skip to content

Commit

Permalink
Optimized prime search utility methods and added timer to FalloffPerl…
Browse files Browse the repository at this point in the history
…inNoiseTest
  • Loading branch information
john01dav committed Jul 29, 2016
1 parent e969cbc commit 5fcb4d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
public class FalloffPerlinNoiseTest{

public static void main(String[] args) throws IOException{
long start = System.currentTimeMillis();
HeightMap heightMap = new HeightMap(2048, new PerlinNoiseTemplate(0L, 9, 2, new FalloffPerlinNoiseController()));
heightMap.generate();
System.out.println("Generation Time: " + (System.currentTimeMillis() - start));

heightMap.saveImage("./falloffislandperlinnoise.png");
}

Expand Down
8 changes: 6 additions & 2 deletions src/src/john01dav/jnoise/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public final class MathUtil{
private MathUtil(){}

public static boolean isPrime(int n){
for(int i=2;i<n;i++){
int sqrtOfN = (int) Math.ceil(Math.sqrt(n));

for(int i=2;i<sqrtOfN;i++){
if(n % i == 0){
return false;
}
Expand All @@ -15,7 +17,9 @@ public static boolean isPrime(int n){
}

public static int getNextPrime(int n){
while(!isPrime(n)) n++;
if(n % 2 == 0) n++;

while(!isPrime(n)) n+=2;
return n;
}

Expand Down

0 comments on commit 5fcb4d2

Please sign in to comment.