Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/ScenePoint2D.h @ 866:c71ef52602a0 toa2019062501
Added the ability to edit existing measuring tools (demo not updated yet)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 25 Jun 2019 17:54:46 +0200 |
parents | a29c13497557 |
children | 240359ab1651 |
rev | line source |
---|---|
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
16 * |
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #pragma once |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../Toolbox/AffineTransform2D.h" |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
25 #include "../Toolbox/LinearAlgebra.h" |
699 | 26 |
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 namespace OrthancStone |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 class ScenePoint2D |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 private: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 double x_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 double y_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 public: |
596 | 36 ScenePoint2D() : |
37 x_(0), | |
38 y_(0) | |
39 { | |
40 } | |
41 | |
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 ScenePoint2D(double x, |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
43 double y) : |
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 x_(x), |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 y_(y) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 double GetX() const |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 return x_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 double GetY() const |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 return y_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 ScenePoint2D Apply(const AffineTransform2D& t) const |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 double x = x_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 double y = y_; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 t.Apply(x, y); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 return ScenePoint2D(x, y); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 } |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
66 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
67 const ScenePoint2D operator-(const ScenePoint2D& a) const |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
68 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
69 ScenePoint2D v; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
70 v.x_ = x_ - a.x_; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
71 v.y_ = y_ - a.y_; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
72 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
73 return v; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
74 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
75 |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
76 const ScenePoint2D operator+(const ScenePoint2D& a) const |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
77 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
78 ScenePoint2D v; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
79 v.x_ = x_ + a.x_; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
80 v.y_ = y_ + a.y_; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
81 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
82 return v; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
83 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
865
diff
changeset
|
84 |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
85 const ScenePoint2D operator*(double a) const |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
86 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
87 ScenePoint2D v; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
88 v.x_ = x_ * a; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
89 v.y_ = y_ * a; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
90 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
91 return v; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
92 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
93 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
94 static double Dot(const ScenePoint2D& a, const ScenePoint2D& b) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
95 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
96 return a.x_ * b.x_ + a.y_ * b.y_; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
97 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
98 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
99 static double SquaredDistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
100 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
101 ScenePoint2D n = b - a; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
102 return Dot(n, n); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
103 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
104 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
105 /** |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
106 Distance from point p to [a,b] segment |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
107 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
108 Rewritten from https://www.randygaul.net/2014/07/23/distance-point-to-line-segment/ |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
109 */ |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
110 static double SquaredDistancePtSegment(const ScenePoint2D& a, const ScenePoint2D& b, const ScenePoint2D& p) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
111 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
112 ScenePoint2D n = b - a; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
113 ScenePoint2D pa = a - p; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
114 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
115 double c = Dot(n, pa); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
116 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
117 // Closest point is a |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
118 if (c > 0.0) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
119 return Dot(pa, pa); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
120 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
121 ScenePoint2D bp = p - b; |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
122 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
123 // Closest point is b |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
124 if (Dot(n, bp) > 0.0) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
125 return Dot(bp, bp); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
126 |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
127 // if segment length is very short, we approximate distance to the |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
128 // distance with a |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
129 double nq = Dot(n, n); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
130 if (LinearAlgebra::IsCloseToZero(nq)) |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
131 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
132 // segment is very small: approximate distance from point to segment |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
133 // with distance from p to a |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
134 return Dot(pa, pa); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
135 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
136 else |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
137 { |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
138 // Closest point is between a and b |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
139 ScenePoint2D e = pa - n * (c / nq); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
140 return Dot(e, e); |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
141 } |
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
142 } |
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 }; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 } |
865
a29c13497557
Added operators to ScenePoint2D + highlight support on MouseOver for measuring tools
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
145 |