23#define __WIZARD_ENGINE_INTERNAL__
27void wze::polygon::update_x() {
30 for (i = 0; i != shape().size(); ++i) {
33 transformation_matrix());
37void wze::polygon::update_y() {
40 for (i = 0; i != shape().size(); ++i) {
41 _points.at(i).second =
43 transformation_matrix());
47float wze::polygon::circumradius()
const {
52 std::for_each(shape().begin(), shape().end(),
53 [&](std::pair<float, float>
const& vertex) ->
void {
55 if (circumradius < temporary) {
56 circumradius = temporary;
63std::pair<float, float>
64wze::polygon::project(std::pair<float, float>
const& vector)
const {
65 std::pair<float, float> projection;
67 projection.first = std::numeric_limits<float>::max();
68 projection.second = -std::numeric_limits<float>::max();
69 std::for_each(points().begin(), points().end(),
70 [&](std::pair<float, float>
const& point) ->
void {
73 scalar = point.first * vector.first +
74 point.second * vector.second;
75 projection.first = std::min(projection.first, scalar);
76 projection.second = std::max(projection.second, scalar);
82std::vector<std::pair<float, float>>
const& wze::polygon::shape()
const {
86float wze::polygon::shape_radius()
const {
90std::vector<std::pair<float, float>>
const& wze::polygon::points()
const {
94float wze::polygon::points_radius()
const {
95 return _points_radius;
98float wze::polygon::x()
const {
102void wze::polygon::set_x(
float x) {
107float wze::polygon::y()
const {
111void wze::polygon::set_y(
float y) {
116float wze::polygon::angle()
const {
120void wze::polygon::set_angle(
float angle) {
122 _transformation_matrix =
128float wze::polygon::scale()
const {
132void wze::polygon::set_scale(
float scale) {
134 _points_radius = shape_radius() * this->scale();
135 _transformation_matrix =
141std::array<float, 4>
const& wze::polygon::transformation_matrix()
const {
142 return _transformation_matrix;
145float wze::polygon::x_offset()
const {
149void wze::polygon::set_x_offset(
float x_offset) {
150 _x_offset = x_offset;
153float wze::polygon::y_offset()
const {
157void wze::polygon::set_y_offset(
float y_offset) {
158 _y_offset = y_offset;
161float wze::polygon::angle_offset()
const {
162 return _angle_offset;
165void wze::polygon::set_angle_offset(
float angle_offset) {
166 _angle_offset = angle_offset;
169bool wze::polygon::attach_x()
const {
173void wze::polygon::set_attach_x(
bool attach_x) {
174 _attach_x = attach_x;
177bool wze::polygon::attach_y()
const {
181void wze::polygon::set_attach_y(
bool attach_y) {
182 _attach_y = attach_y;
185bool wze::polygon::attach_angle()
const {
186 return _attach_angle;
189void wze::polygon::set_attach_angle(
bool attach_angle) {
190 _attach_angle = attach_angle;
193bool wze::polygon::x_angle_lock()
const {
194 return _x_angle_lock;
197void wze::polygon::set_x_angle_lock(
bool x_angle_lock) {
198 _x_angle_lock = x_angle_lock;
201bool wze::polygon::y_angle_lock()
const {
202 return _y_angle_lock;
205void wze::polygon::set_y_angle_lock(
bool y_angle_lock) {
206 _y_angle_lock = y_angle_lock;
209wze::polygon::polygon(std::vector<std::pair<float, float>>
const& shape,
210 float x,
float y,
float angle,
float scale,
211 float x_offset,
float y_offset,
float angle_offset,
212 bool attach_x,
bool attach_y,
bool attach_angle,
213 bool x_angle_lock,
bool y_angle_lock) {
215 _shape_radius = circumradius();
216 _points.resize(this->shape().size());
221 set_x_offset(x_offset);
222 set_y_offset(y_offset);
223 set_angle_offset(angle_offset);
224 set_attach_x(attach_x);
225 set_attach_y(attach_y);
226 set_attach_angle(attach_angle);
227 set_x_angle_lock(x_angle_lock);
228 set_y_angle_lock(y_angle_lock);
231bool wze::polygon::inside(
float x,
float y)
const {
232 std::vector<std::pair<float, float>>::const_iterator point1;
233 std::vector<std::pair<float, float>>::const_iterator point2;
237 if (points_radius() <
math::length(x - this->x(), y - this->y())) {
242 for (point1 = points().begin(), point2 = points().begin() + 1;
243 point1 != points().end(); ++point1, ++point2) {
244 if (point2 == points().end()) {
245 point2 = points().begin();
248 temporary = (point2->first - point1->first) * (y - point1->second) -
249 (x - point1->first) * (point2->second - point1->second);
251 if ((0 < determinant && temporary < 0) ||
252 (determinant < 0 && 0 < temporary)) {
256 determinant = temporary;
static constexpr float transform_y(float x, float y, std::array< float, 4 > const &transformation_matrix)
Transforms the y component of a vector.
static std::array< float, 4 > transformation_matrix(float angle, float scale)
Creates a transformation matrix.
static float length(float x, float y)
Returns the length of a vector.
static constexpr float transform_x(float x, float y, std::array< float, 4 > const &transformation_matrix)
Transforms the x component of a vector.
Convex polygon component.