1 #include <2geom/cairo-path-sink.h>
2 #include <2geom/ellipse.h>
3 #include <2geom/line.h>
4 #include <2geom/polynomial.h>
5 #include <toys/toy-framework-2.h>
6
7 using namespace Geom;
8
9 class CircleIntersect : public Toy {
10 PointSetHandle eh, bh;
11
draw(cairo_t * cr,std::ostringstream * notify,int width,int height,bool save,std::ostringstream * timer_stream)12 void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) {
13
14 Rect all(Point(0,0), Point(width, height));
15
16 double rx = Geom::distance(eh.pts[0], eh.pts[1]);
17 double ry = Geom::distance(eh.pts[0], eh.pts[2]);
18 double rot = Geom::atan2(eh.pts[1] - eh.pts[0]);
19
20 Ellipse e(eh.pts[0], Point(rx, ry), rot);
21 D2<Bezier> b(bh.pts);
22
23 cairo_set_line_width(cr, 1.0);
24 Geom::CairoPathSink cps(cr);
25
26 // draw Bezier control polygon
27 cairo_set_source_rgba(cr, 0, 0, 1, 0.3);
28 cps.moveTo(bh.pts[0]);
29 for (unsigned i = 1; i < bh.pts.size(); ++i) {
30 cps.lineTo(bh.pts[i]);
31 }
32 cairo_stroke(cr);
33
34 // draw Bezier curve and ellipse
35 cairo_set_source_rgb(cr, 0, 0, 0);
36 cps.feed(BezierCurve(b), true);
37 cps.feed(e);
38 cairo_stroke(cr);
39
40 std::vector<ShapeIntersection> result = e.intersect(b);
41
42 cairo_set_source_rgb(cr, 1, 0, 0);
43 for (unsigned i = 0; i < result.size(); ++i) {
44 draw_handle(cr, result[i].point());
45 }
46 cairo_stroke(cr);
47
48 Toy::draw(cr, notify, width, height, save,timer_stream);
49 }
50
51 public:
CircleIntersect()52 CircleIntersect(){
53 eh.push_back(300,300); eh.push_back(450,150); eh.push_back(250, 350);
54 bh.push_back(100,100); bh.push_back(500,100); bh.push_back(100,500); bh.push_back(500,500);
55 handles.push_back(&eh);
56 handles.push_back(&bh);
57 }
58 };
59
main(int argc,char ** argv)60 int main(int argc, char **argv) {
61 init(argc, argv, new CircleIntersect());
62 return 0;
63 }
64
65 /*
66 Local Variables:
67 mode:c++
68 c-file-style:"stroustrup"
69 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
70 indent-tabs-mode:nil
71 fill-column:99
72 End:
73 */
74 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:fileencoding=utf-8:textwidth=99 :
75