forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxLine.java
More file actions
100 lines (89 loc) · 2.09 KB
/
mxLine.java
File metadata and controls
100 lines (89 loc) · 2.09 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
/**
* Copyright (c) 2007-2010, Gaudenz Alder, David Benson
*/
package com.mxgraph.util;
import java.awt.geom.Line2D;
/**
* Implements a line with double precision coordinates.
*/
public class mxLine extends mxPoint
{
/**
*
*/
private static final long serialVersionUID = -4730972599169158546L;
/**
* The end point of the line
*/
protected mxPoint endPoint;
/**
* Creates a new line
*/
public mxLine(mxPoint startPt, mxPoint endPt)
{
this.setX(startPt.getX());
this.setY(startPt.getY());
this.endPoint = endPt;
}
/**
* Creates a new line
*/
public mxLine(double startPtX, double startPtY, mxPoint endPt)
{
x = startPtX;
y = startPtY;
this.endPoint = endPt;
}
/**
* Returns the end point of the line.
*
* @return Returns the end point of the line.
*/
public mxPoint getEndPoint()
{
return this.endPoint;
}
/**
* Sets the end point of the rectangle.
*
* @param value The new end point of the line
*/
public void setEndPoint(mxPoint value)
{
this.endPoint = value;
}
/**
* Sets the start and end points.
*/
public void setPoints(mxPoint startPt, mxPoint endPt)
{
this.setX(startPt.getX());
this.setY(startPt.getY());
this.endPoint = endPt;
}
/**
* Returns the square of the shortest distance from a point to this line.
* The line is considered extrapolated infinitely in both directions for
* the purposes of the calculation.
*
* @param pt the point whose distance is being measured
* @return the square of the distance from the specified point to this line.
*/
public double ptLineDistSq(mxPoint pt)
{
return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint
.getY()).ptLineDistSq(pt.getX(), pt.getY());
}
/**
* Returns the square of the shortest distance from a point to this
* line segment.
*
* @param pt the point whose distance is being measured
* @return the square of the distance from the specified point to this segment.
*/
public double ptSegDistSq(mxPoint pt)
{
return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint
.getY()).ptSegDistSq(pt.getX(), pt.getY());
}
}