point_xy.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * point_xy.cpp - combine x&y to Point (see ExtractCoord for reverse)
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <core/node_info.h>
  19. #include <core/node/node.h>
  20. #include <core/node/property.h>
  21. #include <2geom/point.h>
  22. namespace rainynite::core {
  23. namespace nodes {
  24. class PointXY : public Node<Geom::Point> {
  25. public:
  26. PointXY() {
  27. init<double>(x, 0);
  28. init<double>(y, 0);
  29. }
  30. public:
  31. Geom::Point get(shared_ptr<Context> ctx) const override {
  32. try {
  33. return {get_x()->get(ctx), get_y()->get(ctx)};
  34. } catch (...) {
  35. return {};
  36. }
  37. }
  38. bool can_set_any(any const& value) const override {
  39. return get_type() == value.type();
  40. }
  41. void set_any(any const& value) override {
  42. auto point = any_cast<Geom::Point>(value);
  43. set_property("x", make_value<double>(point.x()));
  44. set_property("y", make_value<double>(point.y()));
  45. }
  46. private:
  47. NODE_PROPERTY(x, double);
  48. NODE_PROPERTY(y, double);
  49. };
  50. REGISTER_NODE(PointXY);
  51. } // namespace nodes
  52. } // namespace rainynite::core