diff --git a/Stream_support/test/Stream_support/data/simple_ascii.ply b/Stream_support/test/Stream_support/data/simple_ascii.ply new file mode 100644 index 000000000000..5bc4a19d34f2 --- /dev/null +++ b/Stream_support/test/Stream_support/data/simple_ascii.ply @@ -0,0 +1,16 @@ +ply +format ascii 1.0 +comment VCGLIB generated +element vertex 3 +property float x +property float y +property float z +property float nx +property float ny +property float nz +element face 0 +property list uchar int vertex_indices +end_header +1 1 1 2 2 2 +3 3 3 4 4 4 +5 5 5 6 6 6 diff --git a/Stream_support/test/Stream_support/issue8155.cpp b/Stream_support/test/Stream_support/issue8155.cpp new file mode 100644 index 000000000000..f92bf9cca843 --- /dev/null +++ b/Stream_support/test/Stream_support/issue8155.cpp @@ -0,0 +1,50 @@ +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::FT FT; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; +typedef std::pair PointVectorPair; +typedef CGAL::First_of_pair_property_map Point_map; +typedef CGAL::Second_of_pair_property_map Normal_map; + +int main() +{ + std::vector pv_pairs; + const std::function lambda = + [&](const PointVectorPair& p) { + FT len = p.second.squared_length(); + if (len > 0 || len != 1.0) { + Vector_3 n = p.second * (1.0 / CGAL::sqrt(len)); + pv_pairs.push_back(std::make_pair(p.first, n)); + } + else pv_pairs.push_back(p); + }; + + pv_pairs.clear(); + std::ifstream file("data/simple_ascii.ply"); + CGAL::IO::read_PLY_with_properties(file, boost::function_output_iterator(lambda), + CGAL::make_ply_point_reader(Point_map()), + CGAL::make_ply_normal_reader(Normal_map())); + + assert(pv_pairs[0].first == Point_3(1, 1, 1)); + assert(pv_pairs[1].first == Point_3(3, 3, 3)); + assert(pv_pairs[2].first == Point_3(5, 5, 5)); + + for (std::size_t i = 0; i < pv_pairs.size(); i++) { + FT dev = CGAL::abs(1.0 - pv_pairs[i].second.squared_length()); + assert(dev < 0.01); + } + + return 0; +}