Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Point.xsp « xsp « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c3dae321699c9f127598d1e9f7d331eb4f0af3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
%module{Slic3r::XS};

%{
#include <xsinit.h>
#include "libslic3r/Point.hpp"
#include "libslic3r/Line.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/Polyline.hpp"
%}

%name{Slic3r::Point} class Point {
    Point(int _x = 0, int _y = 0);
    ~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); %};
    SV* arrayref()
        %code{% RETVAL = to_SV_pureperl(THIS); %};
    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 = THIS->ccw(*p1, *p2); %};
    double ccw_angle(Point* p1, Point* p2)
        %code{% RETVAL = THIS->ccw_angle(*p1, *p2); %};
    Point* projection_onto_polygon(Polygon* polygon)
        %code{% RETVAL = new Point(THIS->projection_onto(*polygon)); %};
    Point* projection_onto_polyline(Polyline* polyline)
        %code{% RETVAL = new Point(THIS->projection_onto(*polyline)); %};
    Point* projection_onto_line(Line* line)
        %code{% RETVAL = new Point(THIS->projection_onto(*line)); %};
    Point* negative()
        %code{% RETVAL = new Point(- *THIS); %};
    bool coincides_with_epsilon(Point* point)
        %code{% RETVAL = (*THIS) == *point; %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};

%{

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

bool
Point::coincides_with(point_sv)
    SV*     point_sv;
    CODE:
        Point point;
        from_SV_check(point_sv, &point);
        RETVAL = (*THIS) == point;
    OUTPUT:
        RETVAL

%}

};

%name{Slic3r::Point3} class Point3 {
    Point3(int _x = 0, int _y = 0, int _z = 0);
    ~Point3();
    Clone<Point3> clone()
        %code{% RETVAL = THIS; %};
    int x()
        %code{% RETVAL = (*THIS)(0); %};
    int y()
        %code{% RETVAL = (*THIS)(1); %};
    int z()
        %code{% RETVAL = (*THIS)(2); %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld,%ld", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %};
};

%name{Slic3r::Pointf} class Pointf {
    Pointf(double _x = 0, double _y = 0);
    ~Pointf();
    Clone<Pointf> clone()
        %code{% RETVAL = THIS; %};
    SV* arrayref()
        %code{% RETVAL = to_SV_pureperl(THIS); %};
    SV* pp()
        %code{% RETVAL = to_SV_pureperl(THIS); %};
    double x()
        %code{% RETVAL = (*THIS)(0); %};
    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 += Pointf(x, y); %};
    void scale(double factor)
        %code{% *THIS *= factor; %};
    void rotate(double angle, Pointf* center)
        %code{% THIS->rotate(angle, *center); %};
    Pointf* negative()
        %code{% RETVAL = new Pointf(- *THIS); %};
    Pointf* vector_to(Pointf* point)
        %code{% RETVAL = new Pointf(*point - *THIS); %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};
};

%name{Slic3r::Pointf3} class Pointf3 {
    Pointf3(double _x = 0, double _y = 0, double _z = 0);
    ~Pointf3();
    Clone<Pointf3> clone()
        %code{% RETVAL = THIS; %};
    double x()
        %code{% RETVAL = (*THIS)(0); %};
    double y()
        %code{% RETVAL = (*THIS)(1); %};
    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 += Pointf3(x, y, z); %};
    void scale(double factor)
        %code{% *THIS *= factor; %};
    double distance_to(Pointf3* point)
        %code{% RETVAL = (*point - *THIS).norm(); %};
    Pointf3* negative()
        %code{% RETVAL = new Pointf3(- *THIS); %};
    Pointf3* vector_to(Pointf3* point)
        %code{% RETVAL = new Pointf3(*point - *THIS); %};
    std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %};
};