forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygon.cpp
More file actions
213 lines (194 loc) · 4.16 KB
/
Copy pathPolygon.cpp
File metadata and controls
213 lines (194 loc) · 4.16 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Polygon.h"
#include "../fmath.h"
namespace OpenXcom
{
/**
* Initializes the polygon with arrays to store each point's coordinates.
* @param points Number of points.
*/
Polygon::Polygon(int points) : _points(points), _texture(0)
{
_lat = new double[_points];
_lon = new double[_points];
_x = new Sint16[_points];
_y = new Sint16[_points];
for (int i = 0; i < _points; ++i)
{
_lat[i] = 0.0;
_lon[i] = 0.0;
_x[i] = 0;
_y[i] = 0;
}
}
/**
* Performs a deep copy of an existing polygon.
* @param other Polygon to copy from.
*/
Polygon::Polygon(const Polygon& other)
{
_points = other._points;
_lat = new double[_points];
_lon = new double[_points];
_x = new Sint16[_points];
_y = new Sint16[_points];
for (int i = 0; i < _points; ++i)
{
_lat[i] = other._lat[i];
_lon[i] = other._lon[i];
_x[i] = other._x[i];
_y[i] = other._y[i];
}
_texture = other._texture;
}
/**
* Deletes the arrays from memory.
*/
Polygon::~Polygon()
{
delete[] _lat;
delete[] _lon;
delete[] _x;
delete[] _y;
}
/**
* Loads the polygon from a YAML file.
* @param node YAML node.
*/
void Polygon::load(const YAML::Node &node)
{
delete[] _lat;
delete[] _lon;
delete[] _x;
delete[] _y;
std::vector<double> coords = node.as< std::vector<double> >();
_points = (coords.size() - 1) / 2;
_lat = new double[_points];
_lon = new double[_points];
_x = new Sint16[_points];
_y = new Sint16[_points];
_texture = coords[0];
for (size_t i = 1; i < coords.size(); i += 2)
{
size_t j = (i - 1) / 2;
_lon[j] = Deg2Rad(coords[i]);
_lat[j] = Deg2Rad(coords[i+1]);
_x[j] = 0;
_y[j] = 0;
}
}
/**
* Returns the latitude of a given point.
* @param i Point number (0-max).
* @return Point's latitude.
*/
double Polygon::getLatitude(int i) const
{
return _lat[i];
}
/**
* Changes the latitude of a given point.
* @param i Point number (0-max).
* @param lat Point's latitude.
*/
void Polygon::setLatitude(int i, double lat)
{
_lat[i] = lat;
}
/**
* Returns the longitude of a given point.
* @param i Point number (0-max).
* @return Point's longitude.
*/
double Polygon::getLongitude(int i) const
{
return _lon[i];
}
/**
* Changes the latitude of a given point.
* @param i Point number (0-max).
* @param lon Point's longitude.
*/
void Polygon::setLongitude(int i, double lon)
{
_lon[i] = lon;
}
/**
* Returns the X coordinate of a given point.
* @param i Point number (0-max).
* @return Point's X coordinate.
*/
Sint16 Polygon::getX(int i) const
{
return _x[i];
}
/**
* Changes the X coordinate of a given point.
* @param i Point number (0-max).
* @param x Point's X coordinate.
*/
void Polygon::setX(int i, Sint16 x)
{
_x[i] = x;
}
/**
* Returns the Y coordinate of a given point.
* @param i Point number (0-max).
* @return Point's Y coordinate.
*/
Sint16 Polygon::getY(int i) const
{
return _y[i];
}
/**
* Changes the Y coordinate of a given point.
* @param i Point number (0-max).
* @param y Point's Y coordinate.
*/
void Polygon::setY(int i, Sint16 y)
{
_y[i] = y;
}
/**
* Returns the texture used to draw the polygon
* (textures are stored in a set).
* @return Texture sprite number.
*/
int Polygon::getTexture() const
{
return _texture;
}
/**
* Changes the texture used to draw the polygon.
* @param tex Texture sprite number.
*/
void Polygon::setTexture(int tex)
{
_texture = tex;
}
/**
* Returns the number of points (vertexes) that make up the polygon.
* @return Number of points.
*/
int Polygon::getPoints() const
{
return _points;
}
}