summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/2geom/src/toys/self-intersect.cpp
blob: 840e05811232ad89b90b383dd2721bcb2f5ae876 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <2geom/basic-intersection.h>
#include <2geom/d2.h>
#include <2geom/sbasis.h>
#include <2geom/sbasis-2d.h>
#include <2geom/bezier-to-sbasis.h>

#include <toys/path-cairo.h>
#include <toys/toy-framework-2.h>

using std::vector;
using namespace Geom;

class SelfIntersect: public Toy {
    PointSetHandle psh;
void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) override {
    cairo_set_line_width (cr, 0.5);
    cairo_set_source_rgba (cr, 0., 0., 0, 1);
    
    D2<SBasis> A = psh.asBezier();
    //Rect Ar = *bounds_fast(A);
    cairo_d2_sb(cr, A);
    cairo_stroke(cr);

    std::vector<std::pair<double, double> >  all_si;
    
    find_self_intersections(all_si, A);
    
    cairo_stroke(cr);
    cairo_set_source_rgba (cr, 1., 0., 1, 1);
    for(auto & i : all_si) {
        draw_handle(cr, A(i.first));
    }
    cairo_stroke(cr);
    
    *notify << "total intersections: " << all_si.size();

    Toy::draw(cr, notify, width, height, save,timer_stream);
}
public:
SelfIntersect (unsigned bez_ord) {
    handles.push_back(&psh);
    for(unsigned i = 0; i < bez_ord; i++)
        psh.push_back(uniform()*400, uniform()*400);
}
};

int main(int argc, char **argv) {   
    unsigned bez_ord=5;
    if(argc > 1)
        sscanf(argv[1], "%d", &bez_ord);
    init(argc, argv, new SelfIntersect(bez_ord));

    return 0;
}



/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :