Skip to content

Commit

Permalink
[math] Creation of superinterface OrientedPoint2D and addition of mis…
Browse files Browse the repository at this point in the history
…sing implementations
  • Loading branch information
tpiotrow committed Jun 10, 2016
1 parent d430662 commit abe0e91
Show file tree
Hide file tree
Showing 9 changed files with 1,380 additions and 296 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ E newArcPathElement(double startX, double startY, double targetX, double targetY
*/
OrientedPoint2afp<?, ?, E, P, V, B> newOrientedPoint(double x, double y);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @param length the length of the point on the polyline.
* @return the new oriented point
*/
OrientedPoint2afp<?, ?, E, P, V, B> newOrientedPoint(double x, double y, double length);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
Expand All @@ -186,6 +195,17 @@ E newArcPathElement(double startX, double startY, double targetX, double targetY
*/
OrientedPoint2afp<?, ?, E, P, V, B> newOrientedPoint(double x, double y, double dirX, double dirY);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @param length the length of the point on the polyline.
* @param dirX the x coordinate of the direction vector.
* @param dirY the y coordinate of the direction vector.
* @return the new oriented point
*/
OrientedPoint2afp<?, ?, E, P, V, B> newOrientedPoint(double x, double y, double length, double dirX, double dirY);

/** Replies the {@link PathIterator2afp} that is corresponding to the given element.
*
* <p>If the given element is already a {@link PathIterator2afp}, returns {@code this}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@

package org.arakhne.afc.math.geometry.d2.afp;

import org.eclipse.xtext.xbase.lib.Pure;

import org.arakhne.afc.math.MathConstants;
import org.arakhne.afc.math.MathUtil;
import org.arakhne.afc.math.geometry.CrossingComputationType;
import org.arakhne.afc.math.geometry.PathWindingRule;
import org.arakhne.afc.math.geometry.d2.OrientedPoint2D;
import org.arakhne.afc.math.geometry.d2.Point2D;
import org.arakhne.afc.math.geometry.d2.Shape2D;
import org.arakhne.afc.math.geometry.d2.Transform2D;
import org.arakhne.afc.math.geometry.d2.Vector2D;
import org.arakhne.afc.vmutil.asserts.AssertMessages;

/** A point 2D with two orientation vectors relative to the polyline: the direction and the normal to the point.
*
* <p>The orientation vectors have no physical existence, i.e. they exist only to represent the direction of the
* point and its normal when the point is part of a polyline. The normal vector is always perpendicular to the
* direction vector..
/** Fonctional interface representing a 2D oriented point on a plane.
*
* @param <ST> is the type of the general implementation.
* @param <IT> is the type of the implementation of this shape.
Expand All @@ -45,19 +40,20 @@
* @param <V> is the type of the vectors.
* @param <B> is the type of the bounding boxes.
* @author $Author: tpiotrow$
* @author $Author: sgalland$
* @author $Author: olamotte$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@SuppressWarnings("unused")
// TODO : add geometrical length
public interface OrientedPoint2afp<
ST extends Shape2afp<?, ?, IE, P, V, B>,
IT extends OrientedPoint2afp<?, ?, IE, P, V, B>,
IE extends PathElement2afp,
P extends Point2D<? super P, ? super V>,
V extends Vector2D<? super V, ? super P>,
B extends Rectangle2afp<?, ?, IE, P, V, B>> extends Shape2afp<ST, IT, IE, P, V, B> {
B extends Rectangle2afp<?, ?, IE, P, V, B>>
extends Shape2afp<ST, IT, IE, P, V, B>, OrientedPoint2D<ST, IT, PathIterator2afp<IE>, P, V, B> {

/** Iterator on the elements of the oriented points.
* It replies : the point and the extremities of the
Expand All @@ -69,6 +65,8 @@ public interface OrientedPoint2afp<
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
// TODO : complete point iterator. The iterator may return only the point or the point and its
// orientation vectors. As such, it may or may not contain multiple moveto elements.
class OrientedPointPathIterator<T extends PathElement2afp> implements PathIterator2afp<T> {

private int index;
Expand Down Expand Up @@ -152,72 +150,6 @@ default PathIterator2afp<IE> getPathIterator(Transform2D transform) {
return new OrientedPointPathIterator<>(this, transform);
}

/** Replies the X coordinate of the point.
*
* @return the x coordinate of the point.
*/
@Pure double getX();

/** Replies the Y coordinate of the point.
*
* @return the y coordinate of the point.
*/
@Pure double getY();

/** Sets a new value in the X of the point.
*
* @param x the new value double x.
*/
void setX(double x);

/** Sets a new value in the Y of the point.
* @param y the new value double y.
*/
void setY(double y);

/** Replies the X coordinate of the direction vector.
* If this point is not part of a polyline, the direction vector is null.
*
* @return the x coordinate of the direction vector.
*/
@Pure double getDirectionX();

/** Replies the Y coordinate of the direction vector.
* If this point is not part of a polyline, the direction vector is null.
*
* @return the y coordinate of the direction vector.
*/
@Pure double getDirectionY();

/** Sets a new value in the X direction of the point.
*
* @param x the new value double x.
*/
void setDirectionX(double x);

/** Sets a new value in the Y direction of the point.
* @param y the new value double y.
*/
void setDirectionY(double y);

/** Replies the X coordinate of the normal vector.
* If this point is not part of a polyline, the normal vector is null.
*
* @return the x coordinate of the normal vector.
*/
@Pure default double getNormalX() {
return -getDirectionY();
}

/** Replies the Y coordinate of the normal vector.
* If this point is not part of a polyline, the normal vector is null.
*
* @return the y coordinate of the normal vector.
*/
@Pure default double getNormalY() {
return getDirectionX();
}

@Override
default boolean contains(double x, double y) {
return x == getX() && y == getY();
Expand All @@ -240,27 +172,6 @@ default boolean contains(Point2D<?, ?> pt) {
return getX() == pt.getX() && getY() == pt.getY();
}

@Override
default boolean equalsToShape(IT shape) {
if (shape == null) {
return false;
}
if (shape == this) {
return true;
}
// We don't need to check normal because it depends of direction
return getX() == shape.getX() && getY() == shape.getY()
&& getDirectionX() == shape.getDirectionX()
&& getDirectionY() == shape.getDirectionY();
}

/** Replies this point.
* @return this point
*/
default P getPoint() {
return getGeomFactory().newPoint(getX(), getY());
}

@Override
default P getClosestPointTo(Circle2afp<?, ?, ?, ?, ?, ?> circle) {
return getPoint();
Expand All @@ -286,11 +197,6 @@ default P getClosestPointTo(Path2afp<?, ?, ?, ?, ?, ?> path) {
return getPoint();
}

@Override
default P getClosestPointTo(Point2D<?, ?> point) {
return getPoint();
}

@Override
default P getClosestPointTo(Rectangle2afp<?, ?, ?, ?, ?, ?> rectangle) {
return getPoint();
Expand All @@ -312,36 +218,12 @@ default P getClosestPointTo(Triangle2afp<?, ?, ?, ?, ?, ?> triangle) {
}

@Override
default P getClosestPointTo(Shape2D<?, ?, ?, ?, ?, ?> shape) {
default P getClosestPointTo(MultiShape2afp<?, ?, ?, ?, ?, ?, ?> multishape) {
return getPoint();
}

@Override
default double getDistanceL1(Point2D<?, ?> pt) {
assert pt != null : AssertMessages.notNullParameter();
return Point2D.getDistanceL1PointPoint(getX(), getY(), pt.getX(), pt.getY());
}

@Override
default double getDistanceLinf(Point2D<?, ?> pt) {
assert pt != null : AssertMessages.notNullParameter();
return Point2D.getDistanceLinfPointPoint(getX(), getY(), pt.getX(), pt.getY());
}

@Override
default double getDistanceSquared(Point2D<?, ?> pt) {
assert pt != null : AssertMessages.notNullParameter();
return Point2D.getDistanceSquaredPointPoint(getX(), getY(), pt.getX(), pt.getY());
}

@Override
default double getDistance(Point2D<?, ?> pt) {
assert pt != null : AssertMessages.notNullParameter();
return Point2D.getDistancePointPoint(getX(), getY(), pt.getX(), pt.getY());
}

@Override
default P getFarthestPointTo(Point2D<?, ?> point) {
default P getClosestPointTo(Shape2D<?, ?, ?, ?, ?, ?> shape) {
return getPoint();
}

Expand Down Expand Up @@ -412,35 +294,6 @@ default boolean intersects(Triangle2afp<?, ?, ?, ?, ?, ?> triangle) {
return triangle.contains(getX(), getY());
}

@Override
default boolean isEmpty() {
return false;
}

/** Change the point.
*
* @param x x coordinate of the point.
* @param y y coordinate of the point.
*/
// No default implementation to ensure atomic change
void set(double x, double y);

/** Change the point and its orientation vector.
*
* @param x x coordinate of the point.
* @param y y coordinate of the point.
* @param dirX x coordinate of the vector.
* @param dirY y coordinate of the vector.
*/
// No default implementation to ensure atomic change
void set(double x, double y, double dirX, double dirY);

@Override
default void set(IT shape) {
assert shape != null : AssertMessages.notNullParameter();
set(shape.getX(), shape.getY(), shape.getDirectionX(), shape.getDirectionY());
}

@Override
default void toBoundingBox(B box) {
assert box != null : AssertMessages.notNullParameter();
Expand Down Expand Up @@ -473,8 +326,4 @@ default void translate(double dx, double dy) {
set(getX() + dx, getY() + dy, getDirectionX() + dx, getDirectionY() + dy);
}

@Override
default void clear() {
set(0, 0, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,44 @@ E newArcPathElement(int startX, int startY, int targetX, int targetY,
int radiusX, int radiusY, double xAxisRotation,
boolean largeArcFlag, boolean sweepFlag);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @return the new oriented point
*/
OrientedPoint2ai<?, ?, E, P, V, B> newOrientedPoint(int x, int y);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @param length the length of the point on the polyline.
* @return the new oriented point
*/
OrientedPoint2ai<?, ?, E, P, V, B> newOrientedPoint(int x, int y, int length);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @param dirX the x coordinate of the direction vector.
* @param dirY the y coordinate of the direction vector.
* @return the new oriented point
*/
OrientedPoint2ai<?, ?, E, P, V, B> newOrientedPoint(int x, int y, int dirX, int dirY);

/** Create an oriented point.
*
* @param x the x coordinate of the point.
* @param y the y coordinate of the point.
* @param length the length of the point on the polyline.
* @param dirX the x coordinate of the direction vector.
* @param dirY the y coordinate of the direction vector.
* @return the new oriented point
*/
OrientedPoint2ai<?, ?, E, P, V, B> newOrientedPoint(int x, int y, int length, int dirX, int dirY);

/** Replies the {@link PathIterator2ai} that is corresponding to the given element.
*
* <p>If the given element is already a {@link PathIterator2ai}, returns {@code this}.
Expand Down

0 comments on commit abe0e91

Please sign in to comment.