aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-02 00:51:55 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-02 00:51:55 +0100
commit837dc3e832b44e7ce74b212c239c99acf3fcf9a2 (patch)
tree955aa6bbd9ab05ccf61fff99c1f239e6f9aa72f3
parentcbcc1513db57c2086fbfc469b3bb064975b297b6 (diff)
downloadRobotique-Projet-837dc3e832b44e7ce74b212c239c99acf3fcf9a2.tar.gz
Robotique-Projet-837dc3e832b44e7ce74b212c239c99acf3fcf9a2.zip
Fix
-rw-r--r--geom.hpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/geom.hpp b/geom.hpp
index aecc822..9038f69 100644
--- a/geom.hpp
+++ b/geom.hpp
@@ -85,9 +85,10 @@ struct line {
line(double aa, double bb, double cc) : a(aa), b(bb), c(cc) {}
line(vec p1, vec p2) {
- a = p1.x-p2.x ;
- b = p1.y-p2.y ;
- c = p1.x*(p2.x-p1.x)+p1.y*(p2.y-p1.y);
+ vec d = p2 - p1;
+ a = d.y ;
+ b = -d.x ;
+ c = - (p1.x * a + p2.x * b);
}
bool on_line(vec p) const {
@@ -129,8 +130,7 @@ struct segment {
double dist(vec p) const {
double scal = vec::dot(b-a, p-a);
double sqn = (b-a).sqnorm();
- if (scal > sqn) return (p-b).norm();
- if (scal < 0) return (p-a).norm();
+ if (scal > sqn || scal < 0) return std::min((p-b).norm(), (p-a).norm());
return line(a,b).dist(p);
}
};