line.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries UICore may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Mark Page
27 */
28 
29 #pragma once
30 
31 namespace uicore
32 {
33  template<typename Type>
34  class Line2x;
35 
36  template<typename Type>
37  class Line3x;
38 
39  template<typename Type>
40  class Rectx;
41 
42  template<typename Type>
43  class Vec2;
44 
48  template<typename Type>
49  class Line3x
50  {
51  public:
54 
55  Line3x() : p(), q() {}
56  Line3x(const Line3x<Type> &copy) : p(copy.p), q(copy.q) {}
57  Line3x(const Vec3<Type> &point_p, const Vec3<Type> &point_q) : p(point_p), q(point_q) {}
58 
65  Vec3<Type> intersection(const Line3x<Type> &second, bool &intersect, Type range = (Type) 0.5) const;
66 
68  Line3x<Type> &operator = (const Line3x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
69 
71  bool operator == (const Line3x<Type>& line) const { return ((p == line.p) && (q == line.q)); }
72 
74  bool operator != (const Line3x<Type>& line) const { return ((p != line.p) || (q != line.q)); }
75  };
76 
80  template<typename Type>
81  class Line2x
82  {
83  public:
86 
87  // \brief Another point on the line
89 
90  Line2x() : p(), q() { }
91  Line2x(const Line2x<Type> &copy) : p(copy.p), q(copy.q) {}
92  Line2x(const Vec2<Type> &point_p, const Vec2<Type> &point_q) : p(point_p), q(point_q) {}
93  Line2x(const Vec2<Type> &point_p, Type gradient) : p(point_p), q(static_cast<Type> (1), gradient) {}
94 
100  Vec2<Type> intersection(const Line2x<Type> &second, bool &intersect) const;
101 
106  Type point_right_of_line(Vec2<Type> point) const { return (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y); }
107 
109  Line2x<Type> &operator = (const Line2x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
110 
112  bool operator == (const Line2x<Type>& line) const { return ((p == line.p) && (q == line.q)); }
113 
115  bool operator != (const Line2x<Type>& line) const { return ((p != line.p) || (q != line.q)); }
116  };
117 
119  class Line2 : public Line2x<int>
120  {
121  public:
122  Line2() : Line2x<int>() { }
123  Line2(const Line2x<int> &copy) : Line2x<int>(copy) { }
124  Line2(const Vec2<int> &point_p, const Vec2<int> &point_q) : Line2x<int>(point_p, point_q) { }
125  Line2(const Vec2<int> &point_p, int gradient) : Line2x<int>(point_p, gradient) { }
126  };
127 
129  class Line2f : public Line2x<float>
130  {
131  public:
132  Line2f() : Line2x<float>() { }
133  Line2f(const Line2x<float> &copy) : Line2x<float>(copy) { }
134  Line2f(const Vec2<float> &point_p, const Vec2<float> &point_q) : Line2x<float>(point_p, point_q) { }
135  Line2f(const Vec2<float> &point_p, float gradient) : Line2x<float>(point_p, gradient) { }
136  };
137 
139  class Line2d : public Line2x<double>
140  {
141  public:
142  Line2d() : Line2x<double>() { }
143  Line2d(const Line2x<double> &copy) : Line2x<double>(copy) { }
144  Line2d(const Vec2<double> &point_p, const Vec2<double> &point_q) : Line2x<double>(point_p, point_q) { }
145  Line2d(const Vec2<double> &point_p, double gradient) : Line2x<double>(point_p, gradient) { }
146  };
147 
149  class Line3 : public Line3x<int>
150  {
151  public:
152  Line3() : Line3x<int>() { }
153  Line3(const Line3x<int> &copy) : Line3x<int>(copy) { }
154  Line3(const Vec3<int> &point_p, const Vec3<int> &point_q) : Line3x<int>(point_p, point_q) { }
155  };
156 
158  class Line3f : public Line3x<float>
159  {
160  public:
161  Line3f() : Line3x<float>() { }
162  Line3f(const Line3x<float> &copy) : Line3x<float>(copy) { }
163  Line3f(const Vec3<float> &point_p, const Vec3<float> &point_q) : Line3x<float>(point_p, point_q) { }
164  };
165 
167  class Line3d : public Line3x<double>
168  {
169  public:
170  Line3d() : Line3x<double>() { }
171  Line3d(const Line3x<double> &copy) : Line3x<double>(copy) { }
172  Line3d(const Vec3<double> &podouble_p, const Vec3<double> &podouble_q) : Line3x<double>(podouble_p, podouble_q) { }
173  };
174 }
Line3()
Definition: line.h:152
Line2d()
Definition: line.h:142
Line3x()
Definition: line.h:55
bool operator!=(const Line2x< Type > &line) const
!= operator.
Definition: line.h:115
Vec3< Type > intersection(const Line3x< Type > &second, bool &intersect, Type range=(Type) 0.5) const
Return the intersection of this and other line.
2D vector
Definition: line.h:43
Line2x< Type > & operator=(const Line2x< Type > &copy)
= operator.
Definition: line.h:109
Line3(const Line3x< int > &copy)
Definition: line.h:153
Line3(const Vec3< int > &point_p, const Vec3< int > &point_q)
Definition: line.h:154
3D vector
Definition: line_ray.h:43
Vec2< Type > intersection(const Line2x< Type > &second, bool &intersect) const
Return the intersection of this and other line.
Line3d(const Line3x< double > &copy)
Definition: line.h:171
Line3d()
Definition: line.h:170
2D line
Definition: line.h:34
Type x
Definition: vec2.h:75
Vec3< Type > q
Definition: line.h:53
Line3f()
Definition: line.h:161
Vec2< Type > p
First point on the line.
Definition: line.h:85
Line2(const Line2x< int > &copy)
Definition: line.h:123
Line2d(const Line2x< double > &copy)
Definition: line.h:143
Line2f(const Vec2< float > &point_p, float gradient)
Definition: line.h:135
3D line - Integer
Definition: line.h:149
Line2x(const Vec2< Type > &point_p, const Vec2< Type > &point_q)
Definition: line.h:92
Line2f(const Vec2< float > &point_p, const Vec2< float > &point_q)
Definition: line.h:134
3D line - Double
Definition: line.h:167
Line3x< Type > & operator=(const Line3x< Type > &copy)
= operator.
Definition: line.h:68
Line2()
Definition: line.h:122
2D line - Float
Definition: line.h:129
Line2x()
Definition: line.h:90
bool operator!=(const Line3x< Type > &line) const
!= operator.
Definition: line.h:74
Type y
Definition: vec2.h:76
Line2x(const Vec2< Type > &point_p, Type gradient)
Definition: line.h:93
Line2f(const Line2x< float > &copy)
Definition: line.h:133
Type point_right_of_line(Vec2< Type > point) const
Return [<0, 0, >0] if the Point P is right, on or left of the line trough A,B.
Definition: line.h:106
Line2x(const Line2x< Type > &copy)
Definition: line.h:91
Line3f(const Vec3< float > &point_p, const Vec3< float > &point_q)
Definition: line.h:163
Line2(const Vec2< int > &point_p, int gradient)
Definition: line.h:125
bool operator==(const Line3x< Type > &line) const
== operator.
Definition: line.h:71
Line2(const Vec2< int > &point_p, const Vec2< int > &point_q)
Definition: line.h:124
Vec3< Type > p
Definition: line.h:52
2D (left,top,right,bottom) rectangle structure.
Definition: line.h:40
3D line
Definition: line.h:37
Vec2< Type > q
Definition: line.h:88
Line3f(const Line3x< float > &copy)
Definition: line.h:162
bool operator==(const Line2x< Type > &line) const
== operator.
Definition: line.h:112
Line2d(const Vec2< double > &point_p, double gradient)
Definition: line.h:145
2D line - Integer
Definition: line.h:119
Line3x(const Line3x< Type > &copy)
Definition: line.h:56
2D line - Double
Definition: line.h:139
Line2d(const Vec2< double > &point_p, const Vec2< double > &point_q)
Definition: line.h:144
Line2f()
Definition: line.h:132
Line3x(const Vec3< Type > &point_p, const Vec3< Type > &point_q)
Definition: line.h:57
3D line - Float
Definition: line.h:158
Definition: Application/application.h:35
Line3d(const Vec3< double > &podouble_p, const Vec3< double > &podouble_q)
Definition: line.h:172