-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathCollisionList.cpp
More file actions
143 lines (131 loc) · 4.63 KB
/
CollisionList.cpp
File metadata and controls
143 lines (131 loc) · 4.63 KB
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
/**************************************************************************************
* File name: CollisionList.cpp
*
* Project: MapWindow Open Source (MapWinGis ActiveX control)
* Description: Implementation of CCollisionList
*
**************************************************************************************
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at http://www.mozilla.org/mpl/
* See the License for the specific language governing rights and limitations
* under the License.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**************************************************************************************
* Contributor(s):
* (Open source contributors should list themselves and their modifications here). */
// Sergei Leschinski (lsu) 25 june 2010 - created the file.
#include "stdafx.h"
#include "CollisionList.h"
// ****************************************************************
// Clear()
// ****************************************************************
void CCollisionList::Clear()
{
for (unsigned int i = 0; i < _extentsHorizontal.size(); i++)
{
delete _extentsHorizontal[i];
}
for (unsigned int i = 0; i < _extentsRotated.size(); i++)
{
delete _extentsRotated[i];
}
_extentsHorizontal.clear();
_extentsRotated.clear();
}
// ****************************************************************
// HaveCollision
// ****************************************************************
// Checking overlapping with existing labels; input label isn't rotated
bool CCollisionList::HaveCollision(CRect& rect)
{
for(int i=0; i < (int)_extentsHorizontal.size(); i++)
{
CRect* r = _extentsHorizontal[i];
if ((rect.right < r->left) || (rect.bottom < r->top) || (r->right < rect.left) || (r->bottom < rect.top))
continue;
else
return true;
}
if (_extentsRotated.size() > 0)
{
for(int i=0; i < (int)_extentsRotated.size(); i++)
{
CRotatedRectangle* r = _extentsRotated[i];
if (r->BoundsIntersect(rect))
{
if (r->Intersects(rect)) return true;
}
}
}
return false;
}
// ****************************************************************
// HaveCollision
// ****************************************************************
// Checking overlapping with existing labels; input label is rotated
bool CCollisionList::HaveCollision(CRotatedRectangle& rect)
{
for(int i=0; i < (int)_extentsHorizontal.size(); i++)
{
CRect* r = _extentsHorizontal[i];
if (rect.BoundsIntersect(*r))
{
if (rect.Intersects(*r)) return true;
}
}
for(int i=0; i < (int)_extentsRotated.size(); i++)
{
CRotatedRectangle* r = _extentsRotated[i];
if (rect.BoundsIntersect(*r))
{
if (rect.Intersects(*r)) return true;
}
}
return false;
}
// ****************************************************************
// AddRectangle
// ****************************************************************
void CCollisionList::AddRectangle(CRect* rect, int bufferX, int bufferY)
{
CRect* rectNew = NULL;
if (bufferX != 0 || bufferY != 0)
{
rectNew = new CRect(rect->left - bufferX/2, rect->top - bufferY/2, rect->right + bufferX/2, rect->bottom + bufferY/2);
}
else
{
rectNew = new CRect(rect->left, rect->top, rect->right, rect->bottom);
}
_extentsHorizontal.push_back(rectNew);
}
// ****************************************************************
// AddRotatedRectangle
// ****************************************************************
void CCollisionList::AddRotatedRectangle(CRotatedRectangle* rect, int bufferX, int bufferY)
{
if (bufferX != 0 || bufferY != 0)
{
// TODO: the calculations here aren't precise
CRect* rectNew = NULL;
CRect* r = rect->BoundingBox();
r->InflateRect(bufferX, bufferY);
rectNew = new CRect(r->left, r->top, r->right, r->bottom);
_extentsHorizontal.push_back(rectNew);
}
else
{
CRotatedRectangle* rectNew = NULL;
rectNew = new CRotatedRectangle();
memcpy(rectNew->points, rect->points, sizeof(POINT) * 4);
_extentsRotated.push_back(rectNew);
}
}