Euphoria
polybezier.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 
5 #include "base/vec2.h"
6 #include "core/iterate.h"
7 
8 namespace eu::core
9 {
10  // todo(Gustav): a poly is a closed path, so rename to path
11  // todo(Gustav): add more features
12  // sebastian lague: bezier support https://github.com/SebLague/Path-Creator
13  // paper.js, smooth and simpify(path fitter) path functions: https://github.com/paperjs/paper.js/blob/develop/src/path/PathFitter.js https://github.com/paperjs/paper.js/blob/develop/src/path/PathItem.js#L466
14  // path fitter original code: https://github.com/erich666/GraphicsGems/blob/master/gems/FitCurves.c
15 
16  // suggested new names:
17  // bezier path - a bezier path that can either be open or closed, has anchor points, control points
18  // vertex path (or poly line) - a path with points with straight linear interpolated lines, can either be open or closed
19  // both paths can either be concave or convex
20  //
21  // can use a tesselator function to create triangulated/convex polygons from closed paths with closed paths as holes:
22  // https://github.com/memononen/libtess2
23  // https://github.com/SebLague/Shape-Editor-Tool/blob/master/Shape%20Editor%20E04/Assets/Geometry/Triangulator.cs
24  // -> https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
25 
26  // check if point in poly: http://geomalgorithms.com/a03-_inclusion.html
27 
28 
34  {
37 
40  };
41 
44  struct PolyBezier2
45  {
46  std::vector<vec2f> points;
47  bool is_closed = false;
48 
49  // todo(Gustav): move out to a controller?
50  bool is_autoset_enabled = false;
51 
52  PolyBezier2(const vec2f& center);
53 
54  void add_point(const vec2f& p);
55  void move_point(int i, const vec2f& delta);
56  void set_closed(bool is_closed);
57  void toggle_closed();
58  void set_auto_set_control_points(bool is_autoset);
60 
61  [[nodiscard]] BezierSegment2 get_segment(int i) const;
62 
63  [[nodiscard]] StepIteratorCreator<size_t> iterate_points() const;
64  [[nodiscard]] StepIteratorCreator<int> iterate_segments() const;
65 
66  [[nodiscard]] static bool is_anchor_point(size_t i);
67  [[nodiscard]] static bool is_control_point(size_t i);
68  };
69 
70 
79  struct Polyline2
80  {
81  std::vector<vec2f> points;
82  bool is_closed = false;
83  };
84 
85 }
Anchor and control points.
Definition: polybezier.h:34
Composite Bézier curve or polybezier.
Definition: polybezier.h:45
BezierSegment2 get_segment(int i) const
Definition: polybezier.cc:385
StepIteratorCreator< size_t > iterate_points() const
Definition: polybezier.cc:348
static bool is_anchor_point(size_t i)
Definition: polybezier.cc:360
void set_closed(bool is_closed)
Definition: polybezier.cc:391
static bool is_control_point(size_t i)
Definition: polybezier.cc:366
void set_auto_set_control_points(bool is_autoset)
Definition: polybezier.cc:404
void add_point(const vec2f &p)
Definition: polybezier.cc:354
StepIteratorCreator< int > iterate_segments() const
Definition: polybezier.cc:379
std::vector< vec2f > points
Definition: polybezier.h:46
void move_point(int i, const vec2f &delta)
Definition: polybezier.cc:373
void toggle_auto_set_control_points()
Definition: polybezier.cc:410
PolyBezier2(const vec2f &center)
Definition: polybezier.cc:337
Straight lines only.
Definition: polybezier.h:80
std::vector< vec2f > points
Definition: polybezier.h:81
Definition: vec2.h:33