1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "Polygon.h"
20 
21 namespace OpenXcom
22 {
23 
24 /**
25  * Initializes the polygon with arrays to store each point's coordinates.
26  * @param points Number of points.
27  */
Polygon(int points)28 Polygon::Polygon(int points) : _points(points), _texture(0)
29 {
30 	_lat = new double[_points];
31 	_lon = new double[_points];
32 	_x = new Sint16[_points];
33 	_y = new Sint16[_points];
34 	for (int i = 0; i < _points; ++i)
35 	{
36 		_lat[i] = 0.0;
37 		_lon[i] = 0.0;
38 		_x[i] = 0;
39 		_y[i] = 0;
40 	}
41 }
42 
43 /**
44  * Performs a deep copy of an existing polygon.
45  * @param other Polygon to copy from.
46  */
Polygon(const Polygon & other)47 Polygon::Polygon(const Polygon& other)
48 {
49 	_points = other._points;
50 	_lat = new double[_points];
51 	_lon = new double[_points];
52 	_x = new Sint16[_points];
53 	_y = new Sint16[_points];
54 	for (int i = 0; i < _points; ++i)
55 	{
56 		_lat[i] = other._lat[i];
57 		_lon[i] = other._lon[i];
58 		_x[i] = other._x[i];
59 		_y[i] = other._y[i];
60 	}
61 	_texture = other._texture;
62 }
63 
64 /**
65  * Deletes the arrays from memory.
66  */
~Polygon()67 Polygon::~Polygon()
68 {
69 	delete[] _lat;
70 	delete[] _lon;
71 	delete[] _x;
72 	delete[] _y;
73 }
74 
75 /**
76  * Returns the latitude of a given point.
77  * @param i Point number (0-max).
78  * @return Point's latitude.
79  */
getLatitude(int i) const80 double Polygon::getLatitude(int i) const
81 {
82 	return _lat[i];
83 }
84 
85 /**
86  * Changes the latitude of a given point.
87  * @param i Point number (0-max).
88  * @param lat Point's latitude.
89  */
setLatitude(int i,double lat)90 void Polygon::setLatitude(int i, double lat)
91 {
92 	_lat[i] = lat;
93 }
94 
95 /**
96  * Returns the longitude of a given point.
97  * @param i Point number (0-max).
98  * @return Point's longitude.
99  */
getLongitude(int i) const100 double Polygon::getLongitude(int i) const
101 {
102 	return _lon[i];
103 }
104 
105 /**
106  * Changes the latitude of a given point.
107  * @param i Point number (0-max).
108  * @param lon Point's longitude.
109  */
setLongitude(int i,double lon)110 void Polygon::setLongitude(int i, double lon)
111 {
112 	_lon[i] = lon;
113 }
114 
115 /**
116  * Returns the X coordinate of a given point.
117  * @param i Point number (0-max).
118  * @return Point's X coordinate.
119  */
getX(int i) const120 Sint16 Polygon::getX(int i) const
121 {
122 	return _x[i];
123 }
124 
125 /**
126  * Changes the X coordinate of a given point.
127  * @param i Point number (0-max).
128  * @param x Point's X coordinate.
129  */
setX(int i,Sint16 x)130 void Polygon::setX(int i, Sint16 x)
131 {
132 	_x[i] = x;
133 }
134 
135 /**
136  * Returns the Y coordinate of a given point.
137  * @param i Point number (0-max).
138  * @return Point's Y coordinate.
139  */
getY(int i) const140 Sint16 Polygon::getY(int i) const
141 {
142 	return _y[i];
143 }
144 
145 /**
146  * Changes the Y coordinate of a given point.
147  * @param i Point number (0-max).
148  * @param y Point's Y coordinate.
149  */
setY(int i,Sint16 y)150 void Polygon::setY(int i, Sint16 y)
151 {
152 	_y[i] = y;
153 }
154 
155 /**
156  * Returns the texture used to draw the polygon
157  * (textures are stored in a set).
158  * @return Texture sprite number.
159  */
getTexture() const160 int Polygon::getTexture() const
161 {
162 	return _texture;
163 }
164 
165 /**
166  * Changes the texture used to draw the polygon.
167  * @param tex Texture sprite number.
168  */
setTexture(int tex)169 void Polygon::setTexture(int tex)
170 {
171 	_texture = tex;
172 }
173 
174 /**
175  * Returns the number of points (vertexes) that make up the polygon.
176  * @return Number of points.
177  */
getPoints() const178 int Polygon::getPoints() const
179 {
180 	return _points;
181 }
182 
183 }
184