Implemented utility functions to operate over lines, polylines, polygons,

surfaces.
This commit is contained in:
bubnikv 2016-11-07 22:49:11 +01:00
parent aac968162b
commit 5a81731577
13 changed files with 495 additions and 66 deletions

View file

@ -36,10 +36,10 @@ MultiPoint::rotate(double angle)
double s = sin(angle);
double c = cos(angle);
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
double cur_x = (double)it->x;
double cur_y = (double)it->y;
it->x = (coord_t)round(c * cur_x - s * cur_y);
it->y = (coord_t)round(c * cur_y + s * cur_x);
double cur_x = (double)it->x;
double cur_y = (double)it->y;
it->x = (coord_t)round(c * cur_x - s * cur_y);
it->y = (coord_t)round(c * cur_y + s * cur_x);
}
}
@ -214,7 +214,38 @@ MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
BoundingBox get_extents(const MultiPoint &mp)
{
return mp.bounding_box();
return BoundingBox(mp.points);
}
BoundingBox get_extents_rotated(const Points &points, double angle)
{
BoundingBox bbox;
if (! points.empty()) {
double s = sin(angle);
double c = cos(angle);
Points::const_iterator it = points.begin();
double cur_x = (double)it->x;
double cur_y = (double)it->y;
bbox.min.x = bbox.max.x = (coord_t)round(c * cur_x - s * cur_y);
bbox.min.y = bbox.max.y = (coord_t)round(c * cur_y + s * cur_x);
for (++it; it != points.end(); ++it) {
double cur_x = (double)it->x;
double cur_y = (double)it->y;
coord_t x = (coord_t)round(c * cur_x - s * cur_y);
coord_t y = (coord_t)round(c * cur_y + s * cur_x);
bbox.min.x = std::min(x, bbox.min.x);
bbox.min.y = std::min(y, bbox.min.y);
bbox.max.x = std::max(x, bbox.max.x);
bbox.max.y = std::max(y, bbox.max.y);
}
bbox.defined = true;
}
return bbox;
}
BoundingBox get_extents_rotated(const MultiPoint &mp, double angle)
{
return get_extents_rotated(mp.points, angle);
}
}