Point.xsp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. Clone<Point> nearest_point(Points points)
  31. %code{% RETVAL = nearest_point(points, *THIS).first; %};
  32. double distance_to(Point* point)
  33. %code{% RETVAL = (*point - *THIS).cast<double>().norm(); %};
  34. double distance_to_line(Line* line)
  35. %code{% RETVAL = line->distance_to(*THIS); %};
  36. double perp_distance_to_line(Line* line)
  37. %code{% RETVAL = line->perp_distance_to(*THIS); %};
  38. double ccw(Point* p1, Point* p2)
  39. %code{% RETVAL = cross2((*p1 - *THIS).cast<double>(), (*p2 - *p1).cast<double>()); %};
  40. Point* negative()
  41. %code{% RETVAL = new Point(- *THIS); %};
  42. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};
  43. %{
  44. void
  45. Point::rotate(angle, center_sv)
  46. double angle;
  47. SV* center_sv;
  48. CODE:
  49. Point center;
  50. from_SV_check(center_sv, &center);
  51. THIS->rotate(angle, center);
  52. bool
  53. Point::coincides_with(point_sv)
  54. SV* point_sv;
  55. CODE:
  56. Point point;
  57. from_SV_check(point_sv, &point);
  58. RETVAL = (*THIS) == point;
  59. OUTPUT:
  60. RETVAL
  61. %}
  62. };
  63. %name{Slic3r::Pointf} class Vec2d {
  64. Vec2d(double _x = 0, double _y = 0);
  65. ~Vec2d();
  66. Clone<Vec2d> clone()
  67. %code{% RETVAL = THIS; %};
  68. SV* arrayref()
  69. %code{% RETVAL = to_SV_pureperl(THIS); %};
  70. SV* pp()
  71. %code{% RETVAL = to_SV_pureperl(THIS); %};
  72. double x()
  73. %code{% RETVAL = (*THIS)(0); %};
  74. double y()
  75. %code{% RETVAL = (*THIS)(1); %};
  76. void set_x(double val)
  77. %code{% (*THIS)(0) = val; %};
  78. void set_y(double val)
  79. %code{% (*THIS)(1) = val; %};
  80. void translate(double x, double y)
  81. %code{% *THIS += Vec2d(x, y); %};
  82. void scale(double factor)
  83. %code{% *THIS *= factor; %};
  84. void rotate(double angle, Vec2d* center)
  85. %code{% *THIS = Eigen::Translation2d(*center) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- *center) * Eigen::Vector2d((*THIS)(0), (*THIS)(1)); %};
  86. Vec2d* negative()
  87. %code{% RETVAL = new Vec2d(- *THIS); %};
  88. Vec2d* vector_to(Vec2d* point)
  89. %code{% RETVAL = new Vec2d(*point - *THIS); %};
  90. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %};
  91. };
  92. %name{Slic3r::Pointf3} class Vec3d {
  93. Vec3d(double _x = 0, double _y = 0, double _z = 0);
  94. ~Vec3d();
  95. Clone<Vec3d> clone()
  96. %code{% RETVAL = THIS; %};
  97. double x()
  98. %code{% RETVAL = (*THIS)(0); %};
  99. double y()
  100. %code{% RETVAL = (*THIS)(1); %};
  101. double z()
  102. %code{% RETVAL = (*THIS)(2); %};
  103. void set_x(double val)
  104. %code{% (*THIS)(0) = val; %};
  105. void set_y(double val)
  106. %code{% (*THIS)(1) = val; %};
  107. void set_z(double val)
  108. %code{% (*THIS)(2) = val; %};
  109. void translate(double x, double y, double z)
  110. %code{% *THIS += Vec3d(x, y, z); %};
  111. void scale(double factor)
  112. %code{% *THIS *= factor; %};
  113. double distance_to(Vec3d* point)
  114. %code{% RETVAL = (*point - *THIS).norm(); %};
  115. Vec3d* negative()
  116. %code{% RETVAL = new Vec3d(- *THIS); %};
  117. Vec3d* vector_to(Vec3d* point)
  118. %code{% RETVAL = new Vec3d(*point - *THIS); %};
  119. std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %};
  120. };