point_xy.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* point_xy.cpp - combine x&y to Point (see ExtractCoord for reverse)
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <core/node_info/macros.h>
  18. #include <core/node/new_node.h>
  19. #include <2geom/point.h>
  20. namespace rainynite::core::nodes {
  21. class PointXY :
  22. public NewNode<
  23. PointXY,
  24. Geom::Point,
  25. types::Only<double>,
  26. types::Only<double>
  27. >
  28. {
  29. DOC_STRING(
  30. "Create Point from coordinate pair"
  31. )
  32. NODE_PROPERTIES("x", "y")
  33. DEFAULT_VALUES(0.0, 0.0)
  34. PROPERTY(x)
  35. PROPERTY(y)
  36. public:
  37. bool can_set() const override {
  38. return p_x()->can_set() && p_y()->can_set();
  39. }
  40. void set(Geom::Point point) override {
  41. p_x()->set_any(point.x());
  42. p_y()->set_any(point.y());
  43. }
  44. any static_any() const override {
  45. auto x = any_cast<double>(p_x()->static_any());
  46. auto y = any_cast<double>(p_y()->static_any());
  47. return Geom::Point{x, y};
  48. }
  49. protected:
  50. Geom::Point get(shared_ptr<Context> ctx) const override {
  51. return {x_value<double>(ctx), y_value<double>(ctx)};
  52. }
  53. };
  54. REGISTER_NODE(PointXY);
  55. class SymmetricPoint :
  56. public NewNode<
  57. SymmetricPoint,
  58. Geom::Point,
  59. types::Only<double>
  60. >
  61. {
  62. DOC_STRING(
  63. "Create Point with equal coordinates"
  64. )
  65. NODE_PROPERTIES("x")
  66. DEFAULT_VALUES(0.0)
  67. PROPERTY(x)
  68. public:
  69. bool can_set() const override {
  70. return p_x()->can_set();
  71. }
  72. void set(Geom::Point point) override {
  73. p_x()->set_any(point.x()); // discarding y coord..
  74. }
  75. any static_any() const override {
  76. auto x = any_cast<double>(p_x()->static_any());
  77. return Geom::Point{x, x};
  78. }
  79. protected:
  80. Geom::Point get(shared_ptr<Context> ctx) const override {
  81. auto x = x_value<double>(ctx);
  82. return {x, x};
  83. }
  84. };
  85. REGISTER_NODE(SymmetricPoint);
  86. } // namespace rainynite::core::nodes