[Arakhnę-Dev] [401] * Add toBoundingBox(Rectangle2f). |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 401
Author: galland
Date: 2013-03-29 11:08:09 +0100 (Fri, 29 Mar 2013)
Log Message:
-----------
* Add toBoundingBox(Rectangle2f).
Modified Paths:
--------------
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/AbstractRectangularShape2f.java
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Circle2f.java
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Path2f.java
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Rectangle2f.java
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Segment2f.java
trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Shape2f.java
trunk/math/src/main/java/org/arakhne/afc/math/discrete/object2d/Rectangle2i.java
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/AbstractRectangularShape2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/AbstractRectangularShape2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/AbstractRectangularShape2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -70,7 +70,15 @@
setFromCorners(x, y, x+width, y+height);
}
+ /** {@inheritDoc}
+ */
@Override
+ public void toBoundingBox(Rectangle2f box) {
+ box.setFromCorners(this.minx, this.minx, this.maxx, this.maxy);
+ }
+
+
+ @Override
public void clear() {
this.minx = this.miny = this.maxx = this.maxy = 0f;
}
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Circle2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Circle2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Circle2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -324,6 +324,16 @@
/** {@inheritDoc}
*/
@Override
+ public void toBoundingBox(Rectangle2f box) {
+ box.setFromCorners(this.cx-this.radius,
+ this.cy-this.radius,
+ this.cx+this.radius,
+ this.cy+this.radius);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
public float distance(Point2D p) {
float d = MathUtil.distancePointToPoint(getX(), getY(), p.getX(), p.getY()) - getRadius();
return Math.max(0f, d);
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Path2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Path2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Path2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -1554,10 +1554,31 @@
bb.setFromCorners(xmin, ymin, xmax, ymax);
this.bounds = new SoftReference<Rectangle2f>(bb);
}
- return bb;
+ return bb.clone();
}
@Override
+ public void toBoundingBox(Rectangle2f box) {
+ Rectangle2f bb = this.bounds==null ? null : this.bounds.get();
+ if (bb==null) {
+ float xmin = Float.POSITIVE_INFINITY;
+ float ymin = Float.POSITIVE_INFINITY;
+ float xmax = Float.NEGATIVE_INFINITY;
+ float ymax = Float.NEGATIVE_INFINITY;
+ for(int i=0; i<this.numCoords; i+= 2) {
+ if (this.coords[i]<xmin) xmin = this.coords[i];
+ if (this.coords[i+1]<ymin) ymin = this.coords[i+1];
+ if (this.coords[i]>xmax) xmax = this.coords[i];
+ if (this.coords[i+1]>ymax) ymax = this.coords[i+1];
+ }
+ bb = new Rectangle2f();
+ bb.setFromCorners(xmin, ymin, xmax, ymax);
+ this.bounds = new SoftReference<Rectangle2f>(bb);
+ }
+ box.set(bb);
+ }
+
+ @Override
public Point2D getClosestPointTo(Point2D p) {
Point2D closest = null;
float bestDist = Float.POSITIVE_INFINITY;
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Rectangle2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Rectangle2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Rectangle2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -286,7 +286,7 @@
*/
@Override
public Rectangle2f toBoundingBox() {
- return this;
+ return clone();
}
/** {@inheritDoc}
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Segment2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Segment2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Segment2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -538,6 +538,17 @@
/** {@inheritDoc}
*/
@Override
+ public void toBoundingBox(Rectangle2f box) {
+ box.setFromCorners(
+ this.ax,
+ this.ay,
+ this.bx,
+ this.by);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
public float distanceSquared(Point2D p) {
return MathUtil.distanceSquaredPointToSegment(p.getX(), p.getY(),
this.ax, this.ay,
Modified: trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Shape2f.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Shape2f.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/continous/object2d/Shape2f.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -44,6 +44,12 @@
*/
public Rectangle2f toBoundingBox();
+ /** Replies the bounds of the shape.
+ *
+ * @param box is set with the bounds of the shape.
+ */
+ public void toBoundingBox(Rectangle2f box);
+
/** Replies the minimal distance from this shape to the given point.
*
* @param p
Modified: trunk/math/src/main/java/org/arakhne/afc/math/discrete/object2d/Rectangle2i.java
===================================================================
--- trunk/math/src/main/java/org/arakhne/afc/math/discrete/object2d/Rectangle2i.java 2013-03-28 16:50:19 UTC (rev 400)
+++ trunk/math/src/main/java/org/arakhne/afc/math/discrete/object2d/Rectangle2i.java 2013-03-29 10:08:09 UTC (rev 401)
@@ -222,7 +222,7 @@
*/
@Override
public Rectangle2i toBoundingBox() {
- return this;
+ return clone();
}
/** {@inheritDoc}