convert.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * convert.cpp - test bezier path <-> knot list 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 <catch.hpp>
  19. #include <2geom/svg-path-parser.h>
  20. #include <geom_helpers/compare.h>
  21. #include <geom_helpers/knots.h>
  22. void test_convert(std::string const& svg) {
  23. auto path = Geom::parse_svg_path(svg.c_str()).at(0);
  24. auto knots = Geom::path_to_knots(path);
  25. if (knots.closed)
  26. CHECK(knots.size() == path.size_default());
  27. CHECK(knots.closed == path.closed());
  28. auto path_c = Geom::knots_to_path(knots);
  29. CHECK(Geom::paths_almost_equal(path, path_c));
  30. }
  31. TEST_CASE("Converting closed path to knot list", "[convert]") {
  32. test_convert("m 27,173 c 187,-91 221,282 0,0 z");
  33. }
  34. TEST_CASE("Converting open path to knot list", "[convert]") {
  35. test_convert("m 27,173 c 187,-91 221,282 0,0");
  36. }
  37. TEST_CASE("Converting another open path to knot list", "[convert]") {
  38. test_convert("m 27,173 c 187,-91 221,282 20,40");
  39. }