Changeset 1415 for trunk/src/org/expeditee/core/bounds
- Timestamp:
- 07/24/19 11:23:45 (5 years ago)
- Location:
- trunk/src/org/expeditee/core/bounds
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/core/bounds/CombinationBounds.java
r1097 r1415 87 87 88 88 @Override 89 public int getMaxX() 90 {91 int maxX = Integer.MIN_VALUE ;89 public int getMaxX() { 90 // +1 makes it safe to do math.abs on 91 int maxX = Integer.MIN_VALUE + 1; 92 92 93 93 for (Bounds b : _bounds) { … … 113 113 114 114 @Override 115 public int getMaxY() 116 {117 int maxY = Integer.MIN_VALUE ;115 public int getMaxY() { 116 // +1 makes it safe to do math.abs on 117 int maxY = Integer.MIN_VALUE + 1; 118 118 119 119 for (Bounds b : _bounds) { -
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)"); -
trunk/src/org/expeditee/core/bounds/PolygonBounds.java
r1142 r1415 538 538 } 539 539 } 540 541 public String toString() { 542 StringBuilder sb = new StringBuilder("PolygonBounds with: "); 543 sb.append("[MinX: " + getMinX() + "]"); 544 sb.append("[MinY: " + getMinY() + "]"); 545 sb.append("[MaxX: " + getMaxX() + "]"); 546 sb.append("[MaxY: " + getMaxY() + "]"); 547 return sb.toString(); 548 } 540 549 541 550 }
Note:
See TracChangeset
for help on using the changeset viewer.