Boost logo

Geometry :

Subject: [geometry] Boost.Geometry models UDLs
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-01-30 09:32:49


Hi,

I was wondering if it would be possible to implement some nice UDL for BG
models. I thought it would be great to have a compile-time WKT which whould
work e.g. like this:

"LINESTRING(0 0, 1 1, 2 2)"_wkt

if we could parse this in compile-time we'd be able to return proper type.
Unfortunately AFAIK it's (currently?) impossible to parse string literals
in compile-time. If you could proof me wrong I'd be very glad :). So I've
implemented some simplified version which can be found here:

https://github.com/awulkiew/test_boost_geometry_udl

Any ideas are welcome. It works like this:

using namespace bg::literals::cart2d;

"(1 1)"_pt; // point<double, 2, cs::cartesian>
"(0 0, 2 2)"_box; // box<p2d>
"(0 0, 1 1, 2 1)"_ls; // linestring<p2d>

// polygon<p2d> - for now the default cw closed, should probably be ccw
"((1 0, 1 3, 3 3, 3 0, 1 0))"_poly

// ring<p2d> - for now the default cw closed, should probably be ccw
// also non-WKT definition could be used - without doubled parentheses
"((1 0, 1 3, 3 3, 3 0, 1 0))"_ring

Of course you must compile it with some compiler supporting user-defined
literals, e.g. GCC >= 4.7 or Clang >= 3.1

Regards,
Adam



Geometry list run by mateusz at loskot.net