knot_list.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * knot_list.cpp - knot list <-> path conversion
  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 <geom_helpers/knots.h>
  22. namespace rainynite::core {
  23. namespace nodes {
  24. class KnotList : public Node<vector<Geom::Knot>> {
  25. public:
  26. KnotList() {
  27. init<Geom::BezierKnots>(path, {});
  28. }
  29. public:
  30. vector<Geom::Knot> get(shared_ptr<Context> ctx) const override {
  31. try {
  32. auto path = get_path()->get(ctx);
  33. return path.knots;
  34. } catch (...) {
  35. return {};
  36. }
  37. }
  38. private:
  39. NODE_PROPERTY(path, Geom::BezierKnots);
  40. };
  41. REGISTER_NODE(KnotList);
  42. class KnotsPath : public Node<Geom::BezierKnots> {
  43. public:
  44. KnotsPath() {
  45. init_list<Geom::Knot>(knots);
  46. init<bool>(closed, false);
  47. }
  48. public:
  49. Geom::BezierKnots get(shared_ptr<Context> ctx) const override {
  50. try {
  51. auto knots = get_knots()->get(ctx);
  52. auto closed = get_closed()->get(ctx);
  53. return Geom::BezierKnots(knots, closed);
  54. } catch (...) {
  55. return {};
  56. }
  57. }
  58. private:
  59. NODE_LIST_PROPERTY(knots, Geom::Knot);
  60. NODE_PROPERTY(closed, bool);
  61. };
  62. REGISTER_NODE(KnotsPath);
  63. } // namespace nodes
  64. } // namespace rainynite::core