Point.xsp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/libslic3r.h"
  5. #include "libslic3r/Point.hpp"
  6. #include "libslic3r/Polygon.hpp"
  7. #include "libslic3r/Polyline.hpp"
  8. %}
  9. %name{Slic3r::Point} class Point {
  10. Point(coord_t _x = 0, coord_t _y = 0);
  11. ~Point();
  12. Clone<Point> clone()
  13. %code{% RETVAL=THIS; %};
  14. void scale(double factor);
  15. void translate(double x, double y);
  16. SV* arrayref()
  17. %code{% RETVAL = to_SV_pureperl(THIS); %};
  18. SV* pp()
  19. %code{% RETVAL = to_SV_pureperl(THIS); %};
  20. long x()
  21. %code{% RETVAL = THIS->x; %};
  22. long y()
  23. %code{% RETVAL = THIS->y; %};
  24. void set_x(long val)
  25. %code{% THIS->x = val; %};
  26. void set_y(long val)
  27. %code{% THIS->y = val; %};
  28. int nearest_point_index(Points points);
  29. Clone<Point> nearest_point(Points points)
  30. %code{% Point p; THIS->nearest_point(points, &p); RETVAL = p; %};
  31. double distance_to(Point* point)
  32. %code{% RETVAL = THIS->distance_to(*point); %};
  33. double distance_to_line(Line* line)
  34. %code{% RETVAL = THIS->distance_to(*line); %};
  35. double perp_distance_to_line(Line* line)
  36. %code{% RETVAL = THIS->perp_distance_to(*line); %};
  37. double ccw(Point* p1, Point* p2)
  38. %code{% RETVAL = THIS->ccw(*p1, *p2); %};
  39. double ccw_angle(Point* p1, Point* p2)
  40. %code{% RETVAL = THIS->ccw_angle(*p1, *p2); %};
  41. Clone<Point> projection_onto_polygon(Polygon* polygon)
  42. %code{% RETVAL = new Point(THIS->projection_onto(*polygon)); %};
  43. Clone<Point> projection_onto_polyline(Polyline* polyline)
  44. %code{% RETVAL = new Point(THIS->projection_onto(*polyline)); %};
  45. Clone<Point> projection_onto_line(Line* line)
  46. %code{% RETVAL = new Point(THIS->projection_onto(*line)); %};
  47. Clone<Point> negative()
  48. %code{% RETVAL = new Point(THIS->negative()); %};
  49. bool coincides_with_epsilon(Point* point)
  50. %code{% RETVAL = THIS->coincides_with_epsilon(*point); %};
  51. %{
  52. void
  53. Point::rotate(angle, center_sv)
  54. double angle;
  55. SV* center_sv;
  56. CODE:
  57. Point center;
  58. from_SV_check(center_sv, &center);
  59. THIS->rotate(angle, center);
  60. bool
  61. Point::coincides_with(point_sv)
  62. SV* point_sv;
  63. CODE:
  64. Point point;
  65. from_SV_check(point_sv, &point);
  66. RETVAL = THIS->coincides_with(point);
  67. OUTPUT:
  68. RETVAL
  69. %}
  70. };
  71. %name{Slic3r::Point3} class Point3 {
  72. Point3(long _x = 0, long _y = 0, long _z = 0);
  73. ~Point3();
  74. Clone<Point3> clone()
  75. %code{% RETVAL = THIS; %};
  76. long x()
  77. %code{% RETVAL = THIS->x; %};
  78. long y()
  79. %code{% RETVAL = THIS->y; %};
  80. long z()
  81. %code{% RETVAL = THIS->z; %};
  82. };
  83. %name{Slic3r::Pointf} class Pointf {
  84. Pointf(double _x = 0, double _y = 0);
  85. ~Pointf();
  86. Clone<Pointf> clone()
  87. %code{% RETVAL = THIS; %};
  88. SV* arrayref()
  89. %code{% RETVAL = to_SV_pureperl(THIS); %};
  90. SV* pp()
  91. %code{% RETVAL = to_SV_pureperl(THIS); %};
  92. double x()
  93. %code{% RETVAL = THIS->x; %};
  94. double y()
  95. %code{% RETVAL = THIS->y; %};
  96. void set_x(double val)
  97. %code{% THIS->x = val; %};
  98. void set_y(double val)
  99. %code{% THIS->y = val; %};
  100. void translate(double x, double y);
  101. void scale(double factor);
  102. void rotate(double angle, Pointf* center)
  103. %code{% THIS->rotate(angle, *center); %};
  104. Clone<Pointf> negative()
  105. %code{% RETVAL = THIS->negative(); %};
  106. Clone<Pointf> vector_to(Pointf* point)
  107. %code{% RETVAL = THIS->vector_to(*point); %};
  108. };
  109. %name{Slic3r::Pointf3} class Pointf3 {
  110. Pointf3(double _x = 0, double _y = 0, double _z = 0);
  111. ~Pointf3();
  112. Clone<Pointf3> clone()
  113. %code{% RETVAL = THIS; %};
  114. double x()
  115. %code{% RETVAL = THIS->x; %};
  116. double y()
  117. %code{% RETVAL = THIS->y; %};
  118. double z()
  119. %code{% RETVAL = THIS->z; %};
  120. void set_x(double val)
  121. %code{% THIS->x = val; %};
  122. void set_y(double val)
  123. %code{% THIS->y = val; %};
  124. void set_z(double val)
  125. %code{% THIS->z = val; %};
  126. void translate(double x, double y, double z);
  127. void scale(double factor);
  128. double distance_to(Pointf3* point)
  129. %code{% RETVAL = THIS->distance_to(*point); %};
  130. Clone<Pointf3> negative()
  131. %code{% RETVAL = THIS->negative(); %};
  132. Clone<Pointf3> vector_to(Pointf3* point)
  133. %code{% RETVAL = THIS->vector_to(*point); %};
  134. };