Point.xsp 5.0 KB

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