Class Point2D
- java.lang.Object
-
- com.supermap.data.Point2D
-
public class Point2D extends java.lang.Object
The instance of the point class is the point object, which is used to represent the point with double coordinate values ranging from 5.0*1e-324 to ±1.7*1e308, with 15-16 effective digits.The Point2D object is a very basic object for various geometric objects, for example, a GeoLine object is formed of a bunch of
Point2D
objects, while a GeoRegion object is also formed of a bunch of Point2D objects, except that the start point and the endpoint is identical. So when depicting the location and shape of a geometric object, the Point2D object is very necessary.To construct a new
Point2D
object, three constructors are provided. When construct a new object with the default constructor, both the x- and y-coordinate are -1.7976931348623157e+308; you can also initialize a new Point2D instance with specified x- and y-coordinate values, or create a copy of an existing Point2D object.Besides the methods for getting and setting the values of coordinates of the point, this class also provides methods that used to create new point with integer x-and y-coordinates with given point, and the method to offset this point etc.
-
-
Constructor Summary
Constructors Constructor and Description Point2D()
Constructs a new Point2D object.Point2D(double x, double y)
Creates a new Point2D object according to the specified arguments.Point2D(Point2D pt)
Constructs a new object identical to the given Point2D object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static Point2D
ceiling(Point2D pt)
Returns a Point2D object whose X, Y coordinates are the larger than or equal to the minimum integer of the X, Y coordinates of the given point.Point2D
clone()
Returns a copy of the current Point2D object.boolean
equals(java.lang.Object obj)
Specifies whether this Point2D object contains the same coordinate with the given System.Object.boolean
equals(Point2D pt)
Determines whether this Point2D object equals to the given Point2D object, that is whether they have the same coordinate.static Point2D
floor(Point2D pt)
Returns a Point2D object whose X, Y coordinates are the less than or equal to the maximum integer of the X, Y coordinates of the given point.static Point2D
getEMPTY()
Returns an empty point object.double
getX()
Returns the X-coordinate of the Point2D object.double
getY()
Returns the Y-coordinate of the Point2D object.int
hashCode()
Gets the hash code of this Point2D object.boolean
isEmpty()
Gets a value that indicates whether both the x-coordinate and the y-coordinate of this Point2D object are -1.7976931348623157e+308.void
offset(double dx, double dy)
Translates this Point2D object by the specified amount.static Point2D
round(Point2D pt)
Returns a new Point2D object.void
setX(double value)
Sets the x-coordinate of this Point2D.void
setY(double value)
Sets the y-coordinate of this Point2D.java.lang.String
toString()
Creates a readable character string of this Point2D, for instance, Point2D(2,3), and the result string format is "{X=2.0,Y=3.0}".
-
-
-
Constructor Detail
-
Point2D
public Point2D()
Constructs a new Point2D object.
-
Point2D
public Point2D(double x, double y)
Creates a new Point2D object according to the specified arguments.- Parameters:
x
- The X coordinate of the Point2D.y
- The Y coordinate of the Point2D.
-
Point2D
public Point2D(Point2D pt)
Constructs a new object identical to the given Point2D object.- Parameters:
pt
- The specified Point2D object.
-
-
Method Detail
-
getEMPTY
public static final Point2D getEMPTY()
Returns an empty point object.- Returns:
- an empty point object.
- Example:
- The code below demonstrates how to create an empty Point2D object.
public void getEmptyTest() { // Construce an empty 2D point object Point2D point2D = Point2D.getEMPTY(); System.out.println(point2D.isEmpty()); // true }
-
isEmpty
public boolean isEmpty()
Gets a value that indicates whether both the x-coordinate and the y-coordinate of this Point2D object are -1.7976931348623157e+308.The determine precision used is equal-zero precision by default. For more information about default equal-zero precision, please refer to the
Environment
class.- Returns:
- returns true if the Point2D object is empty.
- Default:
- the default value is true, that is the Point2D object is null.
-
getX
public double getX()
Returns the X-coordinate of the Point2D object.- Returns:
- the X-coordinate of the Point2D object.
- Default:
- The default value is -1.79769313486232E+308.
-
setX
public void setX(double value)
Sets the x-coordinate of this Point2D.- Parameters:
value
- the x-coordinate of the given Point2D object.
-
getY
public double getY()
Returns the Y-coordinate of the Point2D object.- Returns:
- the Y-coordinate of the Point2D object.
- Default:
- The default value is -1.79769313486232E+308.
-
setY
public void setY(double value)
Sets the y-coordinate of this Point2D.- Parameters:
value
- the y-coordinate of the given Point2D object.
-
clone
public Point2D clone()
Returns a copy of the current Point2D object.- Overrides:
clone
in classjava.lang.Object
- Returns:
- The new Point2D object generated from the clone operation.
-
equals
public boolean equals(Point2D pt)
Determines whether this Point2D object equals to the given Point2D object, that is whether they have the same coordinate. Note that the comparison is performed in terms of the equal-zero precision. For more information about equal-zero precision, please refer to the Environment class.- Parameters:
pt
- the Point2D object to compare with the given Point2D object.- Returns:
- true if the two objects are equal, or false otherwise.
-
ceiling
public static Point2D ceiling(Point2D pt)
Returns a Point2D object whose X, Y coordinates are the larger than or equal to the minimum integer of the X, Y coordinates of the given point. For instance, if the given Point2D object is (32.12, 20.67), this method will return a new Point2D object with the coordinates (33,21).- Parameters:
pt
- the Point2D object to convert.- Returns:
- The converted Point2D object.
- Example:
- The following example demonstrates the ceiling operation on a Point2D object.
public void ceilingTest() { // Constructs a 2D point object Point2D point2D = new Point2D(100.5, 100.4); System.out.println(point2D); // {X=100.5,Y=100.4} // ceiling operation Point2D point2D_c = Point2D.ceiling(point2D); System.out.println(point2D_c); // {X=101.0,Y=101.0} }
-
round
public static Point2D round(Point2D pt)
Returns a new Point2D object. If the X, Y, and Z coordinates of the given object are all integers, the new object will be equal to the given object. If the X, Y, and Z coordinates of the given object are decimal numbers, the coordinates of the new object will be integer values nearest to coordinates of the given object. If the coordinate is in the middle of two integers, the even integer will be returned.e.g.:
- If the given object is (32.12, 26.67), the new object would be (32, 27, 10).
- If the given object is (32, 26.67), the new object would be (32, 27, 10).
- If the given object is (32.5, 25.5), the new object would be (32, 26, 10).
- Parameters:
pt
- the Point2D object to convert.- Returns:
- The converted Point2D object.
-
floor
public static Point2D floor(Point2D pt)
Returns a Point2D object whose X, Y coordinates are the less than or equal to the maximum integer of the X, Y coordinates of the given point. For instance, if the given Point2D object is (32.12, 20.67), this method will return a new Point2D object with the coordinates (32,20). If the X or Y coordinate of the given Point2D object is integral value, the X or Y coordinate of the new Point2D object is the same integral value, for example: if the coordinate of the given point object is (10, 20), the coordinate of the new point object is (10, 20); if the coordinate of the given point object is (32.12, 15), the coordinate of the new point object is (32, 15);- Parameters:
pt
- the Point2D object to convert.- Returns:
- The converted Point2D object.
- Example:
- The following example demonstrates the floor operation on a Point2D object.
public void floorTest() { // Constructs a 2D point object Point2D point2D = new Point2D(100.5, 100.6); System.out.println(point2D); // {X=100.5,Y=100.6} // floor operation Point2D point2D_f = Point2D.floor(point2D); System.out.println(point2D_f); // {X=100.0,Y=100.0} }
-
offset
public void offset(double dx, double dy)
Translates this Point2D object by the specified amount.- Parameters:
dx
- the offset of the X coordinate.dy
- the offset of the X coordinate.- Example:
- The following example demonstrates the offset operation on a Point2D object.
public void offsetTest() { // Constructs a 2D point object Point2D point2D = new Point2D(100, 100); System.out.println(point2D); // {X=100.0,Y=100.0} // offset operation point2D.offset(20.5, -51.6); System.out.println(point2D); // {X=120.5,Y=48.4} }
-
toString
public java.lang.String toString()
Creates a readable character string of this Point2D, for instance, Point2D(2,3), and the result string format is "{X=2.0,Y=3.0}".- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string that represents this
Point2D
.
-
equals
public boolean equals(java.lang.Object obj)
Specifies whether this Point2D object contains the same coordinate with the given System.Object.
-
hashCode
public int hashCode()
Gets the hash code of this Point2D object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code of this Point2D object.
-
-