Point.xsp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(int _x = 0, int _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. int x()
  20. %code{% RETVAL = THIS->x; %};
  21. int y()
  22. %code{% RETVAL = THIS->y; %};
  23. void set_x(int val)
  24. %code{% THIS->x = val; %};
  25. void set_y(int 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. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", THIS->x, THIS->y); RETVAL = buf; %};
  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(int _x = 0, int _y = 0, int _z = 0);
  73. ~Point3();
  74. Clone<Point3> clone()
  75. %code{% RETVAL = THIS; %};
  76. int x()
  77. %code{% RETVAL = THIS->x; %};
  78. int y()
  79. %code{% RETVAL = THIS->y; %};
  80. int z()
  81. %code{% RETVAL = THIS->z; %};
  82. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld,%ld", THIS->x, THIS->y, THIS->z); RETVAL = buf; %};
  83. };
  84. %name{Slic3r::Pointf} class Pointf {
  85. Pointf(double _x = 0, double _y = 0);
  86. ~Pointf();
  87. Clone<Pointf> clone()
  88. %code{% RETVAL = THIS; %};
  89. SV* arrayref()
  90. %code{% RETVAL = to_SV_pureperl(THIS); %};
  91. SV* pp()
  92. %code{% RETVAL = to_SV_pureperl(THIS); %};
  93. double x()
  94. %code{% RETVAL = THIS->x; %};
  95. double y()
  96. %code{% RETVAL = THIS->y; %};
  97. void set_x(double val)
  98. %code{% THIS->x = val; %};
  99. void set_y(double val)
  100. %code{% THIS->y = val; %};
  101. void translate(double x, double y);
  102. void scale(double factor);
  103. void rotate(double angle, Pointf* center)
  104. %code{% THIS->rotate(angle, *center); %};
  105. Clone<Pointf> negative()
  106. %code{% RETVAL = THIS->negative(); %};
  107. Clone<Pointf> vector_to(Pointf* point)
  108. %code{% RETVAL = THIS->vector_to(*point); %};
  109. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", THIS->x, THIS->y); RETVAL = buf; %};
  110. };
  111. %name{Slic3r::Pointf3} class Pointf3 {
  112. Pointf3(double _x = 0, double _y = 0, double _z = 0);
  113. ~Pointf3();
  114. Clone<Pointf3> clone()
  115. %code{% RETVAL = THIS; %};
  116. double x()
  117. %code{% RETVAL = THIS->x; %};
  118. double y()
  119. %code{% RETVAL = THIS->y; %};
  120. double z()
  121. %code{% RETVAL = THIS->z; %};
  122. void set_x(double val)
  123. %code{% THIS->x = val; %};
  124. void set_y(double val)
  125. %code{% THIS->y = val; %};
  126. void set_z(double val)
  127. %code{% THIS->z = val; %};
  128. void translate(double x, double y, double z);
  129. void scale(double factor);
  130. double distance_to(Pointf3* point)
  131. %code{% RETVAL = THIS->distance_to(*point); %};
  132. Clone<Pointf3> negative()
  133. %code{% RETVAL = THIS->negative(); %};
  134. Clone<Pointf3> vector_to(Pointf3* point)
  135. %code{% RETVAL = THIS->vector_to(*point); %};
  136. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", THIS->x, THIS->y, THIS->z); RETVAL = buf; %};
  137. };