PrusaSlicer-NonPlainar/xs/xsp/Polygon.xsp
Petr Ledvina 115aa6885f Implement type checking for XS objects
Type handling is mainly done using templates.
Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used.
Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type).

Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return.

Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments).
It is overloaded to be able to return type, type* and type&.

Typechecking in ExtrusionEntityCollection updated to check all passed types.
2014-04-27 19:38:56 +02:00

66 lines
1.7 KiB
Plaintext

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "Polygon.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Polygon} class Polygon {
~Polygon();
Clone<Polygon> clone()
%code{% RETVAL = THIS; %};
SV* arrayref()
%code{% RETVAL = THIS->to_AV(); %};
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
void scale(double factor);
void translate(double x, double y);
void reverse();
Lines lines();
Polyline* split_at(Point* point)
%code{% RETVAL = THIS->split_at(*point); %};
Polyline* split_at_index(int index)
%code{% RETVAL = THIS->split_at_index(index); %};
Polyline* split_at_first_point()
%code{% RETVAL = THIS->split_at_first_point(); %};
Points equally_spaced_points(double distance);
double length();
double area();
bool is_counter_clockwise();
bool is_clockwise();
bool make_counter_clockwise();
bool make_clockwise();
bool is_valid();
Clone<Point> first_point();
bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %};
Polygons simplify(double tolerance);
Polygons triangulate_convex()
%code{% THIS->triangulate_convex(&RETVAL); %};
%{
Polygon*
Polygon::new(...)
CODE:
RETVAL = new Polygon ();
// ST(0) is class name, ST(1) is first point
RETVAL->points.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
RETVAL->points[i-1].from_SV_check( ST(i) );
}
OUTPUT:
RETVAL
void
Polygon::rotate(angle, center_sv)
double angle;
SV* center_sv;
CODE:
Point center;
center.from_SV_check(center_sv);
THIS->rotate(angle, center);
%}
};