beziercurve-wkt

Crates.iobeziercurve-wkt
lib.rsbeziercurve-wkt
version0.1.3
sourcesrc
created_at2020-04-16 17:22:10.113053
updated_at2021-10-24 07:47:48.582036
descriptionSerialize / deserialize bezier curves to / from a WKT-like string + do clipping operations
homepagehttps://github.com/fschutt/beziercurve-wkt
repositoryhttps://github.com/fschutt/beziercurve-wkt
max_upload_size
id230843
size83,811
Felix Schütt (fschutt)

documentation

README

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

Commit count: 25

cargo fmt