ClanLib
2.3.7
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
Sources
API
Core
Math
line_segment.h
Go to the documentation of this file.
1
/*
2
** ClanLib SDK
3
** Copyright (c) 1997-2011 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
31
32
#pragma once
33
34
#include "../api_core.h"
35
36
template
<
typename
Type>
37
class
CL_LineSegment2x
;
38
39
template
<
typename
Type>
40
class
CL_LineSegment3x
;
41
42
template
<
typename
Type>
43
class
CL_Vec2
;
44
45
template
<
typename
Type>
46
class
CL_Vec3
;
47
48
template
<
typename
Type>
49
class
CL_Rectx
;
50
51
class
CL_Angle
;
52
58
template
<
typename
Type>
59
class
CL_LineSegment3x
60
{
61
public
:
63
CL_Vec3<Type>
p
;
64
65
// \brief End point on the line
66
CL_Vec3<Type>
q
;
67
68
CL_LineSegment3x
() { }
69
CL_LineSegment3x
(
const
CL_LineSegment3x<Type>
©) {
p
= copy.
p
;
q
= copy.
q
;}
70
CL_LineSegment3x
(
const
CL_Vec3<Type>
&point_p,
const
CL_Vec3<Type>
&point_q) {
p
= point_p;
q
= point_q; }
71
74
public
:
78
CL_Vec3<Type>
get_midpoint
()
const
{
return
CL_Vec3<Type>
( (
q
.x +
p
.x)/((Type)2), (
q
.y +
p
.y)/((Type)2), (
q
.z +
p
.z)/((Type)2) ); };
79
85
Type
point_distance
(
const
CL_Vec3<Type>
&point,
CL_Vec3<Type>
&dest_intercept)
const
;
86
90
public
:
92
CL_LineSegment3x<Type>
&
operator =
(
const
CL_LineSegment3x<Type>
& copy) {
p
= copy.
p
;
q
= copy.
q
;
return
*
this
; }
93
95
bool
operator ==
(
const
CL_LineSegment3x<Type>
& line)
const
{
return
((
p
== line.
p
) && (
q
== line.
q
));}
96
98
bool
operator !=
(
const
CL_LineSegment3x<Type>
& line)
const
{
return
((
p
!= line.
p
) || (
q
!= line.
q
));}
100
};
101
107
template
<
typename
Type>
108
class
CL_LineSegment2x
109
{
110
public
:
112
CL_Vec2<Type>
p
;
113
114
// \brief End point on the line
115
CL_Vec2<Type>
q
;
116
117
CL_LineSegment2x
() { }
118
CL_LineSegment2x
(
const
CL_LineSegment2x<Type>
©) {
p
= copy.
p
;
q
= copy.
q
;}
119
CL_LineSegment2x
(
const
CL_Vec2<Type>
&point_p,
const
CL_Vec2<Type>
&point_q) {
p
= point_p;
q
= point_q; }
120
123
public
:
127
CL_Vec2<Type>
get_midpoint
()
const
{
return
CL_Vec2<Type>
( (
q
.x +
p
.x)/((Type)2), (
q
.y +
p
.y)/((Type)2) ); };
128
132
Type
point_distance
(
const
CL_Vec2<Type>
&point);
133
138
bool
collinear
(
const
CL_LineSegment2x<Type>
&second)
const
;
139
145
bool
intersects
(
const
CL_LineSegment2x<Type>
&second,
bool
collinear_intersect )
const
;
146
152
CL_Vec2<Type>
get_intersection
(
const
CL_LineSegment2x<Type>
&second,
bool
&intersect)
const
;
153
158
Type
point_right_of_line
(
const
CL_Vec2<Type>
&point )
const
{
return
(
q
.x -
p
.x) * (point.
y
-
p
.y) - (point.
x
-
p
.x) * (
q
.y -
p
.y);}
159
165
CL_Vec2<Type>
normal
()
const
;
166
170
171
public
:
179
CL_LineSegment2x<Type>
&
clip
(
const
CL_Rectx<Type>
&rect,
bool
&clipped);
180
184
public
:
186
CL_LineSegment2x<Type>
&
operator =
(
const
CL_LineSegment2x<Type>
& copy) {
p
= copy.
p
;
q
= copy.
q
;
return
*
this
; }
187
189
bool
operator ==
(
const
CL_LineSegment2x<Type>
& line)
const
{
return
((
p
== line.
p
) && (
q
== line.
q
));}
190
192
bool
operator !=
(
const
CL_LineSegment2x<Type>
& line)
const
{
return
((
p
!= line.
p
) || (
q
!= line.
q
));}
194
};
195
200
class
CL_LineSegment2
:
public
CL_LineSegment2x
<int>
201
{
202
public
:
203
CL_LineSegment2
() :
CL_LineSegment2x
<int>() {}
204
CL_LineSegment2
(
const
CL_LineSegment2x<int>
©) :
CL_LineSegment2x
<int>(copy) {}
205
CL_LineSegment2
(
const
CL_Vec2<int>
&point_p,
const
CL_Vec2<int>
&point_q) :
CL_LineSegment2x
<int>(point_p, point_q) {}
206
};
207
212
class
CL_LineSegment2f
:
public
CL_LineSegment2x
<float>
213
{
214
public
:
215
CL_LineSegment2f
() :
CL_LineSegment2x
<float>() {}
216
CL_LineSegment2f
(
const
CL_LineSegment2x<float>
©) :
CL_LineSegment2x
<float>(copy) {}
217
CL_LineSegment2f
(
const
CL_Vec2<float>
&point_p,
const
CL_Vec2<float>
&point_q) :
CL_LineSegment2x
<float>(point_p, point_q) {}
218
};
219
224
class
CL_LineSegment2d
:
public
CL_LineSegment2x
<double>
225
{
226
public
:
227
CL_LineSegment2d
() :
CL_LineSegment2x
<double>() {}
228
CL_LineSegment2d
(
const
CL_LineSegment2x<double>
©) :
CL_LineSegment2x
<double>(copy) {}
229
CL_LineSegment2d
(
const
CL_Vec2<double>
&point_p,
const
CL_Vec2<double>
&point_q) :
CL_LineSegment2x
<double>(point_p, point_q) {}
230
};
231
236
class
CL_LineSegment3
:
public
CL_LineSegment3x
<int>
237
{
238
public
:
239
CL_LineSegment3
() :
CL_LineSegment3x
<int>() {}
240
CL_LineSegment3
(
const
CL_LineSegment3x<int>
©) :
CL_LineSegment3x
<int>(copy) {}
241
CL_LineSegment3
(
const
CL_Vec3<int>
&point_p,
const
CL_Vec3<int>
&point_q) :
CL_LineSegment3x
<int>(point_p, point_q) {}
242
};
243
248
class
CL_LineSegment3f
:
public
CL_LineSegment3x
<float>
249
{
250
public
:
251
CL_LineSegment3f
() :
CL_LineSegment3x
<float>() {}
252
CL_LineSegment3f
(
const
CL_LineSegment3x<float>
©) :
CL_LineSegment3x
<float>(copy) {}
253
CL_LineSegment3f
(
const
CL_Vec3<float>
&point_p,
const
CL_Vec3<float>
&point_q) :
CL_LineSegment3x
<float>(point_p, point_q) {}
254
};
255
260
class
CL_LineSegment3d
:
public
CL_LineSegment3x
<double>
261
{
262
public
:
263
CL_LineSegment3d
() :
CL_LineSegment3x
<double>() {}
264
CL_LineSegment3d
(
const
CL_LineSegment3x<double>
©) :
CL_LineSegment3x
<double>(copy) {}
265
CL_LineSegment3d
(
const
CL_Vec3<double>
&point_p,
const
CL_Vec3<double>
&point_q) :
CL_LineSegment3x
<double>(point_p, point_q) {}
266
};
267
269
Generated on Fri Jun 14 2013 13:05:45 for ClanLib by
1.8.4