Package jpicedt.graphic
Class PicPoint
- java.lang.Object
-
- java.awt.geom.Point2D
-
- java.awt.geom.Point2D.Double
-
- jpicedt.graphic.PicPoint
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
PicVector
public class PicPoint extends java.awt.geom.Point2D.Double implements java.lang.CloneableEnhancement of Point2D.Double with convenient formatting methods and constructors.- Since:
- jpicedt 1.0
- Version:
- $Id: PicPoint.java,v 1.12.2.1 2007/09/02 11:56:17 reynal Exp $
- Author:
- Sylvain Reynal
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPicPoint.XComparatora comparator b/w PicPoint for X-axis orderingstatic classPicPoint.YComparatora comparator b/w PicPoint for Y-axis ordering
-
Field Summary
Fields Modifier and Type Field Description static PicPoint.XComparatorX_COMPARATORstatic PicPoint.YComparatorY_COMPARATOR
-
Constructor Summary
Constructors Constructor Description PicPoint()Construct a (0,0) point.PicPoint(double[] f)Construct a point from the first two elements of the given array.PicPoint(double x, double y)Construct (x,y)PicPoint(float[] f)Construct a point from the first two elements of the given array.PicPoint(java.awt.geom.Point2D p)Clone the given point.PicPoint(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double ratio)Construct a new PicPoint "p" located on the line joining p1 with p2, so that (p1,p) = ratio * (p1,p2)PicPoint(java.lang.Number x, java.lang.Number y)Construct a point from the given pair of Number (using their double value).PicPoint(java.lang.String str)Construct a point by parsing a String similar to that given by thetoString()method, ie(x,y).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply(java.awt.geom.AffineTransform at)Apply the given AffineTransform to the coordinates of this pointjava.lang.Objectclone()Creates and returns a deep copy of this PicPoint.static voidmain(java.lang.String[] args)validation testsPicPointmiddle(PicPoint other)Translate this point to the middle of the segment made of [this,other].PicPointproject(PicPoint p1, PicPoint p2)Project this point onto the line joining p1 and p2.PicPointproject(PicPoint p1, PicPoint p2, PicPoint dir)Project this point onto the line joining p1 and p2.PicPointrotate(PicPoint ptOrg, double angle)Apply a rotation of center ptOrg and the given angle in radians to this PicPoint Current implementation arranges for a very fast code if angle is Math.PI, Math.PI/2 or -Math.PI/2.PicPointscale(double ptOrgX, double ptOrgY, double s)Apply a scaling transform to this point.PicPointscale(double ptOrgX, double ptOrgY, double sx, double sy)Apply a scaling transform to this point.PicPointscale(PicPoint ptOrg, double s)Apply a scaling transform to this point.PicPointscale(PicPoint ptOrg, double sx, double sy)Apply a scaling transform to this point.voidsetCoordinates(double x, double y)Set the coordinates of this point from the given pairPicPointsetCoordinates(PicPoint pt)Set the coordinates of this point from the given point.PicPointshear(PicPoint ptOrg, double shx, double shy)Apply a shearing transform of given parameters wrt to the given origin, to this PicPointPicPointsymmetry(PicPoint center)Apply a central-symmetry wrt the given pointstatic PicPointsymmetry(PicPoint center, PicPoint src)Return a new PicPoint obtained by applying a central-symmetry with the given center to the given src point.double[]toDoubleArray(double[] f)Return a two-element array filled with x and y ; if f is null, a new array is allocated ; otherwise, the given array is directly modified and returned for convenience.float[]toFloatArray(float[] f)Return a two-element array filled with x and y ; if f is null, a new array is allocated ; otherwise, the given array is directly modified and returned for convenience.PicPointtoMm(double unitLength)Convert a PicPoint with coordinates expressed in the given unitlenth (expressed in mm), to a new PicPoint in mm coordinates.PicPointtoMm(double xUnit, double yUnit)Convert a PicPoint with coordinate expressed in the given unitlenths along X- and Y-axis (the latter being expressed in mm) to a new PicPoint in mm coordinate.java.lang.StringtoString()Return a "(x,y)" string representing this point.PicPointtranslate(double dx, double dy)translates this point by (dx,dy)PicPointtranslate(PicPoint p)translates this point by (p.x, p.y), ie the given point is considered as a translation vector.PicPointtranslate(PicPoint p, double a)translates this point by a*(p.x, p.y), ie the given point is considered as a translation vector scaled by the given double.
This method proves a useful when one wants to minimize object creation, since it avoids cloning a given PicPoint, scaling it by "a", then passing it to the translate(PicPoint) method.PicPointtranslate(PicPoint p1, PicPoint p2)translates this point by (p2.x-p1.x, p2.y-p2.y), ie the given point is considered as a translation vector build from the two given points.PicPointtranslate(PicPoint p1, PicPoint p2, double a)translates this point by a*(p2.x-p1.x, p2.y-p2.y), ie the given point is considered as a translation vector build from the two given points, then scaled by the given double.
-
-
-
Field Detail
-
X_COMPARATOR
public static final PicPoint.XComparator X_COMPARATOR
-
Y_COMPARATOR
public static final PicPoint.YComparator Y_COMPARATOR
-
-
Constructor Detail
-
PicPoint
public PicPoint()
Construct a (0,0) point.
-
PicPoint
public PicPoint(java.awt.geom.Point2D p)
Clone the given point.
-
PicPoint
public PicPoint(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double ratio)Construct a new PicPoint "p" located on the line joining p1 with p2, so that (p1,p) = ratio * (p1,p2)- Parameters:
ratio- any double, positive or not.
-
PicPoint
public PicPoint(double x, double y)Construct (x,y)
-
PicPoint
public PicPoint(java.lang.Number x, java.lang.Number y)Construct a point from the given pair of Number (using their double value).
-
PicPoint
public PicPoint(float[] f)
Construct a point from the first two elements of the given array.
-
PicPoint
public PicPoint(double[] f)
Construct a point from the first two elements of the given array.
-
PicPoint
public PicPoint(java.lang.String str) throws java.lang.NumberFormatExceptionConstruct a point by parsing a String similar to that given by thetoString()method, ie(x,y).- Throws:
java.lang.NumberFormatException- Since:
- jpicedt 1.3.3
-
-
Method Detail
-
clone
public java.lang.Object clone()
Creates and returns a deep copy of this PicPoint.- Overrides:
clonein classjava.awt.geom.Point2D
-
setCoordinates
public PicPoint setCoordinates(PicPoint pt)
Set the coordinates of this point from the given point.- Returns:
- this for convenience
-
setCoordinates
public void setCoordinates(double x, double y)Set the coordinates of this point from the given pair
-
toFloatArray
public float[] toFloatArray(float[] f)
Return a two-element array filled with x and y ; if f is null, a new array is allocated ; otherwise, the given array is directly modified and returned for convenience.
-
toDoubleArray
public double[] toDoubleArray(double[] f)
Return a two-element array filled with x and y ; if f is null, a new array is allocated ; otherwise, the given array is directly modified and returned for convenience.
-
toString
public java.lang.String toString()
Return a "(x,y)" string representing this point. The returned String in turn may be fed to the PicPoint(String) constructor.- Overrides:
toStringin classjava.awt.geom.Point2D.Double
-
toMm
public PicPoint toMm(double unitLength)
Convert a PicPoint with coordinates expressed in the given unitlenth (expressed in mm), to a new PicPoint in mm coordinates.- Parameters:
unitLength- In mm
-
toMm
public PicPoint toMm(double xUnit, double yUnit)
Convert a PicPoint with coordinate expressed in the given unitlenths along X- and Y-axis (the latter being expressed in mm) to a new PicPoint in mm coordinate.- Parameters:
xUnit- unilength along the X-axis expressed in mmyUnit- unilength along the Y-axis expressed in mm
-
translate
public PicPoint translate(double dx, double dy)
translates this point by (dx,dy)- Returns:
- this for convenience
-
translate
public PicPoint translate(PicPoint p)
translates this point by (p.x, p.y), ie the given point is considered as a translation vector.- Returns:
- this for convenience
-
translate
public PicPoint translate(PicPoint p1, PicPoint p2)
translates this point by (p2.x-p1.x, p2.y-p2.y), ie the given point is considered as a translation vector build from the two given points.- Returns:
- this for convenience
-
translate
public PicPoint translate(PicPoint p, double a)
translates this point by a*(p.x, p.y), ie the given point is considered as a translation vector scaled by the given double.
This method proves a useful when one wants to minimize object creation, since it avoids cloning a given PicPoint, scaling it by "a", then passing it to the translate(PicPoint) method.- Returns:
- this for convenience
-
translate
public PicPoint translate(PicPoint p1, PicPoint p2, double a)
translates this point by a*(p2.x-p1.x, p2.y-p2.y), ie the given point is considered as a translation vector build from the two given points, then scaled by the given double. This method proves a useful when one wants to minimize object creation.- Returns:
- this for convenience
-
symmetry
public PicPoint symmetry(PicPoint center)
Apply a central-symmetry wrt the given point- Returns:
- this for convenience
-
symmetry
public static PicPoint symmetry(PicPoint center, PicPoint src)
Return a new PicPoint obtained by applying a central-symmetry with the given center to the given src point. If src==null, it is allocated and returned for convenience.
-
scale
public PicPoint scale(PicPoint ptOrg, double sx, double sy)
Apply a scaling transform to this point.- Parameters:
sx- Scaling factors along the X-axissy- Scaling factors along the Y-axisptOrg- transformation centre- Returns:
- this for convenience
-
scale
public PicPoint scale(PicPoint ptOrg, double s)
Apply a scaling transform to this point.- Parameters:
s- Scaling factors along the X- and Y- axisptOrg- transformation centre- Returns:
- this for convenience
-
scale
public PicPoint scale(double ptOrgX, double ptOrgY, double s)
Apply a scaling transform to this point.- Parameters:
s- Scaling factors along the X- and Y- axisptOrgX- X-coord of transformation centreptOrgY- Y-coord of transformation centre- Returns:
- this for convenience
-
scale
public PicPoint scale(double ptOrgX, double ptOrgY, double sx, double sy)
Apply a scaling transform to this point.- Parameters:
sx- Scaling factors along the X-axissy- Scaling factors along the Y-axisptOrgX- X-coord of transformation centreptOrgY- Y-coord of transformation centre- Returns:
- this for convenience
-
rotate
public PicPoint rotate(PicPoint ptOrg, double angle)
Apply a rotation of center ptOrg and the given angle in radians to this PicPoint Current implementation arranges for a very fast code if angle is Math.PI, Math.PI/2 or -Math.PI/2.- Returns:
- this for convenience
-
shear
public PicPoint shear(PicPoint ptOrg, double shx, double shy)
Apply a shearing transform of given parameters wrt to the given origin, to this PicPoint- Returns:
- this for convenience
-
middle
public PicPoint middle(PicPoint other)
Translate this point to the middle of the segment made of [this,other].- Returns:
- this for convenience [SR:pending] refactor method name to "midpoint"
-
project
public PicPoint project(PicPoint p1, PicPoint p2)
Project this point onto the line joining p1 and p2. Projectiong is orthogonal. Does nothing it p1==p2.- Returns:
- this for convenience.
-
project
public PicPoint project(PicPoint p1, PicPoint p2, PicPoint dir)
Project this point onto the line joining p1 and p2. Projection is along the given vector. Does nothing it p1==p2 or if "dir" is null, or if dir is parallel to the (p1,p2) line.- Parameters:
dir- a vector indicating the projection axis- Returns:
- this for convenience.
-
main
public static void main(java.lang.String[] args)
validation tests
-
apply
public void apply(java.awt.geom.AffineTransform at)
Apply the given AffineTransform to the coordinates of this point
-
-