SCV
4.2.1
Simple Components for Visual
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
Mathematic.h
Go to the documentation of this file.
1
7
#ifndef __SCV_MATHEMATICS_H__
8
#define __SCV_MATHEMATICS_H__
9
10
#ifndef DOXYGEN_SKIP_THIS
11
#include "
Point.h
"
12
#endif // DOXYGEN_SKIP_THIS
13
14
namespace
scv {
15
20
namespace
math {
21
41
inline
bool
isInside
(
scv::Point
p11,
scv::Point
p12,
scv::Point
p21,
scv::Point
p22) {
42
if
(p12.
x
<= 0 || p12.
y
<= 0 || p22.
x
<= 0 || p22.
y
<= 0)
return
true
;
43
44
int
tx1 = p11.
x
;
45
int
ty1 = p11.
y
;
46
int
rx1 = p21.
x
;
47
int
ry1 = p21.
y
;
48
int
tx2 = tx1 + p12.
x
;
49
int
ty2 = ty1 + p12.
y
;
50
int
rx2 = rx1 + p22.
x
;
51
int
ry2 = ry1 + p22.
y
;
52
53
if
(tx1 < rx1) tx1 = rx1;
54
if
(ty1 < ry1) ty1 = ry1;
55
if
(tx2 > rx2) tx2 = rx2;
56
if
(ty2 > ry2) ty2 = ry2;
57
if
(tx2 < tx1) tx1 = tx2;
58
if
(ty2 < ty1) ty1 = ty2;
59
60
if
(std::abs(tx1 - tx2) * std::abs(ty1 - ty2))
return
true
;
61
return
false
;
62
}
63
65
inline
double
nearestValue
(
double
p,
double
p1,
double
p2) {
66
if
(std::abs(p - p1) < std::abs(p2 - p))
return
p1;
67
return
p2;
68
}
69
82
83
inline
void
intersectSquare
(
scv::Point
&p11,
scv::Point
&p12,
scv::Point
&p21,
scv::Point
&p22) {
84
if
(p11.
x
< p21.
x
) p11.
x
= p21.
x
;
85
if
(p11.
y
< p21.
y
) p11.
y
= p21.
y
;
86
if
(p12.
x
> p22.
x
) p12.
x
= p22.
x
;
87
if
(p12.
y
> p22.
y
) p12.
y
= p22.
y
;
88
if
(p12.
x
< p11.
x
) p11.
x
= p12.
x
;
89
if
(p12.
y
< p11.
y
) p11.
y
= p12.
y
;
90
}
91
92
}
// namespace math
93
}
// namespace scv
94
95
#endif // __SCV_MATHEMATICS_H__
include
SCV
Mathematic.h
Generated on Fri Dec 14 2012 09:44:49 for SCV by
1.8.2