line.h Source File - ClanLib SDK
Description: line.h Source File

line.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31namespace clan
32{
35
36 template<typename Type>
37 class Line2x;
38
39 template<typename Type>
40 class Line3x;
41
42 template<typename Type>
43 class Rectx;
44
45 template<typename Type>
46 class Vec2;
47
48 class Angle;
49
53 template<typename Type>
54 class Line3x
55 {
56 public:
57 Vec3<Type> p;
58 Vec3<Type> q;
59
60 Line3x() : p(), q() {}
61 Line3x(const Line3x<Type> &copy) : p(copy.p), q(copy.q) {}
62 Line3x(const Vec3<Type> &point_p, const Vec3<Type> &point_q) : p(point_p), q(point_q) {}
63
70 Vec3<Type> get_intersection(const Line3x<Type> &second, bool &intersect, Type range = (Type) 0.5) const;
71
73 Line3x<Type> &operator = (const Line3x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
74
76 bool operator == (const Line3x<Type>& line) const { return ((p == line.p) && (q == line.q)); }
77
79 bool operator != (const Line3x<Type>& line) const { return ((p != line.p) || (q != line.q)); }
80 };
81
85 template<typename Type>
86 class Line2x
87 {
88 public:
90 Vec2<Type> p;
91
92 // \brief Another point on the line
93 Vec2<Type> q;
94
95 Line2x() : p(), q() { }
96 Line2x(const Line2x<Type> &copy) : p(copy.p), q(copy.q) {}
97 Line2x(const Vec2<Type> &point_p, const Vec2<Type> &point_q) : p(point_p), q(point_q) {}
98 Line2x(const Vec2<Type> &point_p, Type gradient) : p(point_p), q(static_cast<Type> (1), gradient) {}
99
105 Vec2<Type> get_intersection(const Line2x<Type> &second, bool &intersect) const;
106
111 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); }
112
114 Line2x<Type> &operator = (const Line2x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
115
117 bool operator == (const Line2x<Type>& line) const { return ((p == line.p) && (q == line.q)); }
118
120 bool operator != (const Line2x<Type>& line) const { return ((p != line.p) || (q != line.q)); }
121 };
122
124 class Line2 : public Line2x<int>
125 {
126 public:
127 Line2() : Line2x<int>() { }
128 Line2(const Line2x<int> &copy) : Line2x<int>(copy) { }
129 Line2(const Vec2<int> &point_p, const Vec2<int> &point_q) : Line2x<int>(point_p, point_q) { }
130 Line2(const Vec2<int> &point_p, int gradient) : Line2x<int>(point_p, gradient) { }
131 };
132
134 class Line2f : public Line2x<float>
135 {
136 public:
137 Line2f() : Line2x<float>() { }
138 Line2f(const Line2x<float> &copy) : Line2x<float>(copy) { }
139 Line2f(const Vec2<float> &point_p, const Vec2<float> &point_q) : Line2x<float>(point_p, point_q) { }
140 Line2f(const Vec2<float> &point_p, float gradient) : Line2x<float>(point_p, gradient) { }
141 };
142
144 class Line2d : public Line2x<double>
145 {
146 public:
147 Line2d() : Line2x<double>() { }
148 Line2d(const Line2x<double> &copy) : Line2x<double>(copy) { }
149 Line2d(const Vec2<double> &point_p, const Vec2<double> &point_q) : Line2x<double>(point_p, point_q) { }
150 Line2d(const Vec2<double> &point_p, double gradient) : Line2x<double>(point_p, gradient) { }
151 };
152
154 class Line3 : public Line3x<int>
155 {
156 public:
157 Line3() : Line3x<int>() { }
158 Line3(const Line3x<int> &copy) : Line3x<int>(copy) { }
159 Line3(const Vec3<int> &point_p, const Vec3<int> &point_q) : Line3x<int>(point_p, point_q) { }
160 };
161
163 class Line3f : public Line3x<float>
164 {
165 public:
166 Line3f() : Line3x<float>() { }
167 Line3f(const Line3x<float> &copy) : Line3x<float>(copy) { }
168 Line3f(const Vec3<float> &point_p, const Vec3<float> &point_q) : Line3x<float>(point_p, point_q) { }
169 };
170
172 class Line3d : public Line3x<double>
173 {
174 public:
175 Line3d() : Line3x<double>() { }
176 Line3d(const Line3x<double> &copy) : Line3x<double>(copy) { }
177 Line3d(const Vec3<double> &podouble_p, const Vec3<double> &podouble_q) : Line3x<double>(podouble_p, podouble_q) { }
178 };
179
181}
clan::Line2
2D line - Integer
Definition line.h:125
clan::Line2::Line2
Line2(const Line2x< int > &copy)
Definition line.h:128
clan::Line2::Line2
Line2(const Vec2< int > &point_p, int gradient)
Definition line.h:130
clan::Line2::Line2
Line2(const Vec2< int > &point_p, const Vec2< int > &point_q)
Definition line.h:129
clan::Line2::Line2
Line2()
Definition line.h:127
clan::Line2d
2D line - Double
Definition line.h:145
clan::Line2d::Line2d
Line2d(const Vec2< double > &point_p, const Vec2< double > &point_q)
Definition line.h:149
clan::Line2d::Line2d
Line2d(const Line2x< double > &copy)
Definition line.h:148
clan::Line2d::Line2d
Line2d(const Vec2< double > &point_p, double gradient)
Definition line.h:150
clan::Line2d::Line2d
Line2d()
Definition line.h:147
clan::Line2f
2D line - Float
Definition line.h:135
clan::Line2f::Line2f
Line2f()
Definition line.h:137
clan::Line2f::Line2f
Line2f(const Vec2< float > &point_p, const Vec2< float > &point_q)
Definition line.h:139
clan::Line2f::Line2f
Line2f(const Vec2< float > &point_p, float gradient)
Definition line.h:140
clan::Line2f::Line2f
Line2f(const Line2x< float > &copy)
Definition line.h:138
clan::Line2x
2D line
Definition line.h:87
clan::Line2x::operator=
Line2x< Type > & operator=(const Line2x< Type > &copy)
= operator.
Definition line.h:114
clan::Line2x::Line2x
Line2x(const Vec2< Type > &point_p, const Vec2< Type > &point_q)
Definition line.h:97
clan::Line2x::operator!=
bool operator!=(const Line2x< Type > &line) const
!= operator.
Definition line.h:120
clan::Line2x::operator==
bool operator==(const Line2x< Type > &line) const
== operator.
Definition line.h:117
clan::Line2x::p
Vec2< Type > p
First point on the line.
Definition line.h:90
clan::Line2x::Line2x
Line2x()
Definition line.h:95
clan::Line2x::Line2x
Line2x(const Vec2< Type > &point_p, Type gradient)
Definition line.h:98
clan::Line2x::point_right_of_line
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:111
clan::Line2x::q
Vec2< Type > q
Definition line.h:93
clan::Line2x::get_intersection
Vec2< Type > get_intersection(const Line2x< Type > &second, bool &intersect) const
Return the intersection of this and other line.
clan::Line2x::Line2x
Line2x(const Line2x< Type > &copy)
Definition line.h:96
clan::Line3
3D line - Integer
Definition line.h:155
clan::Line3::Line3
Line3(const Line3x< int > &copy)
Definition line.h:158
clan::Line3::Line3
Line3()
Definition line.h:157
clan::Line3::Line3
Line3(const Vec3< int > &point_p, const Vec3< int > &point_q)
Definition line.h:159
clan::Line3d
3D line - Double
Definition line.h:173
clan::Line3d::Line3d
Line3d(const Vec3< double > &podouble_p, const Vec3< double > &podouble_q)
Definition line.h:177
clan::Line3d::Line3d
Line3d()
Definition line.h:175
clan::Line3d::Line3d
Line3d(const Line3x< double > &copy)
Definition line.h:176
clan::Line3f
3D line - Float
Definition line.h:164
clan::Line3f::Line3f
Line3f(const Line3x< float > &copy)
Definition line.h:167
clan::Line3f::Line3f
Line3f(const Vec3< float > &point_p, const Vec3< float > &point_q)
Definition line.h:168
clan::Line3f::Line3f
Line3f()
Definition line.h:166
clan::Line3x
3D line
Definition line.h:55
clan::Line3x::operator==
bool operator==(const Line3x< Type > &line) const
== operator.
Definition line.h:76
clan::Line3x::get_intersection
Vec3< Type > get_intersection(const Line3x< Type > &second, bool &intersect, Type range=(Type) 0.5) const
Return the intersection of this and other line.
clan::Line3x::operator!=
bool operator!=(const Line3x< Type > &line) const
!= operator.
Definition line.h:79
clan::Line3x::operator=
Line3x< Type > & operator=(const Line3x< Type > &copy)
= operator.
Definition line.h:73
clan::Line3x::Line3x
Line3x()
Definition line.h:60
clan::Line3x::p
Vec3< Type > p
Definition line.h:57
clan::Line3x::Line3x
Line3x(const Vec3< Type > &point_p, const Vec3< Type > &point_q)
Definition line.h:62
clan::Line3x::Line3x
Line3x(const Line3x< Type > &copy)
Definition line.h:61
clan::Line3x::q
Vec3< Type > q
Definition line.h:58
clan::Vec2
2D vector
Definition vec4.h:43
clan::Vec3
3D vector
Definition vec4.h:46
clan::FillMode::line
@ line
clan::FillMode::point
@ point
clan
Definition clanapp.h:36