mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 16:51:21 -06:00
XS interface completed, including new Line class
This commit is contained in:
parent
9af2a1c007
commit
ab6b3d41a7
33 changed files with 435 additions and 257 deletions
|
|
@ -8,94 +8,26 @@ extern "C" {
|
|||
#include "ppport.h"
|
||||
}
|
||||
|
||||
#include "Point.hpp"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Line.hpp"
|
||||
#include "MultiPoint.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Polyline
|
||||
{
|
||||
class Polyline : public MultiPoint {
|
||||
public:
|
||||
Points points;
|
||||
void from_SV(SV* poly_sv);
|
||||
void from_SV_check(SV* poly_sv);
|
||||
SV* to_SV(bool pureperl = false, bool pureperl_children = false);
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void rotate(double angle, Point* center);
|
||||
void reverse();
|
||||
protected:
|
||||
virtual char* perl_class() {
|
||||
return (char*)"Slic3r::Polyline";
|
||||
}
|
||||
Lines lines();
|
||||
};
|
||||
|
||||
typedef std::vector<Polyline> Polylines;
|
||||
|
||||
void
|
||||
Polyline::scale(double factor)
|
||||
Lines
|
||||
Polyline::lines()
|
||||
{
|
||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
(*it).scale(factor);
|
||||
Lines lines;
|
||||
for (int i = 0; i < this->points.size()-1; i++) {
|
||||
lines.push_back(Line(this->points[i], this->points[i+1]));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::translate(double x, double y)
|
||||
{
|
||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
(*it).translate(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::rotate(double angle, Point* center)
|
||||
{
|
||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
(*it).rotate(angle, center);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::reverse()
|
||||
{
|
||||
std::reverse(this->points.begin(), this->points.end());
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::from_SV(SV* poly_sv)
|
||||
{
|
||||
AV* poly_av = (AV*)SvRV(poly_sv);
|
||||
const unsigned int num_points = av_len(poly_av)+1;
|
||||
this->points.resize(num_points);
|
||||
|
||||
for (unsigned int i = 0; i < num_points; i++) {
|
||||
SV** point_sv = av_fetch(poly_av, i, 0);
|
||||
perl2point_check(*point_sv, this->points[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::from_SV_check(SV* poly_sv)
|
||||
{
|
||||
if (sv_isobject(poly_sv) && (SvTYPE(SvRV(poly_sv)) == SVt_PVMG)) {
|
||||
*this = *(Polyline*)SvIV((SV*)SvRV( poly_sv ));
|
||||
} else {
|
||||
this->from_SV(poly_sv);
|
||||
}
|
||||
}
|
||||
|
||||
SV*
|
||||
Polyline::to_SV(bool pureperl, bool pureperl_children) {
|
||||
const unsigned int num_points = this->points.size();
|
||||
AV* av = newAV();
|
||||
av_extend(av, num_points-1);
|
||||
for (unsigned int i = 0; i < num_points; i++) {
|
||||
av_store(av, i, this->points[i].to_SV(pureperl_children));
|
||||
}
|
||||
return sv_bless(newRV_noinc((SV*)av), gv_stashpv(this->perl_class(), GV_ADD));
|
||||
return lines;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue