Refactoring: renamed all contains_*() methods to contains() in C++

This commit is contained in:
Alessandro Ranellucci 2014-11-23 20:14:13 +01:00
parent 5deadc8f12
commit 634bc09e2c
14 changed files with 42 additions and 58 deletions

View File

@ -145,8 +145,8 @@ BridgeDetector::detect_angle()
// remove any line not having both endpoints within anchors
for (size_t i = 0; i < clipped_lines.size(); ++i) {
Line &line = clipped_lines[i];
if (!Slic3r::Geometry::contains_point(my_anchors, line.a)
|| !Slic3r::Geometry::contains_point(my_anchors, line.b)) {
if (!Slic3r::Geometry::contains(my_anchors, line.a)
|| !Slic3r::Geometry::contains(my_anchors, line.b)) {
clipped_lines.erase(clipped_lines.begin() + i);
--i;
}

View File

@ -82,13 +82,13 @@ ExPolygon::is_valid() const
}
bool
ExPolygon::contains_line(const Line &line) const
ExPolygon::contains(const Line &line) const
{
return this->contains_polyline(line);
return this->contains((Polyline)line);
}
bool
ExPolygon::contains_polyline(const Polyline &polyline) const
ExPolygon::contains(const Polyline &polyline) const
{
Polylines pl_out;
diff((Polylines)polyline, *this, &pl_out);
@ -96,11 +96,11 @@ ExPolygon::contains_polyline(const Polyline &polyline) const
}
bool
ExPolygon::contains_point(const Point &point) const
ExPolygon::contains(const Point &point) const
{
if (!this->contour.contains_point(point)) return false;
if (!this->contour.contains(point)) return false;
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
if (it->contains_point(point)) return false;
if (it->contains(point)) return false;
}
return true;
}

View File

@ -22,9 +22,9 @@ class ExPolygon
void rotate(double angle, const Point &center);
double area() const;
bool is_valid() const;
bool contains_line(const Line &line) const;
bool contains_polyline(const Polyline &polyline) const;
bool contains_point(const Point &point) const;
bool contains(const Line &line) const;
bool contains(const Polyline &polyline) const;
bool contains(const Point &point) const;
Polygons simplify_p(double tolerance) const;
ExPolygons simplify(double tolerance) const;
void simplify(double tolerance, ExPolygons &expolygons) const;

View File

@ -55,32 +55,18 @@ ExPolygonCollection::rotate(double angle, const Point &center)
}
}
template <class T>
bool
ExPolygonCollection::contains_point(const Point &point) const
ExPolygonCollection::contains(const T &item) const
{
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
if (it->contains_point(point)) return true;
}
return false;
}
bool
ExPolygonCollection::contains_line(const Line &line) const
{
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
if (it->contains_line(line)) return true;
}
return false;
}
bool
ExPolygonCollection::contains_polyline(const Polyline &polyline) const
{
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
if (it->contains_polyline(polyline)) return true;
if (it->contains(item)) return true;
}
return false;
}
template bool ExPolygonCollection::contains<Point>(const Point &item) const;
template bool ExPolygonCollection::contains<Line>(const Line &item) const;
template bool ExPolygonCollection::contains<Polyline>(const Polyline &item) const;
void
ExPolygonCollection::simplify(double tolerance)

View File

@ -24,9 +24,7 @@ class ExPolygonCollection
void scale(double factor);
void translate(double x, double y);
void rotate(double angle, const Point &center);
bool contains_point(const Point &point) const;
bool contains_line(const Line &line) const;
bool contains_polyline(const Polyline &polyline) const;
template <class T> bool contains(const T &item) const;
void simplify(double tolerance);
void convex_hull(Polygon* hull) const;
};

View File

@ -114,14 +114,14 @@ directions_parallel(double angle1, double angle2, double max_diff)
template<class T>
bool
contains_point(const std::vector<T> &vector, const Point &point)
contains(const std::vector<T> &vector, const Point &point)
{
for (typename std::vector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it) {
if (it->contains_point(point)) return true;
if (it->contains(point)) return true;
}
return false;
}
template bool contains_point(const ExPolygons &vector, const Point &point);
template bool contains(const ExPolygons &vector, const Point &point);
double
rad2deg(double angle)

View File

