Skip to content

Commit

Permalink
Stream_support: Document that WKT can also handle 3D points
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Dec 20, 2024
1 parent 0780533 commit ae81703
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
15 changes: 9 additions & 6 deletions Stream_support/include/CGAL/IO/WKT.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,17 @@ bool read_multi_point_WKT(std::istream& in,
//!
//! The first line starting with LINESTRING in the stream will be used.
//!
//! \tparam Linestring must be a model of `RandomAccessRange` of `CGAL::Point_2`,
//! \tparam Linestring must be a model of `RandomAccessRange` of `CGAL::Point_2` or `CGAL::Point_3`,
//! and have:
//! - a function `push_back()` that takes a `CGAL::Point_2`.
//! - a function `push_back()` that takes a point.
//! - a function `clear()`,
//! - a function `resize()` that takes a `size_type`
//! - an `operator[]()` that takes a `size_type`.
//!
//! \attention Only %Cartesian Kernels with double or float as `FT` are supported.
//!
//! \see `CGAL::Point_2`
//! \see `CGAL::Point_3`
template<typename LineString>
bool read_linestring_WKT(std::istream& in,
LineString& polyline)
Expand Down Expand Up @@ -209,7 +210,6 @@ bool read_linestring_WKT(std::istream& in,
//!
//! \attention Only %Cartesian Kernels with double or float as `FT` are supported.
//!
//! \see `CGAL::Point_2`
template<typename MultiLineString>
bool read_multi_linestring_WKT(std::istream& in,
MultiLineString& mls)
Expand Down Expand Up @@ -359,11 +359,12 @@ bool read_multi_polygon_WKT(std::istream& in,
//!
//! \brief writes `point` into a WKT stream.
//!
//! \tparam Point is a `CGAL::Point_2`
//! \tparam Point is a `CGAL::Point_2` or `CGAL::Point_3`
//!
//! \attention Only %Cartesian Kernels with double or float as `FT` are supported.
//!
//! \see `CGAL::Point_2`
//! \see `CGAL::Point_3`
template<typename Point>
std::ostream& write_point_WKT(std::ostream& out,
const Point& point)
Expand Down Expand Up @@ -399,11 +400,12 @@ std::ostream& write_polygon_WKT(std::ostream& out,
//!
//! \brief writes the content of `ls` into a WKT stream.
//!
//! \tparam LineString must be a `RandomAccessRange` of `CGAL::Point_2`.
//! \tparam LineString must be a `RandomAccessRange` of `CGAL::Point_2` or `CGAL::Point_3`.
//!
//! \attention Only %Cartesian Kernels with double or float as `FT` are supported.
//!
//!\see `CGAL::Point_2`
//!\see `CGAL::Point_3`
template<typename LineString>
std::ostream& write_linestring_WKT(std::ostream& out,
LineString ls)
Expand All @@ -420,11 +422,12 @@ std::ostream& write_linestring_WKT(std::ostream& out,
//!
//! \brief writes the content of `mp` into a WKT stream.
//!
//! \tparam MultiPoint must be a `RandomAccessRange` of `CGAL::Point_2`.
//! \tparam MultiPoint must be a `RandomAccessRange` of `CGAL::Point_2` or `CGAL::Point_3`.
//!
//! \attention Only %Cartesian Kernels with double or float as `FT` are supported.
//!
//!\see `CGAL::Point_2`
//!\see `CGAL::Point_2`
template<typename MultiPoint>
std::ostream& write_multi_point_WKT(std::ostream& out,
MultiPoint& mp)
Expand Down
66 changes: 65 additions & 1 deletion Stream_support/test/Stream_support/test_WKT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <CGAL/IO/WKT.h>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <fstream>
#include <sstream>
#include <vector>
#include <cassert>

Expand All @@ -17,7 +17,69 @@ typedef std::vector<Point> MultiPoint
typedef std::vector<Linestring> MultiLinestring;
typedef std::vector<Poly> MultiPolygon;


typedef CGAL::Point_3<Kernel> Point3;
typedef std::vector<Point3> Linestring3;
typedef std::vector<Point3> MultiPoint3;
typedef std::vector<Linestring3> MultiLinestring3;
////////////////////////////////////////////////////////////////////////////////////////////////////

bool test_WKT_3D()
{
{
Point3 p(1,2,3), q(0,0,0);
std::stringstream ss;
CGAL::IO::write_point_WKT(ss, p);
bool b = CGAL::IO::read_point_WKT(ss, q);
assert(b);
CGAL_USE(b);
assert(p == q);
}
{
Point3 p(1,2,3), q(3,2,1);
MultiPoint3 mp, mq;
mp.push_back(p);
mp.push_back(q);
std::stringstream ss;
CGAL::IO::write_multi_point_WKT(ss, mp);
bool b = CGAL::IO::read_multi_point_WKT(ss, mq);
assert(b);
CGAL_USE(b);
assert(mp == mq);
}
{
Point3 p(1,2,3), q(3,2,1);
Linestring3 mp, mq;
mp.push_back(p);
mp.push_back(q);
std::stringstream ss;
CGAL::IO::write_linestring_WKT(ss, mp);
bool b = CGAL::IO::read_linestring_WKT(ss, mq);
assert(b);
CGAL_USE(b);
assert(mp == mq);
}
{
Point3 p(1,2,3), q(3,2,1), r(4,5,6);
Linestring3 mp, mq;
mp.push_back(p);
mp.push_back(q);
mq.push_back(p);
mq.push_back(r);
MultiLinestring3 mmp, mmq;
mmp.push_back(mp);
mmp.push_back(mq);
std::stringstream ss;
CGAL::IO::write_multi_linestring_WKT(ss, mmp);
bool b = CGAL::IO::read_multi_linestring_WKT(ss, mmq);
assert(b);
CGAL_USE(b);
assert(mmp == mmq);
}
return true;
}


////////////////////////////////////////////////////////////////////////////////////////////////////
/// Read

Expand Down Expand Up @@ -273,6 +335,8 @@ int main()
assert(ok);
ok = test_write_WKT();
assert(ok);
ok = test_WKT_3D();
assert(ok);

return EXIT_SUCCESS;
}

0 comments on commit ae81703

Please sign in to comment.