rotate.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* rotate.cpp - Rotate transformation node
  2. * Copyright (C) 2017 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 <boost/math/constants/constants.hpp>
  18. #include <core/node/node.h>
  19. #include <core/node/property.h>
  20. #include <core/node_info.h>
  21. #include <2geom/transforms.h>
  22. using boost::math::double_constants::pi;
  23. namespace rainynite::core::nodes {
  24. class Rotate : public Node<Geom::Affine> {
  25. DOC_STRING(
  26. "Rotate transformation."
  27. )
  28. public:
  29. Rotate() {
  30. init<Geom::Affine>(source, {});
  31. init<Geom::Point>(origin, {});
  32. init<double>(angle, {});
  33. }
  34. Geom::Affine get(shared_ptr<Context> ctx) const override {
  35. auto offset = get_origin()->value(ctx);
  36. auto turns = get_angle()->value(ctx);
  37. return
  38. get_source()->value(ctx) *
  39. Geom::Translate(-offset) *
  40. Geom::Rotate(turns * pi * 2) *
  41. Geom::Translate(offset);
  42. }
  43. private:
  44. NODE_PROPERTY(source, Geom::Affine);
  45. NODE_PROPERTY(origin, Geom::Point);
  46. NODE_PROPERTY(angle, double);
  47. };
  48. REGISTER_NODE(Rotate);
  49. } // namespace rainynite::core::nodes