Class Point
- Direct Known Subclasses:
CranePosition
Segment and
Polyline classes.
NaNs and infinite coordinates are allowed and there are no checks that prevent from creating points with such coordinates. But these coordinates are not supported in most methods which can cause errors. Thus, in documentation to majority of methods, the special cases with NaNs and infinite coordinates are not described
- Author:
- Andrey Malykhanov
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsPoint(Point point) Checks whether this primitive contains the specified pointdoubledistanceTo(Point p) Returns the distance from this point to the specified point.booleanChecks whether the other given point is equal to this point, i.e.booleanequals(Point point, EpsilonComparator comparator) Checks whether the other given point is equal to this point, i.e.booleangetCopy()Returns a copy of this point, i.e.doublegetX()Returns the x-coordinate (abscissa) of the pointdoublegetY()Returns the y-coordinate (ordinate) of the pointinthashCode()doubleReturns the heading from this point towards the specified point, in radians.Returns a new instance of point which is a result of coordinate-wise subtraction of this point and the specified point.multiply(double factor) Returns a new instance of point which is a result of coordinate-wise multiplication of this point by the specified factorReturns a new instance of point which is a coordinate-wise sum of this point and the specified point.rotate(double angle) Returns a new instance of point which is the result of rotation of this point around the (0, 0) point by the specified angle in radians.rotateAround(double angle, Point rotationCenter) Returns a new instance of point which is the result of rotation of this point around the specified point (rotation center) by the specified angle in radians.doubleReturns the squared distance from this point to the specified point.Returns the string representing Java code that creates this primitive in its current statetoString()
-
Field Details
-
x
protected double x -
y
protected double y
-
-
Constructor Details
-
Point
public Point()Creates a new point with (0, 0) coordinates. -
Point
public Point(double x, double y) Creates a new point with the specified coordinates.- Parameters:
x- x-coordinate of the pointy- y-coordinate of the point
-
-
Method Details
-
getX
public double getX()Returns the x-coordinate (abscissa) of the point- Returns:
- x-coordinate of the point
-
getY
public double getY()Returns the y-coordinate (ordinate) of the point- Returns:
- y-coordinate of the point
-
distanceTo
Returns the distance from this point to the specified point. The returned value cannot be negative. Note thatMath.sqrt(double)function is used inside this function, which can cause performance issues when used inside "hot" code parts, so consider usingsquaredDistanceTo(Point)when possible.Distance between finite point and infinite point is Double.POSITIVE_INFINITY
- Parameters:
p- the specified point- Returns:
- distance from this point to the specified point
-
squaredDistanceTo
Returns the squared distance from this point to the specified point. The returned value cannot be negative.Squared distance between finite point and infinite point is Double.POSITIVE_INFINITY
- Parameters:
p- the specified point- Returns:
- distance from this point to the specified point
-
headingTo
Returns the heading from this point towards the specified point, in radians. The heading is calculated as angle between the base vector pointing downwards (in screen coordinate system) and the direction between the current point and the specified point. Counter-clockwise direction from the base vector is considered positive heading, clockwise - negative heading. The heading always lies in range (-PI, PI]. If points are equal, returns 0.
- Parameters:
p- the specified point- Returns:
- heading from this point towards the specified point, in radians. The value is always in range (-PI, PI] Creates a new point with (0, 0) coordinates.
-
plus
Returns a new instance of point which is a coordinate-wise sum of this point and the specified point.- Parameters:
point- the specified point- Returns:
- sum of this point and the specified point
-
minus
Returns a new instance of point which is a result of coordinate-wise subtraction of this point and the specified point.- Parameters:
point- the specified point- Returns:
- coordinate-wise difference of this point and the specified point
-
rotate
Returns a new instance of point which is the result of rotation of this point around the (0, 0) point by the specified angle in radians.In screen coordinate system, if the angle is positive, the rotation is directed clockwise. If the angle is negative, the rotation is directed counter-clockwise

- Parameters:
angle- specified angle in radians- Returns:
- result of rotation
-
multiply
Returns a new instance of point which is a result of coordinate-wise multiplication of this point by the specified factor- Parameters:
factor- specified factor- Returns:
- result of coordinate-wise multiplication of this point by the specified factor
-
rotateAround
Returns a new instance of point which is the result of rotation of this point around the specified point (rotation center) by the specified angle in radians. In screen coordinate system, if the angle is positive, the rotation is directed clockwise. If the angle is negative, the rotation is directed counter-clockwise
- Parameters:
angle- specified angle in radiansrotationCenter- specified rotation center- Returns:
- result of rotation
-
containsPoint
Description copied from class:AbstractGeometricPrimitiveChecks whether this primitive contains the specified point- Specified by:
containsPointin classAbstractGeometricPrimitive- Parameters:
point- the specified point- Returns:
trueif this primitive contains the specified point,falseotherwise
-
hashCode
public int hashCode() -
equals
-
equals
Checks whether the other given point is equal to this point, i.e. if both x and y points coordinates the other point equal correspondingly to x and y coordinates of this point.The equality of the coordinates is determined with respect to the default epsilon, that can be obtained by
Compare.getEpsilon().- Parameters:
point- other given point- Returns:
trueif the other given point is equal to this point,falseotherwise
-
equals
Checks whether the other given point is equal to this point, i.e. if both x and y points coordinates the other point equal correspondingly to x and y coordinates of this point.The equality of the coordinates is determined with respect to the specified epsilon.
- Parameters:
point- other given pointcomparator- specified comparator to compare length and distances- Returns:
trueif the other given point is equal to this point,falseotherwise
-
getCopy
Returns a copy of this point, i.e. the point with the same coordinates- Returns:
- copy of this point
-
toString
-
toCodeString
Description copied from class:AbstractGeometricPrimitiveReturns the string representing Java code that creates this primitive in its current state- Specified by:
toCodeStringin classAbstractGeometricPrimitive- Returns:
- Java code required to create this primitive in its current state
-