http://www.jpicedt.org

jpicedt.graphic
Class PicPoint

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by java.awt.geom.Point2D.Double
          extended by jpicedt.graphic.PicPoint
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
PicVector

public class PicPoint
extends Point2D.Double
implements Cloneable

Enhancement of Point2D.Double with convenient formatting methods and constructors.

Since:
jpicedt 1.0
Version:
$Id: PicPoint.java,v 1.25 2013/03/27 07:00:43 vincentb1 Exp $
Author:
Sylvain Reynal
See Also:
Serialized Form

Nested Class Summary
static class PicPoint.XComparator
          a comparator b/w PicPoint for X-axis ordering
static class PicPoint.YComparator
          a comparator b/w PicPoint for Y-axis ordering
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float
 
Field Summary
static PicPoint.XComparator X_COMPARATOR
           
static PicPoint.YComparator Y_COMPARATOR
           
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
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(Number x, Number y)
          Construct a point from the given pair of Number (using their double value).
PicPoint(Point2D p)
          Clone the given point.
PicPoint(Point2D p1, 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(String str)
          Construct a point by parsing a String similar to that given by the toString() method, ie (x,y).
 
Method Summary
 PicPoint apply(AffineTransform at)
          Apply the given AffineTransform to the coordinates of this point
 PicPoint clone()
          Creates and returns a deep copy of this PicPoint.
static void main(String[] args)
          validation tests
 PicPoint middle(PicPoint other)
          Translate this point to the middle of the segment made of [this,other].
 PicPoint mirror(PicPoint ptOrg, PicVector normalVector)
          A le même effet que l'appel à mirror(ptOrg,normalVector,this), c'est à dire que la valeur de this est changée par reflexion relativement à l'axe passant par ptOrg et normal à normalVector.
 PicPoint mirror(PicPoint ptOrg, PicVector normalVector, PicPoint ret)
          Renvoie l'image par réflection du PicPoint this relativement à l'axe passant par le point ptOrg et normal au vecteur normalVector.
 double norm1Distance(Point2D other)
          Compute the distance with regards to norm norm1.
 double normInfDistance(Point2D other)
          Compute the distance with regards to norm normInf.
 PicPoint project(PicPoint p1, PicPoint p2)
          Project this point onto the line joining p1 and p2.
 PicPoint project(PicPoint p1, PicPoint p2, PicPoint dir)
          Project this point onto the line joining p1 and p2.
 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 PI, PI/2 or -PI/2.
 PicPoint scale(double ptOrgX, double ptOrgY, double s)
          Apply a scaling transform to this point.
 PicPoint scale(double ptOrgX, double ptOrgY, double sx, double sy)
          Apply a scaling transform to this point.
 PicPoint scale(PicPoint ptOrg, double s)
          Apply a scaling transform to this point.
 PicPoint scale(PicPoint ptOrg, double sx, double sy)
          Apply a scaling transform to this point.
 PicPoint setCoordinates(double x, double y)
          Set the coordinates of this point from the given pair
 PicPoint setCoordinates(PicPoint pt)
          Set the coordinates of this point from the given point.
 PicPoint shear(PicPoint ptOrg, double shx, double shy)
          Apply a shearing transform of given parameters wrt to the given origin, to this PicPoint
 PicPoint symmetry(PicPoint center)
          Apply a central-symmetry wrt the given point
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.
 Complex toComplex()
          Return the equivalent complex number of this, that is to say complex number with real part equal to this.getX(), and imaginary part equal to this.getY();
 double[] toDoubleArray(double[] f)
           
 float[] toFloatArray(float[] f)
           
 PicPoint toMm(double unitLength)
          Convert a PicPoint with coordinates expressed in the given unitlenth (expressed in mm), to a new PicPoint in mm coordinates.
 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.
 String toString()
          Return a "(x,y)" string representing this point.
 PicPoint translate(double dx, double dy)
          translates this point by (dx,dy)
 PicPoint translate(PicPoint p)
          translates this point by (p.x, p.y), ie the given point is considered as a translation vector.
 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.
 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.
 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.
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation
 
Methods inherited from class java.awt.geom.Point2D
distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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(Point2D p)
Clone the given point.


PicPoint

public PicPoint(Point2D p1,
                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(Number x,
                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(String str)
         throws NumberFormatException
Construct a point by parsing a String similar to that given by the toString() method, ie (x,y).
author: Sylvain Reynal

Throws:
NumberFormatException
Since:
jpicedt 1.3.3
Method Detail

clone

public PicPoint clone()
Creates and returns a deep copy of this PicPoint.

Overrides:
clone in class Point2D

setCoordinates

public PicPoint setCoordinates(PicPoint pt)
Set the coordinates of this point from the given point.

Returns:
this for convenience

setCoordinates

public PicPoint setCoordinates(double x,
                               double y)
Set the coordinates of this point from the given pair


mirror

public PicPoint mirror(PicPoint ptOrg,
                       PicVector normalVector,
                       PicPoint ret)
Renvoie l'image par réflection du PicPoint this relativement à l'axe passant par le point ptOrg et normal au vecteur normalVector. si un PicPoint ret est passé en argument, il est utilisé pour le résultat. Si ret est égal à this, alors, la réflection est effectuée sur this.

Parameters:
ptOrg - le PicPoint par lequel passe l'axe de réflection.
normalVector - le PicVector normal à l'axe de réflection
ret - un PicPoint permettant d'allouer l'image à l'extérieur de la méthode. Omettre ret pour que mirror se charge de l'allocation.
Returns:
l'image par réflection de this.

mirror

public PicPoint mirror(PicPoint ptOrg,
                       PicVector normalVector)
A le même effet que l'appel à mirror(ptOrg,normalVector,this), c'est à dire que la valeur de this est changée par reflexion relativement à l'axe passant par ptOrg et normal à normalVector.

Parameters:
normalVector - le PicVector normal à l'axe de réflexion
ptOrg - un PicPoint par lequel passe l'axe de réflexion
Returns:
l'image par réflection de this.

norm1Distance

public double norm1Distance(Point2D other)
Compute the distance with regards to norm norm1. Preferable to distance when you want to check that two points are close enough, as norm1 computes faster than norm.

Returns:
abs(this.getX() - other.getX()) + abs(this.getY() - other.getY())

normInfDistance

public double normInfDistance(Point2D other)
Compute the distance with regards to norm normInf.

Returns:
max(abs(this.getX() - other.getX()),abs(this.getY() - other.getY()))

toComplex

public Complex toComplex()
Return the equivalent complex number of this, that is to say complex number with real part equal to this.getX(), and imaginary part equal to this.getY();

Since:
jPicEdt 1.6

toFloatArray

public float[] toFloatArray(float[] f)
Returns:
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)
Returns:
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 String toString()
Return a "(x,y)" string representing this point. The returned String in turn may be fed to the PicPoint(String) constructor.

Overrides:
toString in class 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 mm
yUnit - 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-axis
sy - Scaling factors along the Y-axis
ptOrg - 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- axis
ptOrg - 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- axis
ptOrgX - X-coord of transformation centre
ptOrgY - 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-axis
sy - Scaling factors along the Y-axis
ptOrgX - X-coord of transformation centre
ptOrgY - 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 PI, PI/2 or -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 if 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(String[] args)
validation tests


apply

public PicPoint apply(AffineTransform at)
Apply the given AffineTransform to the coordinates of this point

Returns:
this for convenience

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org