aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/include/flatten.hpp
blob: bd2d8e30bf199bc1fab468e191b139fe9e4a968e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "gerbolyze.hpp"

namespace gerbolyze {
    class curve3_div {
        public:
            curve3_div(double distance_tolerance=0.1, double angle_tolerance=0.0, double cusp_limit=0.0)
                : m_cusp_limit(cusp_limit),
                m_distance_tolerance_square(0.25*distance_tolerance*distance_tolerance),
                m_angle_tolerance(angle_tolerance)
                {
                }

            void run(double x1, double y1, double x2, double y2, double x3, double y3);
            const std::vector<d2p> &points() { return m_points; }

        private:
            void recursive_bezier(double x1, double y1, double x2, double y2, 
                                  double x3, double y3,
                                  unsigned level);
            double m_cusp_limit;
            double m_distance_tolerance_square;
            double m_angle_tolerance;
            std::vector<d2p> m_points;
    };

    class curve4_div {
        public:
            curve4_div(double distance_tolerance=0.1, double angle_tolerance=0.0, double cusp_limit=0.0)
                : m_cusp_limit(cusp_limit),
                m_distance_tolerance_square(0.25*distance_tolerance*distance_tolerance),
                m_angle_tolerance(angle_tolerance)
                {
                }

            void run(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
            const std::vector<d2p> &points() { return m_points; }

        private:
            void recursive_bezier(double x1, double y1, double x2, double y2, 
                                  double x3, double y3, double x4, double y4,
                                  unsigned level);
            double m_cusp_limit;
            double m_distance_tolerance_square;
            double m_angle_tolerance;
            std::vector<d2p> m_points;
    };
}