forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxPoint.java
More file actions
174 lines (151 loc) · 2.99 KB
/
mxPoint.java
File metadata and controls
174 lines (151 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Copyright (c) 2007-2010, Gaudenz Alder, David Benson
*/
package com.mxgraph.util;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.io.Serializable;
/**
* Implements a 2-dimensional point with double precision coordinates.
*/
public class mxPoint implements Serializable, Cloneable
{
/**
*
*/
private static final long serialVersionUID = 6554231393215892186L;
/**
* Holds the x- and y-coordinates of the point. Default is 0.
*/
protected double x, y;
/**
* Constructs a new point at (0, 0).
*/
public mxPoint()
{
this(0, 0);
}
/**
* Constructs a new point at the location of the given point.
*
* @param point Point that specifies the location.
*/
public mxPoint(Point2D point)
{
this(point.getX(), point.getY());
}
/**
* Constructs a new point at the location of the given point.
*
* @param point Point that specifies the location.
*/
public mxPoint(mxPoint point)
{
this(point.getX(), point.getY());
}
/**
* Constructs a new point at (x, y).
*
* @param x X-coordinate of the point to be created.
* @param y Y-coordinate of the point to be created.
*/
public mxPoint(double x, double y)
{
setX(x);
setY(y);
}
/**
* Returns the x-coordinate of the point.
*
* @return Returns the x-coordinate.
*/
public double getX()
{
return x;
}
/**
* Sets the x-coordinate of the point.
*
* @param value Double that specifies the new x-coordinate.
*/
public void setX(double value)
{
x = value;
}
/**
* Returns the x-coordinate of the point.
*
* @return Returns the x-coordinate.
*/
public double getY()
{
return y;
}
/**
* Sets the y-coordinate of the point.
*
* @param value Double that specifies the new x-coordinate.
*/
public void setY(double value)
{
y = value;
}
/**
* Returns the coordinates as a new point.
*
* @return Returns a new point for the location.
*/
public Point getPoint()
{
return new Point((int) Math.round(x), (int) Math.round(y));
}
/**
*
* Returns true if the given object equals this rectangle.
*/
public boolean equals(Object obj)
{
if (obj instanceof mxPoint)
{
mxPoint pt = (mxPoint) obj;
return pt.getX() == getX() && pt.getY() == getY();
}
return false;
}
/**
* Returns a new instance of the same point.
*/
public Object clone()
{
mxPoint clone;
try
{
clone = (mxPoint) super.clone();
}
catch (CloneNotSupportedException e)
{
clone = new mxPoint();
}
clone.setX(getX());
clone.setY(getY());
return clone;
}
/**
* Returns a <code>String</code> that represents the value
* of this <code>mxPoint</code>.
* @return a string representation of this <code>mxPoint</code>.
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(16);
builder.append(getClass().getSimpleName());
builder.append(" [");
builder.append("x=");
builder.append(x);
builder.append(", y=");
builder.append(y);
builder.append("]");
return builder.toString();
}
}