The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


%module{Math::Clipper};
%package{Math::Clipper};

%{
#include <myinit.h>

PROTOTYPES: DISABLE

IV
_constant()
  ALIAS:
    CT_INTERSECTION = ctIntersection
    CT_UNION = ctUnion
    CT_DIFFERENCE = ctDifference
    CT_XOR = ctXor
    PT_SUBJECT = ptSubject
    PT_CLIP = ptClip
    PFT_EVENODD = pftEvenOdd
    PFT_NONZERO = pftNonZero
    JT_MITER = jtMiter
    JT_ROUND = jtRound
    JT_SQUARE = jtSquare
  CODE:
    RETVAL = ix;
  OUTPUT: RETVAL

%}

%name{Math::Clipper}
class Clipper {
  Clipper();
  ~Clipper();

%{
ClipperLib::Polygons*
execute(THIS, clipType, subjFillType = pftEvenOdd, clipFillType = pftEvenOdd)
    Clipper* THIS
    ClipType clipType
    PolyFillType subjFillType
    PolyFillType clipFillType
  CODE:
    RETVAL = new ClipperLib::Polygons();
    THIS->Execute(clipType, *RETVAL, subjFillType, clipFillType);
  OUTPUT:
    RETVAL

ClipperLib::ExPolygons*
ex_execute(THIS, clipType, subjFillType = pftEvenOdd, clipFillType = pftEvenOdd)
    Clipper* THIS
    ClipType clipType
    PolyFillType subjFillType
    PolyFillType clipFillType
  CODE:
    RETVAL = new ClipperLib::ExPolygons();
    THIS->Execute(clipType, *RETVAL, subjFillType, clipFillType);
  OUTPUT:
    RETVAL
%}

// No longer in v4.X
//  %name{get_force_orientation}
//    bool ForceOrientation();
//  %name{set_force_orientation}
//    void ForceOrientation(bool value);

// We don't expose this since we save the PolyType stuff entirely that way!
//  %name{add_polygon}
//    void AddPolygon(const Polygon &pg, PolyType polyType);

%{

void
add_subject_polygon(self, poly)
    Clipper* self
    ClipperLib::Polygon* poly
  PPCODE:
    self->AddPolygon(*poly, ptSubject);
    delete poly;

void
add_clip_polygon(self, poly)
    Clipper* self
    ClipperLib::Polygon* poly
  PPCODE:
    self->AddPolygon(*poly, ptClip);
    delete poly;

void
add_subject_polygons(self, polys)
    Clipper* self
    ClipperLib::Polygons* polys
  PPCODE:
    self->AddPolygons(*polys, ptSubject);
    delete polys;

void
add_clip_polygons(self, polys)
    Clipper* self
    ClipperLib::Polygons* polys
  PPCODE:
    self->AddPolygons(*polys, ptClip);
    delete polys;

double
orientation(polygon)
    ClipperLib::Polygon* polygon
  CODE:
    RETVAL = ClipperLib::Orientation(*polygon);
  OUTPUT: RETVAL

double
area(polygon)
    ClipperLib::Polygon* polygon
  CODE:
    RETVAL = ClipperLib::Area(*polygon);
  OUTPUT: RETVAL

ClipperLib::Polygons*
_offset(polygons, delta, jointype, MiterLimit)
    ClipperLib::Polygons* polygons
    const float delta
    JoinType jointype
    const double MiterLimit
  CODE:
    RETVAL = new ClipperLib::Polygons();
    ClipperLib::OffsetPolygons(*polygons, *RETVAL, delta, jointype, MiterLimit);
  OUTPUT:
    RETVAL

ClipperLib::Polygons*
simplify_polygon(polygon, fillType)
    ClipperLib::Polygon* polygon
    PolyFillType fillType
  CODE:
    RETVAL = new ClipperLib::Polygons();
    ClipperLib::SimplifyPolygon(*polygon, *RETVAL, fillType);
  OUTPUT:
    RETVAL

ClipperLib::Polygons*
simplify_polygons(polygons, fillType)
    ClipperLib::Polygons* polygons
    PolyFillType fillType
  CODE:
    RETVAL = new ClipperLib::Polygons();
    ClipperLib::SimplifyPolygons(*polygons, *RETVAL, fillType);
  OUTPUT:
    RETVAL
%}

  %name{clear}
    void Clear();

};