Refactoring: renamed all contains_*() methods to contains() in C++
This commit is contained in:
parent
5deadc8f12
commit
634bc09e2c
@ -145,8 +145,8 @@ BridgeDetector::detect_angle()
|
|||||||
// remove any line not having both endpoints within anchors
|
// remove any line not having both endpoints within anchors
|
||||||
for (size_t i = 0; i < clipped_lines.size(); ++i) {
|
for (size_t i = 0; i < clipped_lines.size(); ++i) {
|
||||||
Line &line = clipped_lines[i];
|
Line &line = clipped_lines[i];
|
||||||
if (!Slic3r::Geometry::contains_point(my_anchors, line.a)
|
if (!Slic3r::Geometry::contains(my_anchors, line.a)
|
||||||
|| !Slic3r::Geometry::contains_point(my_anchors, line.b)) {
|
|| !Slic3r::Geometry::contains(my_anchors, line.b)) {
|
||||||
clipped_lines.erase(clipped_lines.begin() + i);
|
clipped_lines.erase(clipped_lines.begin() + i);
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
@ -82,13 +82,13 @@ ExPolygon::is_valid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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
|
bool
|
||||||
ExPolygon::contains_polyline(const Polyline &polyline) const
|
ExPolygon::contains(const Polyline &polyline) const
|
||||||
{
|
{
|
||||||
Polylines pl_out;
|
Polylines pl_out;
|
||||||
diff((Polylines)polyline, *this, &pl_out);
|
diff((Polylines)polyline, *this, &pl_out);
|
||||||
@ -96,11 +96,11 @@ ExPolygon::contains_polyline(const Polyline &polyline) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ class ExPolygon
|
|||||||
void rotate(double angle, const Point ¢er);
|
void rotate(double angle, const Point ¢er);
|
||||||
double area() const;
|
double area() const;
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
bool contains_line(const Line &line) const;
|
bool contains(const Line &line) const;
|
||||||
bool contains_polyline(const Polyline &polyline) const;
|
bool contains(const Polyline &polyline) const;
|
||||||
bool contains_point(const Point &point) const;
|
bool contains(const Point &point) const;
|
||||||
Polygons simplify_p(double tolerance) const;
|
Polygons simplify_p(double tolerance) const;
|
||||||
ExPolygons simplify(double tolerance) const;
|
ExPolygons simplify(double tolerance) const;
|
||||||
void simplify(double tolerance, ExPolygons &expolygons) const;
|
void simplify(double tolerance, ExPolygons &expolygons) const;
|
||||||
|
@ -55,32 +55,18 @@ ExPolygonCollection::rotate(double angle, const Point ¢er)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
bool
|
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) {
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
||||||
if (it->contains_point(point)) return true;
|
if (it->contains(item)) 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;
|
|
||||||
}
|
}
|
||||||
return false;
|
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
|
void
|
||||||
ExPolygonCollection::simplify(double tolerance)
|
ExPolygonCollection::simplify(double tolerance)
|
||||||
|
@ -24,9 +24,7 @@ class ExPolygonCollection
|
|||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
void translate(double x, double y);
|
void translate(double x, double y);
|
||||||
void rotate(double angle, const Point ¢er);
|
void rotate(double angle, const Point ¢er);
|
||||||
bool contains_point(const Point &point) const;
|
template <class T> bool contains(const T &item) const;
|
||||||
bool contains_line(const Line &line) const;
|
|
||||||
bool contains_polyline(const Polyline &polyline) const;
|
|
||||||
void simplify(double tolerance);
|
void simplify(double tolerance);
|
||||||
void convex_hull(Polygon* hull) const;
|
void convex_hull(Polygon* hull) const;
|
||||||
};
|
};
|
||||||
|
@ -114,14 +114,14 @@ directions_parallel(double angle1, double angle2, double max_diff)
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool
|
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) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
template bool contains_point(const ExPolygons &vector, const Point &point);
|
template bool contains(const ExPolygons &vector, const Point &point);
|
||||||
|
|
||||||
double
|
double
|
||||||
rad2deg(double angle)
|
rad2deg(double angle)
|
||||||
|
@ -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);
|
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);
|
template<class T> void chained_path_items(Points &points, T &items, T &retval);
|
||||||
bool directions_parallel(double angle1, double angle2, double max_diff = 0);
|
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(double angle);
|
||||||
double rad2deg_dir(double angle);
|
double rad2deg_dir(double angle);
|
||||||
double deg2rad(double angle);
|
double deg2rad(double angle);
|
||||||
|
@ -86,10 +86,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
|
|||||||
// Are both points in the same island?
|
// Are both points in the same island?
|
||||||
int island_idx = -1;
|
int island_idx = -1;
|
||||||
for (ExPolygons::const_iterator island = this->islands.begin(); island != this->islands.end(); ++island) {
|
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?
|
// since both points are in the same island, is a direct move possible?
|
||||||
// if so, we avoid generating the visibility environment
|
// 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(from);
|
||||||
polyline->points.push_back(to);
|
polyline->points.push_back(to);
|
||||||
return;
|
return;
|
||||||
@ -104,20 +104,20 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
|
|||||||
Point inner_to = to;
|
Point inner_to = to;
|
||||||
bool from_is_inside, to_is_inside;
|
bool from_is_inside, to_is_inside;
|
||||||
if (island_idx == -1) {
|
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.
|
// Find the closest inner point to start from.
|
||||||
from.nearest_point(this->outer, &inner_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.
|
// Find the closest inner point to start from.
|
||||||
to.nearest_point(this->outer, &inner_to);
|
to.nearest_point(this->outer, &inner_to);
|
||||||
}
|
}
|
||||||
} else {
|
} 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.
|
// Find the closest inner point to start from.
|
||||||
from.nearest_point(this->inner[island_idx], &inner_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.
|
// Find the closest inner point to start from.
|
||||||
to.nearest_point(this->inner[island_idx], &inner_to);
|
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();
|
const VD::vertex_type* v1 = edge->vertex1();
|
||||||
Point p0 = Point(v0->x(), v0->y());
|
Point p0 = Point(v0->x(), v0->y());
|
||||||
Point p1 = Point(v1->x(), v1->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
|
// and should it fail on any boundary points it's not a big problem
|
||||||
if (island_idx == -1) {
|
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 {
|
} 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);
|
t_vd_vertices::const_iterator i_v0 = vd_vertices.find(v0);
|
||||||
|
@ -141,7 +141,7 @@ Polygon::is_valid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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
|
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
@ -32,7 +32,7 @@ class Polygon : public MultiPoint {
|
|||||||
bool make_counter_clockwise();
|
bool make_counter_clockwise();
|
||||||
bool make_clockwise();
|
bool make_clockwise();
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
bool contains_point(const Point &point) const;
|
bool contains(const Point &point) const;
|
||||||
Polygons simplify(double tolerance) const;
|
Polygons simplify(double tolerance) const;
|
||||||
void simplify(double tolerance, Polygons &polygons) const;
|
void simplify(double tolerance, Polygons &polygons) const;
|
||||||
void triangulate_convex(Polygons* polygons) const;
|
void triangulate_convex(Polygons* polygons) const;
|
||||||
|
@ -788,7 +788,7 @@ TriangleMeshSlicer::make_expolygons_simple(std::vector<IntersectionLine> &lines,
|
|||||||
int slice_idx = -1;
|
int slice_idx = -1;
|
||||||
double current_contour_area = -1;
|
double current_contour_area = -1;
|
||||||
for (ExPolygons::iterator slice = slices->begin(); slice != slices->end(); ++slice) {
|
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();
|
double area = slice->contour.area();
|
||||||
if (area < current_contour_area || current_contour_area == -1) {
|
if (area < current_contour_area || current_contour_area == -1) {
|
||||||
slice_idx = slice - slices->begin();
|
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.
|
supply everything to offset() instead of performing several union/diff calls.
|
||||||
|
|
||||||
we sort by area assuming that the outermost loops have larger area;
|
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
|
loops correctly in some edge cases when original model had overlapping facets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@
|
|||||||
double area();
|
double area();
|
||||||
bool is_valid();
|
bool is_valid();
|
||||||
bool contains_line(Line* line)
|
bool contains_line(Line* line)
|
||||||
%code{% RETVAL = THIS->contains_line(*line); %};
|
%code{% RETVAL = THIS->contains(*line); %};
|
||||||
bool contains_polyline(Polyline* polyline)
|
bool contains_polyline(Polyline* polyline)
|
||||||
%code{% RETVAL = THIS->contains_polyline(*polyline); %};
|
%code{% RETVAL = THIS->contains(*polyline); %};
|
||||||
bool contains_point(Point* point)
|
bool contains_point(Point* point)
|
||||||
%code{% RETVAL = THIS->contains_point(*point); %};
|
%code{% RETVAL = THIS->contains(*point); %};
|
||||||
ExPolygons simplify(double tolerance);
|
ExPolygons simplify(double tolerance);
|
||||||
Polygons simplify_p(double tolerance);
|
Polygons simplify_p(double tolerance);
|
||||||
Polylines medial_axis(double max_width, double min_width)
|
Polylines medial_axis(double max_width, double min_width)
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
int count()
|
int count()
|
||||||
%code{% RETVAL = THIS->expolygons.size(); %};
|
%code{% RETVAL = THIS->expolygons.size(); %};
|
||||||
bool contains_point(Point* point)
|
bool contains_point(Point* point)
|
||||||
%code{% RETVAL = THIS->contains_point(*point); %};
|
%code{% RETVAL = THIS->contains(*point); %};
|
||||||
bool contains_line(Line* line)
|
bool contains_line(Line* line)
|
||||||
%code{% RETVAL = THIS->contains_line(*line); %};
|
%code{% RETVAL = THIS->contains(*line); %};
|
||||||
bool contains_polyline(Polyline* polyline)
|
bool contains_polyline(Polyline* polyline)
|
||||||
%code{% RETVAL = THIS->contains_polyline(*polyline); %};
|
%code{% RETVAL = THIS->contains(*polyline); %};
|
||||||
void simplify(double tolerance);
|
void simplify(double tolerance);
|
||||||
Polygons polygons()
|
Polygons polygons()
|
||||||
%code{% RETVAL = *THIS; %};
|
%code{% RETVAL = *THIS; %};
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
bool is_valid();
|
bool is_valid();
|
||||||
Clone<Point> first_point();
|
Clone<Point> first_point();
|
||||||
bool contains_point(Point* point)
|
bool contains_point(Point* point)
|
||||||
%code{% RETVAL = THIS->contains_point(*point); %};
|
%code{% RETVAL = THIS->contains(*point); %};
|
||||||
Polygons simplify(double tolerance);
|
Polygons simplify(double tolerance);
|
||||||
Polygons triangulate_convex()
|
Polygons triangulate_convex()
|
||||||
%code{% THIS->triangulate_convex(&RETVAL); %};
|
%code{% THIS->triangulate_convex(&RETVAL); %};
|
||||||
|
Loading…
Reference in New Issue
Block a user