%module{Slic3r::XS};

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

%name{Slic3r::Geometry::BoundingBox} class BoundingBox {
    BoundingBox();
    ~BoundingBox();
    Clone<BoundingBox> clone()
        %code{% RETVAL = THIS; %};
    void merge(BoundingBox* bb) %code{% THIS->merge(*bb); %};
    void merge_point(Point* point) %code{% THIS->merge(*point); %};
    void scale(double factor);
    void translate(double x, double y);
    void offset(double delta);
    bool contains_point(Point* point) %code{% RETVAL = THIS->contains(*point); %};
    bool overlap(BoundingBox* bbox) %code{% RETVAL = THIS->overlap(*bbox); %};
    Clone<Polygon> polygon();
    Clone<Point> size();
    Clone<Point> center();
    bool empty() %code{% RETVAL = empty(*THIS); %};
    double radius();
    Clone<Point> min_point() %code{% RETVAL = THIS->min; %};
    Clone<Point> max_point() %code{% RETVAL = THIS->max; %};
    int x_min() %code{% RETVAL = THIS->min.x; %};
    int x_max() %code{% RETVAL = THIS->max.x; %};
    int y_min() %code{% RETVAL = THIS->min.y; %};
    int y_max() %code{% RETVAL = THIS->max.y; %};
    void set_x_min(double val) %code{% THIS->min.x = val; %};
    void set_x_max(double val) %code{% THIS->max.x = val; %};
    void set_y_min(double val) %code{% THIS->min.y = val; %};
    void set_y_max(double val) %code{% THIS->max.y = val; %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld;%ld,%ld", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %};
    bool defined() %code{% RETVAL = THIS->defined; %};

%{

BoundingBox*
new_from_points(CLASS, points)
    char*   CLASS
    Points  points
    CODE:
        RETVAL = new BoundingBox(points);
    OUTPUT:
        RETVAL

%}
};

%name{Slic3r::Geometry::BoundingBoxf} class BoundingBoxf {
    BoundingBoxf();
    ~BoundingBoxf();
    Clone<BoundingBoxf> clone()
        %code{% RETVAL = THIS; %};
    void merge(BoundingBoxf* bb) %code{% THIS->merge(*bb); %};
    void merge_point(Pointf* point) %code{% THIS->merge(*point); %};
    void scale(double factor);
    void translate(double x, double y);
    Clone<Pointf> size();
    Clone<Pointf> center();
    double radius();
    bool empty() %code{% RETVAL = empty(*THIS); %};
    Clone<Pointf> min_point() %code{% RETVAL = THIS->min; %};
    Clone<Pointf> max_point() %code{% RETVAL = THIS->max; %};
    double x_min() %code{% RETVAL = THIS->min.x; %};
    double x_max() %code{% RETVAL = THIS->max.x; %};
    double y_min() %code{% RETVAL = THIS->min.y; %};
    double y_max() %code{% RETVAL = THIS->max.y; %};
    void set_x_min(double val) %code{% THIS->min.x = val; %};
    void set_x_max(double val) %code{% THIS->max.x = val; %};
    void set_y_min(double val) %code{% THIS->min.y = val; %};
    void set_y_max(double val) %code{% THIS->max.y = val; %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf;%lf,%lf", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %};
    bool defined() %code{% RETVAL = THIS->defined; %};
    
%{

BoundingBoxf*
new_from_points(CLASS, points)
    char*   CLASS
    Pointfs points
    CODE:
        RETVAL = new BoundingBoxf(points);
    OUTPUT:
        RETVAL

%}
};

%name{Slic3r::Geometry::BoundingBoxf3} class BoundingBoxf3 {
    BoundingBoxf3();
    ~BoundingBoxf3();
    Clone<BoundingBoxf3> clone()
        %code{% RETVAL = THIS; %};
    void merge(BoundingBoxf3* bb) %code{% THIS->merge(*bb); %};
    void merge_point(Pointf3* point) %code{% THIS->merge(*point); %};
    void scale(double factor);
    void translate(double x, double y, double z);
    void offset(double delta);
    bool contains_point(Pointf3* point) %code{% RETVAL = THIS->contains(*point); %};
    Clone<Pointf3> size();
    Clone<Pointf3> center();
    double radius();
    bool empty() %code{% RETVAL = empty(*THIS); %};
    Clone<Pointf3> min_point() %code{% RETVAL = THIS->min; %};
    Clone<Pointf3> max_point() %code{% RETVAL = THIS->max; %};
    double x_min() %code{% RETVAL = THIS->min.x; %};
    double x_max() %code{% RETVAL = THIS->max.x; %};
    double y_min() %code{% RETVAL = THIS->min.y; %};
    double y_max() %code{% RETVAL = THIS->max.y; %};
    double z_min() %code{% RETVAL = THIS->min.z; %};
    double z_max() %code{% RETVAL = THIS->max.z; %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf;%lf,%lf,%lf", THIS->min.x, THIS->min.y, THIS->min.z, THIS->max.x, THIS->max.y, THIS->max.z); RETVAL = buf; %};
    bool defined() %code{% RETVAL = THIS->defined; %};
};
