-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds quadtrees with int coordinates. Affects #6
- Loading branch information
Showing
24 changed files
with
3,384 additions
and
9 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
73 changes: 73 additions & 0 deletions
73
...spatial.api/src/main/java/com/io7m/jspatial/api/quadtrees/QuadTreeConfigurationIType.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,73 @@ | ||
/* | ||
* Copyright © 2017 <[email protected]> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jspatial.api.quadtrees; | ||
|
||
import com.io7m.jregions.core.unparameterized.areas.AreaI; | ||
import com.io7m.jspatial.api.JSpatialImmutableStyleType; | ||
import org.immutables.value.Value; | ||
|
||
/** | ||
* The type of integer quadtree configurations. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
|
||
@JSpatialImmutableStyleType | ||
@Value.Immutable | ||
public interface QuadTreeConfigurationIType | ||
{ | ||
/** | ||
* @return The maximum bounding area of the tree | ||
*/ | ||
|
||
@Value.Parameter | ||
AreaI area(); | ||
|
||
/** | ||
* @return The minimum width of quadrants (must be {@code >= 2}) | ||
*/ | ||
|
||
@Value.Parameter | ||
@Value.Default | ||
default int minimumQuadrantWidth() | ||
{ | ||
return 2; | ||
} | ||
|
||
/** | ||
* @return The minimum height of quadrants (must be {@code >= 2}) | ||
*/ | ||
|
||
@Value.Parameter | ||
@Value.Default | ||
default int minimumQuadrantHeight() | ||
{ | ||
return 2; | ||
} | ||
|
||
/** | ||
* @return {@code true} iff the implementation should attempt to trim empty | ||
* leaf nodes when an item is removed | ||
*/ | ||
|
||
@Value.Parameter | ||
@Value.Default | ||
default boolean trimOnRemove() | ||
{ | ||
return false; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
com.io7m.jspatial.api/src/main/java/com/io7m/jspatial/api/quadtrees/QuadTreeIType.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,90 @@ | ||
/* | ||
* Copyright © 2017 <[email protected]> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jspatial.api.quadtrees; | ||
|
||
import com.io7m.jregions.core.unparameterized.areas.AreaI; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* The type of mutable quadtrees with {@code int} integer coordinates. | ||
* | ||
* @param <A> The precise type of quadtree members | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
|
||
public interface QuadTreeIType<A> extends QuadTreeReadableIType<A> | ||
{ | ||
/** | ||
* <p>Insert the object {@code item} into the quadtree.</p> | ||
* | ||
* <p>The function returns {@code false} if the object could not be | ||
* inserted for any reason (perhaps due to being too large).</p> | ||
* | ||
* <p>If the object is already in the tree, it is replaced. This can be | ||
* used to update the bounds of an object within the tree.</p> | ||
* | ||
* @param item The object to insert | ||
* @param bounds The object's bounds | ||
* | ||
* @return {@code true} if the object was inserted | ||
*/ | ||
|
||
boolean insert( | ||
final A item, | ||
final AreaI bounds); | ||
|
||
/** | ||
* <p>Remove the object {@code item} from the quadtree.</p> | ||
* | ||
* <p>The function returns {@code false} if the object could not be | ||
* removed for any reason (perhaps due to not being in the tree in the first | ||
* place).</p> | ||
* | ||
* @param item The object to remove | ||
* | ||
* @return {@code true} if the object was removed | ||
*/ | ||
|
||
boolean remove( | ||
A item); | ||
|
||
/** | ||
* Remove all objects from the tree. | ||
*/ | ||
|
||
void clear(); | ||
|
||
/** | ||
* Trim all empty quadrants from the tree. | ||
*/ | ||
|
||
void trim(); | ||
|
||
/** | ||
* Apply {@code f} to each element of the tree. | ||
* | ||
* @param f A mapping function | ||
* @param <B> The type of result elements | ||
* | ||
* @return A new tree | ||
*/ | ||
|
||
@Override | ||
<B> QuadTreeIType<B> map(BiFunction<A, AreaI, B> f); | ||
} |
46 changes: 46 additions & 0 deletions
46
...o7m.jspatial.api/src/main/java/com/io7m/jspatial/api/quadtrees/QuadTreeQuadrantIType.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,46 @@ | ||
/* | ||
* Copyright © 2017 <[email protected]> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jspatial.api.quadtrees; | ||
|
||
import com.io7m.jregions.core.unparameterized.areas.AreaI; | ||
import com.io7m.jregions.core.unparameterized.areas.AreaL; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A quadrant as it appears within the context of a quadtree. | ||
* | ||
* @param <T> The precise type of objects | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
|
||
public interface QuadTreeQuadrantIType<T> | ||
{ | ||
/** | ||
* @return A read-only view of the objects directly contained within this | ||
* quadrant | ||
*/ | ||
|
||
Map<T, AreaI> objects(); | ||
|
||
/** | ||
* @return The area of the quadrant | ||
*/ | ||
|
||
AreaI area(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...ial.api/src/main/java/com/io7m/jspatial/api/quadtrees/QuadTreeQuadrantIterationIType.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,47 @@ | ||
/* | ||
* Copyright © 2017 <[email protected]> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jspatial.api.quadtrees; | ||
|
||
import com.io7m.jspatial.api.TreeVisitResult; | ||
|
||
/** | ||
* The type of functions used to iterate over the quadrants of quadtrees. | ||
* | ||
* @param <A> The type of tree objects | ||
* @param <C> The type of contextual values | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
|
||
@FunctionalInterface | ||
public interface QuadTreeQuadrantIterationIType<A, C> | ||
{ | ||
/** | ||
* Apply the function. | ||
* | ||
* @param context A context value | ||
* @param quadrant The current quadrant | ||
* @param depth The current quadrant depth | ||
* | ||
* @return A value indicating how or if the traversal should continue | ||
*/ | ||
|
||
TreeVisitResult apply( | ||
C context, | ||
QuadTreeQuadrantIType<A> quadrant, | ||
long depth); | ||
} |
63 changes: 63 additions & 0 deletions
63
...spatial.api/src/main/java/com/io7m/jspatial/api/quadtrees/QuadTreeRaycastResultIType.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,63 @@ | ||
/* | ||
* Copyright © 2017 <[email protected]> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jspatial.api.quadtrees; | ||
|
||
import com.io7m.jregions.core.unparameterized.areas.AreaI; | ||
import com.io7m.jregions.core.unparameterized.areas.AreaL; | ||
import com.io7m.jspatial.api.JSpatialImmutableStyleType; | ||
import org.immutables.value.Value; | ||
|
||
/** | ||
* The type of quadtree raycast results. | ||
* | ||
* @param <T> The precise type of objects | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
|
||
@Value.Immutable | ||
@JSpatialImmutableStyleType | ||
public interface QuadTreeRaycastResultIType<T> | ||
extends Comparable<QuadTreeRaycastResultIType<T>> | ||
{ | ||
@Override | ||
default int compareTo(final QuadTreeRaycastResultIType<T> o) | ||
{ | ||
return Double.compare(this.distance(), o.distance()); | ||
} | ||
|
||
/** | ||
* @return The distance to the object | ||
*/ | ||
|
||
@Value.Parameter(order = 0) | ||
double distance(); | ||
|
||
/** | ||
* @return The object area | ||
*/ | ||
|
||
@Value.Parameter(order = 1) | ||
AreaI area(); | ||
|
||
/** | ||
* @return The object | ||
*/ | ||
|
||
@Value.Parameter(order = 2) | ||
T item(); | ||
} |
Oops, something went wrong.