@ -17,7 +17,7 @@ void chained_path(const Points &points, std::vector<Points::size_type> &retval,
void chained_path(const Points &points, std::vector<Points::size_type> &retval);
template<class T> void chained_path_items(Points &points, T &items, T &retval);
bool directions_parallel(double angle1, double angle2, double max_diff = 0);
template<class T> bool contains_point(const std::vector<T> &vector, const Point &point);
template<class T> bool contains(const std::vector<T> &vector, const Point &point);
double rad2deg(double angle);
double rad2deg_dir(double angle);
double deg2rad(double angle);

View File

@ -86,10 +86,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
// Are both points in the same island?
int island_idx = -1;
for (ExPolygons::const_iterator island = this->islands.begin(); island != this->islands.end(); ++island) {
if (island->contains_point(from) && island->contains_point(to)) {
if (island->contains(from) && island->contains(to)) {
// since both points are in the same island, is a direct move possible?
// if so, we avoid generating the visibility environment
if (island->contains_line(Line(from, to))) {
if (island->contains(Line(from, to))) {
polyline->points.push_back(from);
polyline->points.push_back(to);
return;
@ -104,20 +104,20 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
Point inner_to = to;
bool from_is_inside, to_is_inside;
if (island_idx == -1) {
if (!(from_is_inside = this->outer.contains_point(from))) {
if (!(from_is_inside = this->outer.contains(from))) {
// Find the closest inner point to start from.
from.nearest_point(this->outer, &inner_from);
}
if (!(to_is_inside = this->outer.contains_point(to))) {
if (!(to_is_inside = this->outer.contains(to))) {
// Find the closest inner point to start from.
to.nearest_point(this->outer, &inner_to);
}
} else {
if (!(from_is_inside = this->inner[island_idx].contains_point(from))) {
if (!(from_is_inside = this->inner[island_idx].contains(from))) {
// Find the closest inner point to start from.
from.nearest_point(this->inner[island_idx], &inner_from);
}
if (!(to_is_inside = this->inner[island_idx].contains_point(to))) {
if (!(to_is_inside = this->inner[island_idx].contains(to))) {
// Find the closest inner point to start from.
to.nearest_point(this->inner[island_idx], &inner_to);
}
@ -175,12 +175,12 @@ MotionPlanner::init_graph(int island_idx)
const VD::vertex_type* v1 = edge->vertex1();
Point p0 = Point(v0->x(), v0->y());
Point p1 = Point(v1->x(), v1->y());
// contains_point() should probably be faster than contains_line(),
// contains() should probably be faster than contains(),
// and should it fail on any boundary points it's not a big problem
if (island_idx == -1) {
if (!this->outer.contains_point(p0) || !this->outer.contains_point(p1)) continue;
if (!this->outer.contains(p0) || !this->outer.contains(p1)) continue;
} else {
if (!this->inner[island_idx].contains_point(p0) || !this->inner[island_idx].contains_point(p1)) continue;
if (!this->inner[island_idx].contains(p0) || !this->inner[island_idx].contains(p1)) continue;
}
t_vd_vertices::const_iterator i_v0 = vd_vertices.find(v0);

View File

@ -141,7 +141,7 @@ Polygon::is_valid() const
}
bool
Polygon::contains_point(const Point &point) const
Polygon::contains(const Point &point) const
{
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
bool result = false;

View File

@ -32,7 +32,7 @@ class Polygon : public MultiPoint {
bool make_counter_clockwise();
bool make_clockwise();
bool is_valid() const;
bool contains_point(const Point &point) const;
bool contains(const Point &point) const;
Polygons simplify(double tolerance) const;
void simplify(double tolerance, Polygons &polygons) const;
void triangulate_convex(Polygons* polygons) const;

View File

@ -788,7 +788,7 @@ TriangleMeshSlicer::make_expolygons_simple(std::vector<IntersectionLine> &lines,
int slice_idx = -1;
double current_contour_area = -1;
for (ExPolygons::iterator slice = slices->begin(); slice != slices->end(); ++slice) {
if (slice->contour.contains_point(loop->points.front())) {
if (slice->contour.contains(loop->points.front())) {
double area = slice->contour.area();
if (area < current_contour_area || current_contour_area == -1) {
slice_idx = slice - slices->begin();
@ -816,7 +816,7 @@ TriangleMeshSlicer::make_expolygons(const Polygons &loops, ExPolygons* slices)
supply everything to offset() instead of performing several union/diff calls.
we sort by area assuming that the outermost loops have larger area;
the previous sorting method, based on $b->contains_point($a->[0]), failed to nest
the previous sorting method, based on $b->contains($a->[0]), failed to nest
loops correctly in some edge cases when original model had overlapping facets
*/

View File

@ -22,11 +22,11 @@
double area();
bool is_valid();
bool contains_line(Line* line)
%code{% RETVAL = THIS->contains_line(*line); %};
%code{% RETVAL = THIS->contains(*line); %};
bool contains_polyline(Polyline* polyline)
%code{% RETVAL = THIS->contains_polyline(*polyline); %};
%code{% RETVAL = THIS->contains(*polyline); %};
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
%code{% RETVAL = THIS->contains(*point); %};
ExPolygons simplify(double tolerance);
Polygons simplify_p(double tolerance);
Polylines medial_axis(double max_width, double min_width)

View File

@ -18,11 +18,11 @@
int count()
%code{% RETVAL = THIS->expolygons.size(); %};
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
%code{% RETVAL = THIS->contains(*point); %};
bool contains_line(Line* line)
%code{% RETVAL = THIS->contains_line(*line); %};
%code{% RETVAL = THIS->contains(*line); %};
bool contains_polyline(Polyline* polyline)
%code{% RETVAL = THIS->contains_polyline(*polyline); %};
%code{% RETVAL = THIS->contains(*polyline); %};
void simplify(double tolerance);
Polygons polygons()
%code{% RETVAL = *THIS; %};

View File

@ -36,7 +36,7 @@
bool is_valid();
Clone<Point> first_point();
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
%code{% RETVAL = THIS->contains(*point); %};
Polygons simplify(double tolerance);
Polygons triangulate_convex()
%code{% THIS->triangulate_convex(&RETVAL); %};