From 530b634c56247557f6123d597c6b324a36a19f5b Mon Sep 17 00:00:00 2001 From: Sebastian Kapfer Date: Fri, 8 May 2026 00:38:06 +0200 Subject: [PATCH] Handle DOS line endings --- lib/readpoly.cpp | 1 + test_suite/inputs/cuboid-dos.off | 19 +++++++++++++++++++ test_suite/test_offreader.cpp | 14 ++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test_suite/inputs/cuboid-dos.off diff --git a/lib/readpoly.cpp b/lib/readpoly.cpp index e999ef2..35b35c5 100644 --- a/lib/readpoly.cpp +++ b/lib/readpoly.cpp @@ -84,6 +84,7 @@ namespace { { case ' ': case '\t': + case '\r': is.get (); break; default: diff --git a/test_suite/inputs/cuboid-dos.off b/test_suite/inputs/cuboid-dos.off new file mode 100644 index 0000000..6c859df --- /dev/null +++ b/test_suite/inputs/cuboid-dos.off @@ -0,0 +1,19 @@ +OFF +# cuboid.off +# Ein Quader. + +8 6 12 + 1.0 0.0 1.0 + 0.0 1.0 1.0 +-1.0 0.0 1.0 + 0.0 -1.0 1.0 + 1.0 0.0 -1.0 + 0.0 1.0 -1.0 +-1.0 0.0 -1.0 + 0.0 -1.0 -1.0 + 4 0 1 2 3 + 4 7 4 0 3 + 4 4 5 1 0 + 4 5 6 2 1 + 4 3 2 6 7 + 4 6 5 4 7 diff --git a/test_suite/test_offreader.cpp b/test_suite/test_offreader.cpp index c0e8b09..d415150 100644 --- a/test_suite/test_offreader.cpp +++ b/test_suite/test_offreader.cpp @@ -18,6 +18,20 @@ TEST_CASE( "parse valid off file without labels" ){ CHECK (surface.label_of_triangle(i) == LABEL_UNASSIGNED); } +TEST_CASE( "parse valid off file without labels; DOS line endings" ){ + Triangulation surface; + std::ifstream is ("inputs/cuboid-dos.off"); + ReadIntoTriangulation adap1 (&surface, false); + TriangulatingPolyFileSink adap2 (&adap1); + parse_off_file (&adap2, is); + CHECK (surface.n_triangles () == 6 * 2); + CHECK (surface.n_vertices () == 8); + CHECK_THAT(surface.get_pos_of_vertex (0), IsApprox({1, 0, 1}, 1e-12)); + CHECK_THAT(surface.get_pos_of_vertex (7), IsApprox({0, -1, -1}, 1e-12)); + for (int i = 0; i != 12; ++i) + CHECK (surface.label_of_triangle(i) == LABEL_UNASSIGNED); +} + TEST_CASE( "parse valid off file without labels, but expecting to find some" ){ Triangulation surface; std::ifstream is ("inputs/cuboid.off");