summaryrefslogtreecommitdiffstats
path: root/Project/Element.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-04-24 17:39:03 -0300
committerGitHub <noreply@github.com>2017-04-24 17:39:03 -0300
commit7804c1bd2c0bd2a5f135c30b20991e8187581cc6 (patch)
tree725e524253d6fd714460402194b408cb33b80b3f /Project/Element.cpp
parent69131a727782090ffd7cb467f449e8f26d3d2949 (diff)
parent9529a6ed44645842adc6f938478acc1dfa17a284 (diff)
downloadPSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.tar.gz
PSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.tar.xz
PSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.zip
Merge pull request #28 from Thales1330/wip/generic-controllers
Wip generic controllers. Chart view implementation required, creating new branch....
Diffstat (limited to 'Project/Element.cpp')
-rw-r--r--Project/Element.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/Project/Element.cpp b/Project/Element.cpp
index fa08905..ca24196 100644
--- a/Project/Element.cpp
+++ b/Project/Element.cpp
@@ -1,6 +1,6 @@
#include "Element.h"
-Element::Element() {}
+Element::Element() { m_selectionColour.SetRGBA(0.0, 0.5, 1.0, 0.5); }
Element::~Element() {}
@@ -357,3 +357,38 @@ OpenGLColour::OpenGLColour(GLdouble red, GLdouble green, GLdouble blue, GLdouble
{
SetRGBA(red, green, blue, alpha);
}
+
+double Element::PointToLineDistance(wxPoint2DDouble point, int* segmentNumber) const
+{
+ //[Ref] http://geomalgorithms.com/a02-_lines.html
+ double distance = 100.0; // Big initial distance.
+ wxPoint2DDouble p0 = point;
+
+ for(int i = 1; i < (int)m_pointList.size() - 2; i++) {
+ double d = 0.0;
+
+ wxPoint2DDouble p1 = m_pointList[i];
+ wxPoint2DDouble p2 = m_pointList[i + 1];
+
+ wxPoint2DDouble v = p2 - p1;
+ wxPoint2DDouble w = p0 - p1;
+
+ double c1 = w.m_x * v.m_x + w.m_y * v.m_y;
+ double c2 = v.m_x * v.m_x + v.m_y * v.m_y;
+
+ if(c1 <= 0.0) {
+ d = std::sqrt(std::pow(p0.m_y - p1.m_y, 2) + std::pow(p0.m_x - p1.m_x, 2));
+ } else if(c2 <= c1) {
+ d = std::sqrt(std::pow(p0.m_y - p2.m_y, 2) + std::pow(p0.m_x - p2.m_x, 2));
+ } else {
+ d = std::abs((p2.m_y - p1.m_y) * p0.m_x - (p2.m_x - p1.m_x) * p0.m_y + p2.m_x * p1.m_y - p2.m_y * p1.m_x) /
+ std::sqrt(std::pow(p2.m_y - p1.m_y, 2) + std::pow(p2.m_x - p1.m_x, 2));
+ }
+ if(d < distance) {
+ distance = d;
+ if(segmentNumber) *segmentNumber = i;
+ }
+ }
+
+ return distance;
+}