comparison Framework/Scene2D/ScenePoint2D.h @ 901:240359ab1651

Added Dot + magnitude + couple helpers in ScenePoint2D + Added ability to target several sets of 5-layer text packs stored in LayerHolder
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 17 Jul 2019 09:39:51 +0200
parents c71ef52602a0
children 59906485896f 2d8ab34c8c91
comparison
equal deleted inserted replaced
899:a8e3d686b43e 901:240359ab1651
89 v.y_ = y_ * a; 89 v.y_ = y_ * a;
90 90
91 return v; 91 return v;
92 } 92 }
93 93
94 const ScenePoint2D operator/(double a) const
95 {
96 ScenePoint2D v;
97 v.x_ = x_ / a;
98 v.y_ = y_ / a;
99
100 return v;
101 }
102
103 static void MidPoint(ScenePoint2D& result, const ScenePoint2D& a, const ScenePoint2D& b)
104 {
105 result.x_ = 0.5 * (a.x_ + b.x_);
106 result.y_ = 0.5 * (a.y_ + b.y_);
107 }
108
94 static double Dot(const ScenePoint2D& a, const ScenePoint2D& b) 109 static double Dot(const ScenePoint2D& a, const ScenePoint2D& b)
95 { 110 {
96 return a.x_ * b.x_ + a.y_ * b.y_; 111 return a.x_ * b.x_ + a.y_ * b.y_;
112 }
113
114 static double SquaredMagnitude(const ScenePoint2D& v)
115 {
116 return v.x_ * v.x_ + v.y_ * v.y_;
117 }
118
119 static double Magnitude(const ScenePoint2D& v)
120 {
121 double squaredMagnitude = SquaredMagnitude(v);
122 if (LinearAlgebra::IsCloseToZero(squaredMagnitude))
123 return 0.0;
124 return sqrt(squaredMagnitude);
97 } 125 }
98 126
99 static double SquaredDistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b) 127 static double SquaredDistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b)
100 { 128 {
101 ScenePoint2D n = b - a; 129 ScenePoint2D n = b - a;
102 return Dot(n, n); 130 return Dot(n, n);
131 }
132
133 static double DistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b)
134 {
135 double squaredDist = SquaredDistancePtPt(a, b);
136 return sqrt(squaredDist);
103 } 137 }
104 138
105 /** 139 /**
106 Distance from point p to [a,b] segment 140 Distance from point p to [a,b] segment
107 141