%module{Slic3r::XS};

%{
#include <xsinit.h>
#include "libslic3r/ExPolygon.hpp"
%}

%name{Slic3r::ExPolygon} class ExPolygon {
    ~ExPolygon();
    Clone<ExPolygon> clone()
        %code{% RETVAL = THIS; %};
    SV* arrayref()
        %code{% RETVAL = to_AV(THIS); %};
    SV* pp()
        %code{% RETVAL = to_SV_pureperl(THIS); %};
    Ref<Polygon> contour()
        %code{% RETVAL = &(THIS->contour); %};
    Polygons* holes()
        %code{% RETVAL = &(THIS->holes); %};
    void scale(double factor);
    void translate(double x, double y);
    double area();
    bool is_valid();
    bool contains_line(Line* line)
        %code{% RETVAL = THIS->contains(*line); %};
    bool contains_polyline(Polyline* polyline)
        %code{% RETVAL = THIS->contains(*polyline); %};
    bool contains_point(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)
        %code{% THIS->medial_axis(max_width, min_width, &RETVAL); %};
    Polygons get_trapezoids2(double angle)
        %code{% THIS->get_trapezoids2(&RETVAL, angle); %};
    Polygons triangulate()
        %code{% THIS->triangulate(&RETVAL); %};
%{

ExPolygon*
ExPolygon::new(...)
    CODE:
        RETVAL = new ExPolygon ();
        // ST(0) is class name, ST(1) is contour and others are holes
        from_SV_check(ST(1), &RETVAL->contour);
        RETVAL->holes.resize(items-2);
        for (unsigned int i = 2; i < items; i++) {
            from_SV_check(ST(i), &RETVAL->holes[i-2]);
        }
    OUTPUT:
        RETVAL

void
ExPolygon::rotate(angle, center_sv)
    double  angle;
    SV*     center_sv;
    CODE:
        Point center;
        from_SV_check(center_sv, &center);
        THIS->rotate(angle, center);

%}
};
