-
Notifications
You must be signed in to change notification settings - Fork 1
/
heuristics.hpp
170 lines (129 loc) · 3.96 KB
/
heuristics.hpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright 2020 Casey Sanchez
*/
#pragma once
#include <set>
#include <vector>
#include <initializer_list>
#include <iostream>
#include "graph.hpp"
namespace Mandoline
{
// Generates edges of a path from vertices
// e.g. Given vertices 0, 1, 2, the following edges are created:
// { 0, 1 }, { 1, 2 }
class Path
{
std::vector<Eigen::Vector2d> m_vertices;
public:
Path(std::vector<Eigen::Vector2d> const &vertices);
Path(std::initializer_list<Eigen::Vector2d> const &vertices);
void Compute(Graph &output);
};
// Generates edges of a polygon from vertices
// e.g. Given vertices 0, 1, 2, the following edges are created:
// { 0, 1 }, { 1, 2 }, { 2, 0 }
class Polygon
{
std::vector<Eigen::Vector2d> m_vertices;
public:
Polygon(std::vector<Eigen::Vector2d> const &vertices);
Polygon(std::initializer_list<Eigen::Vector2d> const &vertices);
void Compute(Graph &output);
};
// Generates a regular n-sided polygon
class Regular
{
uint32_t m_sides;
double m_radius;
public:
Regular(uint32_t const &sides, double const &radius);
void Compute(Graph &output);
};
class Bezier
{
std::vector<Eigen::Vector2d> m_vertices;
double m_bezier_gain;
public:
Bezier(std::vector<Eigen::Vector2d> const &vertices, double const &bezier_gain = 1.0);
void Compute(Graph &output);
private:
// TODO: Max of 20!, need a more efficient method for calculating binomial coefficients
uint64_t Factorial(uint64_t const &n);
};
// Applies an affine transformation to the graph.
class Transform
{
Graph m_graph;
Eigen::Affine2d m_transform;
public:
Transform(Graph const &graph, Eigen::Affine2d const &transform);
void Compute(Graph &output);
};
// Merges the graphs contained within the list to a single graph.
class Merge
{
std::vector<Graph> m_graphs;
public:
Merge(Graph const &graph_lhs, Graph const &graph_rhs);
Merge(std::initializer_list<Graph> const &graphs);
Merge(std::vector<Graph> const &graphs);
void Compute(Graph &output);
};
// Reverses the ordering of vertices in the graph.
// This changes edges from { a, b } to { b, a } which effects the edge normals.
class Invert
{
Graph m_graph;
public:
Invert(Graph const &graph);
void Compute(Graph &output);
};
// Extrudes the edges of the graph by the specified distance.
class Extrude
{
Graph m_graph;
double m_distance;
public:
Extrude(Graph const &graph, double const &distance);
void Compute(Graph &output);
};
class Slice
{
Graph m_graph;
double m_spacing;
public:
Slice(Graph const &graph, double const &spacing);
void Compute(Graph &output);
private:
void Segment(std::vector<Eigen::Vector2d> &output_vertices, std::vector<Eigen::Array2i> &output_edges);
void Connect(std::vector<Eigen::Vector2d> &output_vertices, std::vector<Eigen::Array2i> &output_edges);
};
// Creates vertices & edges at the intersections of the two graphs
class Fragment
{
Graph m_graph_lhs;
Graph m_graph_rhs;
public:
Fragment(Graph const &graph_lhs, Graph const &graph_rhs);
void Compute(Graph &output);
};
// Removes edges where the midpoint falls within the polygon
class Difference
{
Graph m_graph_lhs;
Graph m_graph_rhs;
public:
Difference(Graph const &graph_lhs, Graph const &graph_rhs);
void Compute(Graph &output);
};
// Unionizes two polygons
class Union
{
Graph m_graph_lhs;
Graph m_graph_rhs;
public:
Union(Graph const &graph_lhs, Graph const &graph_rhs);
void Compute(Graph &output);
};
}