projects
/
anneal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
checkpoint
[anneal.git]
/
src
/
edu
/
berkeley
/
qfat
/
geom
/
Segment.java
diff --git
a/src/edu/berkeley/qfat/geom/Segment.java
b/src/edu/berkeley/qfat/geom/Segment.java
index
5f46051
..
fa303d1
100644
(file)
--- a/
src/edu/berkeley/qfat/geom/Segment.java
+++ b/
src/edu/berkeley/qfat/geom/Segment.java
@@
-25,8
+25,18
@@
public class Segment implements HasBoundingBox {
public float getMaxZ() { return Math.max(p1.z, p2.z); }
public float getMinZ() { return Math.min(p1.z, p2.z); }
public float getMaxZ() { return Math.max(p1.z, p2.z); }
public float getMinZ() { return Math.min(p1.z, p2.z); }
+ /** the line passing through both endpoints of this segment */
+ public Line getLine() { return new Line(p1, p2); }
+
+ public float length() { return p1.distance(p2); }
+
public double distance(Point p) {
public double distance(Point p) {
- throw new RuntimeException("not yet implemented");
+ Line line = getLine();
+ Point proj = line.projection(p);
+ if (proj.distance(p1)+proj.distance(p2) > length())
+ return Math.min(p1.distance(p),
+ p2.distance(p));
+ return proj.distance(p);
}
}
}
}