#curve #string-format #serialization #deserialize #clipping #operations #postgis

beziercurve-wkt

Serialize / deserialize bezier curves to / from a WKT-like string + do clipping operations

4 releases

0.1.3 Oct 24, 2021
0.1.2 Apr 29, 2020
0.1.1 Apr 24, 2020
0.1.0 Apr 16, 2020

#1237 in Parser implementations

22 downloads per month

MIT license

79KB
1.5K SLoC

beziercurve-wkt

beziercurve-wkt

About

This libary exists because PostGis (current version 12.0) does not support Bezier curves. However, keeping data in tables is still very useful. It's also sometimes necessary to have a human-readable format of Bezier curves. So instead of keeping the data in a binary format, the data is kept in string format and this libary provides a serializer / deserializer for it.

The string format for Bezier curves looks like this:

BEZIERCURVE((0.0 1.0, 2.0 1.0), (2.0 1.0, 46.0 20.0, 0.0 0.0), (0.0 0.0, 40.0, 47.0, 50.0 30.0, 2.0 1.0))

The parser looks at the points and determines the type of point by its length:

(x1 y1, x2 y2) -> Line from p1 to p2
(x1 y1, x2 y2, x3 y3) -> Quadratic bezier curve from p1 to p3 with control point p2
(x1 y1, x2 y2, x3 y3, x4 y4) -> Cubic bezier curve from p1 to p4 with control points p2 and p3

The reason for duplicating the point on each "item" / section is so that the BezierCurve can be constructed in parallel, if necessary.

Additional to serialization / deserialization, this library features tools to:

  • calculate the bounding box of a curve (necessary for calculating intersection of curves using a quadtree)
  • calculate intersection(s) between curve-curve and curve-line
  • calculate the angles of intersections (necessary for ex. to put texts on curves)
  • cutting curves

License

MIT

License: MIT

Dependencies

~34–460KB