Point.xsp 4.6 KB

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