Refactored signatures of many C++ methods for more efficient and safer style. Includes a bugfix for Point::nearest_point() which was returning a pointer to freed memory. #1961

This commit is contained in:
Alessandro Ranellucci 2014-04-24 16:40:10 +02:00
parent 6201aacf88
commit ca4d4211c9
30 changed files with 203 additions and 161 deletions

View file

@ -21,8 +21,10 @@
void translate(double x, double y);
double area();
bool is_valid();
bool contains_line(Line* line);
bool contains_point(Point* point);
bool contains_line(Line* line)
%code{% RETVAL = THIS->contains_line(*line); %};
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
ExPolygons simplify(double tolerance);
Polygons simplify_p(double tolerance);
Polylines medial_axis(double max_width, double min_width)

View file

@ -17,7 +17,8 @@
%code{% THIS->rotate(angle, *center); %};
int count()
%code{% RETVAL = THIS->expolygons.size(); %};
bool contains_point(Point* point);
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
void simplify(double tolerance);
%{

View file

@ -11,13 +11,21 @@
void clear()
%code{% THIS->entities.clear(); %};
ExtrusionEntityCollection* chained_path(bool no_reverse)
%code{% const char* CLASS = "Slic3r::ExtrusionPath::Collection"; RETVAL = THIS->chained_path(no_reverse); %};
%code{%
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
RETVAL = new ExtrusionEntityCollection();
THIS->chained_path(RETVAL, no_reverse);
%};
ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse)
%code{% const char* CLASS = "Slic3r::ExtrusionPath::Collection"; RETVAL = THIS->chained_path_from(start_near, no_reverse); %};
%code{%
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
RETVAL = new ExtrusionEntityCollection();
THIS->chained_path_from(*start_near, RETVAL, no_reverse);
%};
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
int count()
%code{% RETVAL = THIS->entities.size(); %};
std::vector<size_t> orig_indices()
@ -84,9 +92,9 @@ ExtrusionEntityCollection::chained_path_indices(bool no_reverse)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE:
RETVAL = new ExtrusionEntityCollection();
std::vector<size_t> indices;
RETVAL = THIS->chained_path(no_reverse, &indices);
RETVAL->orig_indices = indices;
THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices);
OUTPUT:
RETVAL

View file

@ -19,9 +19,9 @@
%code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_first_point(); %};
bool make_counter_clockwise();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
bool is_perimeter();
bool is_fill();
bool is_bridge();

View file

@ -18,9 +18,9 @@
Lines lines()
%code{% RETVAL = THIS->polyline.lines(); %};
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
void clip_end(double distance);
void simplify(double tolerance);
double length();

View file

@ -56,7 +56,7 @@ Line::coincides_with(line_sv)
CODE:
Line line;
line.from_SV_check(line_sv);
RETVAL = THIS->coincides_with(&line);
RETVAL = THIS->coincides_with(line);
OUTPUT:
RETVAL

View file

@ -22,9 +22,11 @@
%code{% RETVAL = THIS->y; %};
int nearest_point_index(Points points);
Point* nearest_point(Points points)
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %};
double distance_to(Point* point);
%name{distance_to_line} double distance_to(Line* line);
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(); THIS->nearest_point(points, RETVAL); %};
double distance_to(Point* point)
%code{% RETVAL = THIS->distance_to(*point); %};
double distance_to_line(Line* line)
%code{% RETVAL = THIS->distance_to(*line); %};
double ccw(Point* p1, Point* p2)
%code{% RETVAL = THIS->ccw(*p1, *p2); %};
@ -45,7 +47,7 @@ Point::coincides_with(point_sv)
CODE:
Point point;
point.from_SV_check(point_sv);
RETVAL = THIS->coincides_with(&point);
RETVAL = THIS->coincides_with(point);
OUTPUT:
RETVAL

View file

@ -18,7 +18,7 @@
void reverse();
Lines lines();
Polyline* split_at(Point* point)
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at(point); %};
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at(*point); %};
Polyline* split_at_index(int index)
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %};
Polyline* split_at_first_point()
@ -32,8 +32,9 @@
bool make_clockwise();
bool is_valid();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
bool contains_point(Point* point);
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
Polygons simplify(double tolerance);
%{

View file

@ -21,9 +21,9 @@
void reverse();
Lines lines();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
Points equally_spaced_points(double distance);
double length();
bool is_valid();

View file

@ -12,13 +12,21 @@
void clear()
%code{% THIS->polylines.clear(); %};
PolylineCollection* chained_path(bool no_reverse)
%code{% const char* CLASS = "Slic3r::Polyline::Collection"; RETVAL = THIS->chained_path(no_reverse); %};
%code{%
const char* CLASS = "Slic3r::Polyline::Collection";
RETVAL = new PolylineCollection();
THIS->chained_path(RETVAL, no_reverse);
%};
PolylineCollection* chained_path_from(Point* start_near, bool no_reverse)
%code{% const char* CLASS = "Slic3r::Polyline::Collection"; RETVAL = THIS->chained_path_from(start_near, no_reverse); %};
%code{%
const char* CLASS = "Slic3r::Polyline::Collection";
RETVAL = new PolylineCollection();
THIS->chained_path_from(*start_near, RETVAL, no_reverse);
%};
int count()
%code{% RETVAL = THIS->polylines.size(); %};
Point* leftmost_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->leftmost_point(); %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->leftmost_point()); %};
%{
PolylineCollection*