line.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib 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 ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Mark Page
27 */
28 
29 
30 #pragma once
31 
32 
33 namespace clan
34 {
37 
38 template<typename Type>
39 class Line2x;
40 
41 template<typename Type>
42 class Line3x;
43 
44 template<typename Type>
45 class Rectx;
46 
47 template<typename Type>
48 class Vec2;
49 
50 class Angle;
51 
55 template<typename Type>
56 class Line3x
57 {
58 public:
61 
62  Line3x(): p(), q() {}
63  Line3x(const Line3x<Type> &copy): p(copy.p), q(copy.q) {}
64  Line3x(const Vec3<Type> &point_p, const Vec3<Type> &point_q): p(point_p), q(point_q) {}
65 
68 public:
75  Vec3<Type> get_intersection( const Line3x<Type> &second, bool &intersect, Type range = (Type) 0.5 ) const;
76 
80 public:
82  Line3x<Type> &operator = (const Line3x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
83 
85  bool operator == (const Line3x<Type>& line) const {return ((p == line.p) && (q == line.q));}
86 
88  bool operator != (const Line3x<Type>& line) const {return ((p != line.p) || (q != line.q));}
90 };
91 
95 template<typename Type>
96 class Line2x
97 {
98 public:
101 
102  // \brief Another point on the line
104 
105  Line2x(): p(), q() { }
106  Line2x(const Line2x<Type> &copy): p(copy.p), q(copy.q) {}
107  Line2x(const Vec2<Type> &point_p, const Vec2<Type> &point_q): p(point_p), q(point_q) {}
108  Line2x(const Vec2<Type> &point_p, Type gradient): p(point_p), q(static_cast<Type> (1), gradient) {}
109 
112 public:
118  Vec2<Type> get_intersection( const Line2x<Type> &second, bool &intersect ) const;
119 
124  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);}
125 
129 
130 public:
131 
135 public:
137  Line2x<Type> &operator = (const Line2x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
138 
140  bool operator == (const Line2x<Type>& line) const {return ((p == line.p) && (q == line.q));}
141 
143  bool operator != (const Line2x<Type>& line) const {return ((p != line.p) || (q != line.q));}
145 };
146 
148 class Line2 : public Line2x<int>
149 {
150 public:
151  Line2() : Line2x<int>() { }
152  Line2(const Line2x<int> &copy) : Line2x<int>(copy) { }
153  Line2(const Vec2<int> &point_p, const Vec2<int> &point_q) : Line2x<int>(point_p, point_q) { }
154  Line2(const Vec2<int> &point_p, int gradient) : Line2x<int>(point_p, gradient) { }
155 };
156 
158 class Line2f : public Line2x<float>
159 {
160 public:
161  Line2f() : Line2x<float>() { }
162  Line2f(const Line2x<float> &copy) : Line2x<float>(copy) { }
163  Line2f(const Vec2<float> &point_p, const Vec2<float> &point_q) : Line2x<float>(point_p, point_q) { }
164  Line2f(const Vec2<float> &point_p, float gradient) : Line2x<float>(point_p, gradient) { }
165 };
166 
168 class Line2d : public Line2x<double>
169 {
170 public:
171  Line2d() : Line2x<double>() { }
172  Line2d(const Line2x<double> &copy) : Line2x<double>(copy) { }
173  Line2d(const Vec2<double> &point_p, const Vec2<double> &point_q) : Line2x<double>(point_p, point_q) { }
174  Line2d(const Vec2<double> &point_p, double gradient) : Line2x<double>(point_p, gradient) { }
175 };
176 
178 class Line3 : public Line3x<int>
179 {
180 public:
181  Line3() : Line3x<int>() { }
182  Line3(const Line3x<int> &copy) : Line3x<int>(copy) { }
183  Line3(const Vec3<int> &point_p, const Vec3<int> &point_q) : Line3x<int>(point_p, point_q) { }
184 };
185 
187 class Line3f : public Line3x<float>
188 {
189 public:
190  Line3f() : Line3x<float>() { }
191  Line3f(const Line3x<float> &copy) : Line3x<float>(copy) { }
192  Line3f(const Vec3<float> &point_p, const Vec3<float> &point_q) : Line3x<float>(point_p, point_q) { }
193 };
194 
196 class Line3d : public Line3x<double>
197 {
198 public:
199  Line3d() : Line3x<double>() { }
200  Line3d(const Line3x<double> &copy) : Line3x<double>(copy) { }
201  Line3d(const Vec3<double> &podouble_p, const Vec3<double> &podouble_q) : Line3x<double>(podouble_p, podouble_q) { }
202 };
203 
204 }
205 
206 /// \}
Line2()
Definition: line.h:151
Line3(const Vec3< int > &point_p, const Vec3< int > &point_q)
Definition: line.h:183
bool operator==(const Line2x< Type > &line) const
== operator.
Definition: line.h:140
Type y
Definition: vec2.h:81
Line3f()
Definition: line.h:190
3D line - Float
Definition: line.h:188
2D (left,top,right,bottom) rectangle structure.
Definition: line.h:45
Line2x< Type > & operator=(const Line2x< Type > &copy)
= operator.
Definition: line.h:137
bool operator!=(const Line3x< Type > &line) const
!= operator.
Definition: line.h:88
3D line
Definition: line.h:42
Line2(const Vec2< int > &point_p, const Vec2< int > &point_q)
Definition: line.h:153
Line2d(const Vec2< double > &point_p, const Vec2< double > &point_q)
Definition: line.h:173
Line2f()
Definition: line.h:161
2D line - Double
Definition: line.h:169
Line3f(const Line3x< float > &copy)
Definition: line.h:191
Line2x(const Vec2< Type > &point_p, Type gradient)
Definition: line.h:108
Line3()
Definition: line.h:181
Vec3< Type > p
Definition: line.h:59
bool operator!=(const Line2x< Type > &line) const
!= operator.
Definition: line.h:143
Line2d()
Definition: line.h:171
Line2f(const Vec2< float > &point_p, float gradient)
Definition: line.h:164
Type x
Definition: vec2.h:80
Line3(const Line3x< int > &copy)
Definition: line.h:182
Vec2< Type > p
First point on the line.
Definition: line.h:100
Angle class.
Definition: angle.h:63
Line3x< Type > & operator=(const Line3x< Type > &copy)
= operator.
Definition: line.h:82
Line3x()
Definition: line.h:62
2D vector
Definition: line.h:48
Vec3< Type > get_intersection(const Line3x< Type > &second, bool &intersect, Type range=(Type) 0.5) const
Return the intersection of this and other line.
2D line
Definition: line.h:39
Line3x(const Line3x< Type > &copy)
Definition: line.h:63
Line2d(const Vec2< double > &point_p, double gradient)
Definition: line.h:174
Line2x(const Line2x< Type > &copy)
Definition: line.h:106
Vec2< Type > get_intersection(const Line2x< Type > &second, bool &intersect) const
Return the intersection of this and other line.
Line3x(const Vec3< Type > &point_p, const Vec3< Type > &point_q)
Definition: line.h:64
Vec2< Type > q
Definition: line.h:103
2D line - Integer
Definition: line.h:149
Line2d(const Line2x< double > &copy)
Definition: line.h:172
Line2x(const Vec2< Type > &point_p, const Vec2< Type > &point_q)
Definition: line.h:107
2D line - Float
Definition: line.h:159
Definition: clanapp.h:36
3D line - Double
Definition: line.h:197
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:124
Vec3< Type > q
Definition: line.h:60
3D line - Integer
Definition: line.h:179
Line2x()
Definition: line.h:105
bool operator==(const Line3x< Type > &line) const
== operator.
Definition: line.h:85
Line2f(const Vec2< float > &point_p, const Vec2< float > &point_q)
Definition: line.h:163
Line3f(const Vec3< float > &point_p, const Vec3< float > &point_q)
Definition: line.h:192
3D vector
Definition: line_ray.h:48
Line3d()
Definition: line.h:199
Line3d(const Line3x< double > &copy)
Definition: line.h:200
Line2(const Line2x< int > &copy)
Definition: line.h:152
Line2(const Vec2< int > &point_p, int gradient)
Definition: line.h:154
Line3d(const Vec3< double > &podouble_p, const Vec3< double > &podouble_q)
Definition: line.h:201
Line2f(const Line2x< float > &copy)
Definition: line.h:162