- Timestamp:
- 07/24/19 11:23:45 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/core/bounds/EllipticalBounds.java
r1142 r1415 70 70 71 71 @Override 72 public boolean contains(int x, int y) 73 { 72 public boolean contains(int x, int y) { 74 73 // If the ellipse is degenerate then it can't contain anything 75 74 if (_diameters.getArea() == 0) return false; 76 77 // Get the position of the given coordinates with respect to the ellipse centre 78 Point pRel = new Point(x - _centre.getX(), y - _centre.getY()); 79 80 // x^2 / r_x^2 + y^2 / r_y^2 must be <= 1 81 // (using diameters instead of radii hence the 4.0f value) 82 float xNorm = (((float) pRel.getX()) * pRel.getX()) / (((float) _diameters.width) * _diameters.width); 83 float yNorm = (((float) pRel.getY()) * pRel.getY()) / (((float) _diameters.height) * _diameters.height); 84 return (xNorm + yNorm <= 4.0f); 75 76 double deltaXSq = Math.pow(x - _centre.getX(), 2); 77 double deltaYSq = Math.pow(y - _centre.getY(), 2); 78 double minorAxisSq = Math.pow(Math.min(_diameters.height, _diameters.width) / 2, 2); 79 double majorAxisSq = Math.pow(Math.max(_diameters.height, _diameters.width) / 2, 2); 80 double result = (deltaXSq / majorAxisSq) + (deltaYSq / minorAxisSq); 81 return result <= 1.0f; 85 82 } 86 83 … … 118 115 119 116 @Override 120 public boolean equals(Bounds other) 121 { 117 public boolean equals(Bounds other) { 122 118 if (other instanceof EllipticalBounds) { 123 119 EllipticalBounds e = (EllipticalBounds) other; … … 128 124 129 125 @Override 130 public boolean intersects(AxisAlignedBoxBounds other) 131 { 126 public boolean intersects(AxisAlignedBoxBounds other) { 132 127 // Treat the box as a polygon 133 128 return intersects(other.getPolygon()); … … 135 130 136 131 @Override 137 public boolean intersects(CombinationBounds other) 138 { 132 public boolean intersects(CombinationBounds other) { 139 133 // Defer to the CombinationBounds routine 140 134 return other.intersects(this); … … 142 136 143 137 @Override 144 public boolean intersects(EllipticalBounds other) 145 { 138 public boolean intersects(EllipticalBounds other) { 146 139 // TODO: Implement. cts16 147 140 System.err.println("Unimplemented method: EllipticalBounds.intersects(EllipticalBounds)");
Note:
See TracChangeset
for help on using the changeset viewer.