Point.xsp 4.3 KB

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