20 EndPoint() : time(0) { }
30 Edge(EndPoint f, EndPoint t,
int i,
bool c) : from(f), to(t), ix(i), cw(
c) { }
31 bool operator==(Edge
const &other)
const {
return from.time == other.from.time && to.time == other.to.time; }
39 for(
unsigned i = 0; i <= cr.size(); i++) {
40 double t = cr[i == cr.size() ? 0 : i].getTime(ix);
44 std::cout << pnt <<
"\n";
45 EndPoint cur(pnt, normal, t);
46 if(i == 0) { prev = cur;
continue; }
47 ret.push_back(Edge(prev, cur, ix,
false));
48 ret.push_back(Edge(prev, cur, ix,
true));
55void append(std::vector<T> &vec, std::vector<T>
const &other) {
56 vec.insert(vec.end(),other.begin(), other.end());
61 for(
unsigned i = 0; i < crs.size(); i++) {
70 for(
const auto & e :
es) {
71 ret.
push_back(ps[e.ix].portion(e.from.time, e.to.time));
78 cairo_set_line_width(cr,
uniform() * 10);
94void remove(std::vector<T> &vec, T
const &val) {
95 for (
typename std::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) {
106 std::vector<Edges> ret = std::vector<Edges>();
109 std::cout <<
"hello!\n";
116 std::cout << rev <<
" " << cur.from.time <<
", " << cur.to.time <<
"\n";
119 EndPoint curpnt = rev ? cur.from : cur.to;
120 Point norm = rev ? -curpnt.norm : curpnt.norm;
125 if(e == was || e.cw !=
start.
cw)
continue;
126 if((!
are_near(curpnt.time, e.from.time)) &&
127 are_near(curpnt.point, e.from.point, 0.1)) {
128 double v =
ang(norm, e.from.norm);
132 if(
start.
cw ? v < a : v > a ) {
138 if((!
are_near(curpnt.time, e.to.time)) &&
139 are_near(curpnt.point, e.to.point, 0.1)) {
140 double v =
ang(norm, -e.to.norm);
150 if(cur == was)
break;
151 }
while(!(cur ==
start));
152 if(
are_near(
start.to.point, rev ? cur.from.point : cur.to.point)) {
163class Sanitize:
public Toy {
165 std::vector<Edges>
es;
169 std::ostringstream *timer_stream)
override
171 int ix = pathix.
pts[0][
X] / 10;
181 *notify <<
ang(ap, bp);
187 void first_time(
int argc,
char** argv)
override {
188 const char *path_name=
"sanitize_examples.svgd";
201int main(
int argc,
char **argv) {
202 init(argc, argv,
new Sanitize());
Various utility functions.
void push_back(Path const &path)
Append a path at the end.
Sequence of contiguous curves, aka spline.
Point pointAt(Coord t) const
Get the point at the specified time value.
Function defined as discrete pieces.
Two-dimensional point that doubles as a vector.
void normalize()
Normalize the vector representing the point.
constexpr Point cw() const
Return a point like this point but rotated +90 degrees.
void push_back(double x, double y)
std::vector< Geom::Point > pts
virtual void first_time(int, char **)
vector< Handle * > handles
virtual void save(FILE *f)
virtual void draw(cairo_t *cr, std::ostringstream *notify, int w, int h, bool save, std::ostringstream *timing_stream)
Structure representing the intersection of two curves.
Lifts one dimensional objects into 2D.
PathVector read_svgd(char const *filename)
Create path vector from SVG path data stored in a file.
vector< vector< Point > > paths
Various utility functions.
Piecewise< D2< SBasis > > paths_to_pw(PathVector const &paths)
void append(T &a, T const &b)
A little sugar for appending a list to another.
int centroid(std::vector< Geom::Point > const &p, Geom::Point ¢roid, double &area)
polyCentroid: Calculates the centroid (xCentroid, yCentroid) and area of a polygon,...
static double area(Geom::Point a, Geom::Point b, Geom::Point c)
CrossingSet crossings_among(PathVector const &p)
std::vector< Crossing > Crossings
std::vector< Crossings > CrossingSet
Piecewise< SBasis > cross(Piecewise< D2< SBasis > > const &a, Piecewise< D2< SBasis > > const &b)
T dot(D2< T > const &a, D2< T > const &b)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
bool operator==(D2< T > const &a, D2< T > const &b)
gdouble norm(const Fvector &v)
returns the euclidean norm of the vector v
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
void cairo_path(cairo_t *cr, Geom::Path const &p)
PathVector - a sequence of subpaths.
void remove(std::vector< T > &vec, T const &val)
void draw_cell(cairo_t *cr, Edges const &es, PathVector const &ps)
PathVector edges_to_paths(Edges const &es, PathVector const &ps)
std::vector< Edge > Edges
int cellWinding(Edges const &, PathVector const &)
Edges edges(Path const &p, Crossings const &cr, unsigned ix)
std::vector< Edges > cells(cairo_t *, PathVector const &ps)
double ang(Point n1, Point n2)
two-dimensional geometric operators.
Polynomial in symmetric power basis (S-basis)
parse SVG path specifications
void cairo_set_source_rgba(cairo_t *cr, colour c)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)