File tree Expand file tree Collapse file tree
src/main/java/com/simsilica/mathd Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050public class Grid {
5151
5252 private final Vec3i gridSpacing ;
53+ private final int dimensions ;
5354
5455 private final int shift ;
5556 private final long mask ;
@@ -97,6 +98,7 @@ public Grid( Vec3i gridSpacing ) {
9798 if ( gridSpacing .z != 0 ) {
9899 axes ++;
99100 }
101+ this .dimensions = axes ;
100102 int bits = 64 / axes ;
101103 shift = bits ;
102104
@@ -122,6 +124,10 @@ public Grid( Vec3i gridSpacing ) {
122124 public final Vec3i getSpacing () {
123125 return gridSpacing ;
124126 }
127+
128+ public final int getDimensions () {
129+ return dimensions ;
130+ }
125131
126132 private int worldToCell ( int i , int size ) {
127133 if ( size == 0 ) {
Original file line number Diff line number Diff line change @@ -72,24 +72,28 @@ public final Vec3i getWorldOrigin() {
7272 public final boolean contains ( Vec3d world ) {
7373 return contains (world .x , world .y , world .z );
7474 }
75-
75+
76+ /**
77+ * Returns true if this GridCell contains the specified world location
78+ * where containment is in the range of min inclusive, max exclusive.
79+ */
7680 public final boolean contains ( double x , double y , double z ) {
7781 Vec3i spacing = grid .getSpacing ();
7882 double xLocal = x - worldOrigin .x ;
7983 double yLocal = y - worldOrigin .y ;
8084 double zLocal = z - worldOrigin .z ;
8185 if ( spacing .x != 0 ) {
82- if ( xLocal < 0 || xLocal > spacing .x ) {
86+ if ( xLocal < 0 || xLocal >= spacing .x ) {
8387 return false ;
8488 }
8589 }
8690 if ( spacing .y != 0 ) {
87- if ( yLocal < 0 || yLocal > spacing .y ) {
91+ if ( yLocal < 0 || yLocal >= spacing .y ) {
8892 return false ;
8993 }
9094 }
9195 if ( spacing .z != 0 ) {
92- if ( zLocal < 0 || zLocal > spacing .z ) {
96+ if ( zLocal < 0 || zLocal >= spacing .z ) {
9397 return false ;
9498 }
9599 }
You can’t perform that action at this time.
0 commit comments