PrusaSlicer-NonPlainar/xs/xsp/Point.xsp

133 lines
4.3 KiB
Plaintext
Raw Normal View History

2013-07-06 13:26:32 +00:00
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "libslic3r/Point.hpp"
#include "libslic3r/Line.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/Polyline.hpp"
2013-07-06 13:26:32 +00:00
%}
2013-07-15 18:31:43 +00:00
%name{Slic3r::Point} class Point {
Point(int _x = 0, int _y = 0);
2013-07-07 14:51:02 +00:00
~Point();
Clone<Point> clone()
%code{% RETVAL=THIS; %};
void scale(double factor)
%code{% *THIS *= factor; %};
void translate(double x, double y)
%code{% *THIS += Point(x, y); %};
2013-07-15 14:04:49 +00:00
SV* arrayref()
%code{% RETVAL = to_SV_pureperl(THIS); %};
2013-07-16 15:13:01 +00:00
SV* pp()
%code{% RETVAL = to_SV_pureperl(THIS); %};
int x()
%code{% RETVAL = (*THIS)(0); %};
int y()
%code{% RETVAL = (*THIS)(1); %};
void set_x(int val)
%code{% (*THIS)(0) = val; %};
void set_y(int val)
%code{% (*THIS)(1) = val; %};
int nearest_point_index(Points points);
Clone<Point> nearest_point(Points points)
%code{% Point p; THIS->nearest_point(points, &p); RETVAL = p; %};
double distance_to(Point* point)
%code{% RETVAL = (*point - *THIS).cast<double>().norm(); %};
double distance_to_line(Line* line)
%code{% RETVAL = line->distance_to(*THIS); %};
double perp_distance_to_line(Line* line)
%code{% RETVAL = line->perp_distance_to(*THIS); %};
double ccw(Point* p1, Point* p2)
%code{% RETVAL = cross2((*p1 - *THIS).cast<double>(), (*p2 - *p1).cast<double>()); %};
Point* projection_onto_line(Line* line)
2014-05-21 18:08:21 +00:00
%code{% RETVAL = new Point(THIS->projection_onto(*line)); %};
Point* negative()
%code{% RETVAL = new Point(- *THIS); %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};
2013-07-15 14:04:49 +00:00
2013-07-06 14:39:22 +00:00
%{
2013-07-15 14:04:49 +00:00
void
Point::rotate(angle, center_sv)
double angle;
SV* center_sv;
CODE:
Point center;
from_SV_check(center_sv, &center);
THIS->rotate(angle, center);
2013-07-15 14:04:49 +00:00
bool
Point::coincides_with(point_sv)
SV* point_sv;
2013-07-06 14:39:22 +00:00
CODE:
2013-07-15 14:04:49 +00:00
Point point;
from_SV_check(point_sv, &point);
RETVAL = (*THIS) == point;
2013-07-06 14:39:22 +00:00
OUTPUT:
RETVAL
%}
2013-07-15 14:04:49 +00:00
2013-07-06 13:26:32 +00:00
};
2014-01-07 11:48:09 +00:00
%name{Slic3r::Pointf} class Vec2d {
Vec2d(double _x = 0, double _y = 0);
~Vec2d();
Clone<Vec2d> clone()
2014-04-27 22:13:50 +00:00
%code{% RETVAL = THIS; %};
2014-08-02 22:20:55 +00:00
SV* arrayref()
%code{% RETVAL = to_SV_pureperl(THIS); %};
2014-08-02 22:20:55 +00:00
SV* pp()
%code{% RETVAL = to_SV_pureperl(THIS); %};
2014-04-27 22:13:50 +00:00
double x()
%code{% RETVAL = (*THIS)(0); %};
2014-04-27 22:13:50 +00:00
double y()
%code{% RETVAL = (*THIS)(1); %};
void set_x(double val)
%code{% (*THIS)(0) = val; %};
void set_y(double val)
%code{% (*THIS)(1) = val; %};
void translate(double x, double y)
%code{% *THIS += Vec2d(x, y); %};
void scale(double factor)
%code{% *THIS *= factor; %};
void rotate(double angle, Vec2d* center)
%code{% *THIS = Eigen::Translation2d(*center) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- *center) * Eigen::Vector2d((*THIS)(0), (*THIS)(1)); %};
Vec2d* negative()
%code{% RETVAL = new Vec2d(- *THIS); %};
Vec2d* vector_to(Vec2d* point)
%code{% RETVAL = new Vec2d(*point - *THIS); %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};
2014-04-27 22:13:50 +00:00
};
%name{Slic3r::Pointf3} class Vec3d {
Vec3d(double _x = 0, double _y = 0, double _z = 0);
~Vec3d();
Clone<Vec3d> clone()
%code{% RETVAL = THIS; %};
2014-01-07 11:48:09 +00:00
double x()
%code{% RETVAL = (*THIS)(0); %};
2014-01-07 11:48:09 +00:00
double y()
%code{% RETVAL = (*THIS)(1); %};
2014-01-07 11:48:09 +00:00
double z()
%code{% RETVAL = (*THIS)(2); %};
void set_x(double val)
%code{% (*THIS)(0) = val; %};
void set_y(double val)
%code{% (*THIS)(1) = val; %};
void set_z(double val)
%code{% (*THIS)(2) = val; %};
void translate(double x, double y, double z)
%code{% *THIS += Vec3d(x, y, z); %};
void scale(double factor)
%code{% *THIS *= factor; %};
double distance_to(Vec3d* point)
%code{% RETVAL = (*point - *THIS).norm(); %};
Vec3d* negative()
%code{% RETVAL = new Vec3d(- *THIS); %};
Vec3d* vector_to(Vec3d* point)
%code{% RETVAL = new Vec3d(*point - *THIS); %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %};
2014-01-07 11:48:09 +00:00
};