-
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.
add generic spatial index for (forest) map generation
- Loading branch information
Showing
2 changed files
with
79 additions
and
6 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
60 changes: 60 additions & 0 deletions
60
...in/java/com/recom/commons/model/maprendererpipeline/dataprovider/forest/SpacialIndex.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,60 @@ | ||
package com.recom.commons.model.maprendererpipeline.dataprovider.forest; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class SpacialIndex<T> { | ||
|
||
@NonNull | ||
private final List<T>[][] index; | ||
@Getter | ||
private final int width; | ||
@Getter | ||
private final int height; | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
public SpacialIndex( | ||
final int width, | ||
final int height | ||
) { | ||
this.width = width; | ||
this.height = height; | ||
this.index = (List<T>[][]) new List[width][height]; | ||
|
||
preInitializeIndex(width, height); | ||
} | ||
|
||
private void preInitializeIndex( | ||
final int width, | ||
final int height | ||
) { | ||
for (int x = 0; x < width; x++) { | ||
for (int y = 0; y < height; y++) { | ||
this.index[x][y] = new ArrayList<T>(); | ||
} | ||
} | ||
} | ||
|
||
public void put( | ||
final int x, | ||
final int y, | ||
@NonNull final T value | ||
) { | ||
index[x][y].add(value); | ||
} | ||
|
||
@NonNull | ||
public List<T> get( | ||
final int x, | ||
final int y | ||
) { | ||
return index[x][y]; | ||
} | ||
|
||
} | ||
|