My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "Core.h"

NAMESPACE_UPP

//template <>
//void Rect_<double>::Union(const Rect_<double>& r) {
void Rect_double_Union(Rect_<double>& self, const Rect_<double>& r) {
if(IsNull(r)) return;
if(IsNull(self)) {
self.Set(r);
return;
}
if(r.left < self.left) self.left = r.left;
if(r.top < self.top) self.top = r.top;
if(r.right > self.right) self.right = r.right;
if(r.bottom > self.bottom) self.bottom = r.bottom;
}

//bool Rect_double_Contains(const Rect_<double>& self, const Point_<double>& p) {
// return p.x >= self.left && p.x <= self.right && p.y >= self.top && p.y <= self.bottom;
//}

//template <>
//bool Rect_<double>::Intersects(const Rect_<double>& r) const {
bool Rect_double_Intersects(const Rect_<double>& self, const Rect_<double>& r) {
if(IsNull(self) || IsNull(r)) return false;
return r.right >= self.left && r.bottom >= self.top && r.left <= self.right && r.top <= self.bottom;
}

//template <>
//Point_<double> Rect_<double>::Bind(Point_<double> pt) const
Point_<double> Rect_double_Bind(const Rect_<double>& self, Point_<double> pt) {
return Point_<double>(pt.x < self.left ? self.left : pt.x > self.right ? self.right : pt.x,
pt.y < self.top ? self.top : pt.y > self.bottom ? self.bottom : pt.y);
}

Size iscale(Size a, int b, int c)
{
return Size(iscale(a.cx, b, c), iscale(a.cy, b, c));
}

Size iscalefloor(Size a, int b, int c)
{
return Size(iscalefloor(a.cx, b, c), iscalefloor(a.cy, b, c));
}

Size iscaleceil(Size a, int b, int c)
{
return Size(iscaleceil(a.cx, b, c), iscaleceil(a.cy, b, c));
}

Size idivfloor(Size a, int b)
{
return Size(idivfloor(a.cx, b), idivfloor(a.cy, b));
}

Size idivceil(Size a, int b)
{
return Size(idivceil(a.cx, b), idivceil(a.cy, b));
}

Size iscale(Size a, Size b, Size c)
{
return Size(iscale(a.cx, b.cx, c.cx), iscale(a.cy, b.cy, c.cy));
}

Size iscalefloor(Size a, Size b, Size c)
{
return Size(iscalefloor(a.cx, b.cx, c.cx), iscalefloor(a.cy, b.cy, c.cy));
}

Size iscaleceil(Size a, Size b, Size c)
{
return Size(iscaleceil(a.cx, b.cx, c.cx), iscaleceil(a.cy, b.cy, c.cy));
}

Size idivfloor(Size a, Size b)
{
return Size(idivfloor(a.cx, b.cx), idivfloor(a.cy, b.cy));
}

Size idivceil(Size a, Size b)
{
return Size(idivceil(a.cx, b.cx), idivceil(a.cy, b.cy));
}

Size GetRatioSize(Size sz, int cx, int cy)
{
return cx == 0 ? cy == 0 ? sz : sz.cy ? Size(sz.cx * cy / sz.cy, cy) : Size(0, 0)
: cy == 0 ? sz.cx ? Size(cx, sz.cy * cx / sz.cx) : Size(0, 0)
: Size(cx, cy);
}

Size GetFitSize(Size sz, int cx, int cy)
{
if(cx <= 0 || cy <= 0 || sz.cx <= 0 || sz.cy <= 0)
return Size(0, 0);
if(cx * sz.cy >= cy * sz.cx) // too high
return iscale(sz, cy, sz.cy);
else
return iscale(sz, cx, sz.cx);
}

double SquareDist(const Pointf& p1, const Pointf& p2)
{
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}

Pointf Mid(const Pointf& a, const Pointf& b)
{
return 0.5 * (a + b);
}

Pointf Orthogonal(const Pointf& p)
{
return Pointf(-p.y, p.x);
}

double Squared(const Pointf& p)
{
return p.x * p.x + p.y * p.y;
}

double Length(const Pointf& p)
{
return sqrt(Squared(p));
}

double Distance(const Pointf& p1, const Pointf& p2)
{
return Length(p1 - p2);
}

double SquaredDistance(const Pointf& p1, const Pointf& p2)
{
return Squared(p1 - p2);
}

Pointf Polar(double a)
{
return Pointf(cos(a), sin(a));
}

Pointf Polar(const Pointf& p, double r, double a)
{
return p + r * Polar(a);
}

double Bearing(const Pointf& p)
{
return atan2(p.y, p.x);
}

END_UPP_NAMESPACE

Change log

r4651 by cxl on Mar 3, 2012   Diff
Core: Value support for Xmlize, Jasonize
Go to: 
Project members, sign in to write a code review

Older revisions

r4495 by cxl on Jan 30, 2012   Diff
Core: new Value reintegrated for
conditional compilation (SVO_VALUE
flag)
r1086 by cxl on Apr 21, 2009   Diff
GTypes - missing Bearing fixed (not
missing anymore)
r1085 by cxl on Apr 21, 2009   Diff
Some conflicting Geom/Painter routines
moved to Core
All revisions of this file

File info

Size: 3535 bytes, 154 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting