Package com.storedobject.svg
Record Class Coordinates
java.lang.Object
java.lang.Record
com.storedobject.svg.Coordinates
- Record Components:
x1- The x-coordinate of the top-left corner.y1- The y-coordinate of the top-left corner.x2- The x-coordinate of the bottom-right corner.y2- The y-coordinate of the bottom-right corner.
Represents a coordinate system defined by two points (x1, y1) and (x2, y2).
The boundary is adjusted to ensure the coordinates reflect a valid rectangular region,
where (x1, y1) represent the top-left corner, and (x2, y2) represent the bottom-right corner.
- Author:
- Syam
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that initializes the Coordinates object with zero values for all points.Coordinates(double x1, double y1, double x2, double y2) Constructs aCoordinatesobject by defining a rectangular region based on two points (x1, y1) and (x2, y2).Coordinates(Node node) Constructs aCoordinatesobject by initializing the rectangular region using the coordinates of the givenNodeobject.Coordinates(Point p) Constructs aCoordinatesobject by defining a rectangular region where both the top-left and bottom-right corners are represented by the samePoint.Coordinates(Point p1, Point p2) Constructs aCoordinatesobject by defining a rectangular region based on twoPointobjects. -
Method Summary
Modifier and TypeMethodDescriptionCombines the currentCoordinatesobject with the specifiedCoordinatesobject to create a new rectangular region.Combines the currentCoordinatesobject with the rectangular region represented by the givenNodeobject.Combines the currentCoordinatesobject with a rectangular region derived from the specifiedPointobject.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doubleheight()Calculates the height of the rectangular region based on the difference between the y-coordinates of the bottom-right and top-left corners.voidSets the coordinates of the givenNodeobject to match the currentCoordinatesobject.final StringtoString()Returns a string representation of this record class.doublewidth()Calculates the width of the rectangular region based on the difference between the x-coordinates of the bottom-right and top-left corners.doublex1()Returns the value of thex1record component.doublex2()Returns the value of thex2record component.doubley1()Returns the value of they1record component.doubley2()Returns the value of they2record component.
-
Constructor Details
-
Coordinates
public Coordinates()Default constructor that initializes the Coordinates object with zero values for all points. This results in a rectangle represented by the top-left corner (0, 0) and bottom-right corner (0, 0). -
Coordinates
public Coordinates(double x1, double y1, double x2, double y2) Constructs aCoordinatesobject by defining a rectangular region based on two points (x1, y1) and (x2, y2). The coordinates are adjusted so that (x1, y1) represents the top-left corner and (x2, y2) represents the bottom-right corner of the rectangle.- Parameters:
x1- The x-coordinate of the first point.y1- The y-coordinate of the first point.x2- The x-coordinate of the second point.y2- The y-coordinate of the second point.
-
Coordinates
Constructs aCoordinatesobject by defining a rectangular region based on twoPointobjects. The coordinates are adjusted so that the rectangle is represented with the top-left corner as (x1, y1) and the bottom-right corner as (x2, y2).- Parameters:
p1- The first point defining the rectangular region.p2- The second point defining the rectangular region.
-
Coordinates
Constructs aCoordinatesobject by defining a rectangular region where both the top-left and bottom-right corners are represented by the samePoint. This effectively creates a rectangle with zero width and height at the given point.- Parameters:
p- The point defining both the top-left and bottom-right corners of the rectangular region.
-
Coordinates
Constructs aCoordinatesobject by initializing the rectangular region using the coordinates of the givenNodeobject. The coordinates from the node are used to represent the top-left corner (x1, y1) and the bottom-right corner (x2, y2) of the rectangle.- Parameters:
node- TheNodeobject providing the coordinates to initialize the rectangular region.
-
-
Method Details
-
width
public double width()Calculates the width of the rectangular region based on the difference between the x-coordinates of the bottom-right and top-left corners.- Returns:
- The width of the rectangular region.
-
height
public double height()Calculates the height of the rectangular region based on the difference between the y-coordinates of the bottom-right and top-left corners.- Returns:
- The height of the rectangular region.
-
combine
Combines the currentCoordinatesobject with the specifiedCoordinatesobject to create a new rectangular region. The resulting region is the smallest rectangle that can fully contain both the current and the specifiedCoordinates.- Parameters:
c- TheCoordinatesobject to combine with the current object.- Returns:
- A new
Coordinatesobject representing the combined rectangular region.
-
combine
Combines the currentCoordinatesobject with the rectangular region represented by the givenNodeobject. The resultingCoordinatesrepresents the smallest rectangle that can fully contain both the current region and the region derived from the specifiedNode.- Parameters:
node- TheNodeobject containing the coordinates to be combined.- Returns:
- A new
Coordinatesobject representing the combined rectangular region.
-
combine
Combines the currentCoordinatesobject with a rectangular region derived from the specifiedPointobject. The resulting region is the smallest rectangle that can fully contain both the currentCoordinatesand the region represented by the specifiedPoint.- Parameters:
p- ThePointobject whose coordinates are used to define the rectangular region to combine with.- Returns:
- A new
Coordinatesobject representing the combined rectangular region.
-
setTo
Sets the coordinates of the givenNodeobject to match the currentCoordinatesobject. The fieldsx1,y1,x2, andy2of the providedNodeare updated using the corresponding values from thisCoordinatesobject.- Parameters:
node- TheNodeobject whose coordinates will be updated.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
x1
-
y1
-
x2
-
y2
-