summaryrefslogtreecommitdiffstats
path: root/src/toys/conic-section-toy.cpp
blob: 31695bef0433b6206c48273afd0d5a29fecfe5a2 (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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
/*
 * Conic Section Toy
 *
 * Authors:
 *      Marco Cecchetti <mrcekets at gmail.com>
 *
 * Copyright 2009  authors
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 */


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

//#define CLIP_WITH_CAIRO_SUPPORT
#ifdef CLIP_WITH_CAIRO_SUPPORT
    #include <2geom/conic_section_clipper_cr.h>
#endif


#include <2geom/conicsec.h>
#include <2geom/line.h>

//#include <iomanip>
#include <optional>


using namespace Geom;


class ConicSectionToy : public Toy
{
    enum menu_item_t
    {
        SHOW_MENU = 0,
        TEST_VERTEX_FOCI,
        TEST_FITTING,
        TEST_ECCENTRICITY,
        TEST_DEGENERATE,
        TEST_ROOTS,
        TEST_NEAREST_POINT,
        TEST_BOUND,
        TEST_CLIP,
        TEST_TANGENT,
        TEST_DUAL,
        TOTAL_ITEMS // this one must be the last item
    };

    static const char* menu_items[TOTAL_ITEMS];
    static const char keys[TOTAL_ITEMS];

    void first_time(int /*argc*/, char** /*argv*/) override
    {
        draw_f = &ConicSectionToy::draw_menu;
    }


    void init_common()
    {
        init_vertex_foci();
        set_control_geometry = true;
    }

    void draw_common (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_vertex_foci(cr, notify, width, height, save, timer_stream);
    }


/*
 *  TEST VERTEX FOCI
 */
    void init_vertex_foci()
    {
        set_common_control_geometry = true;
        handles.clear();

        focus1.pos = Point(300, 300);
        focus2.pos = Point(500, 300);
        vertex.pos = Point(200, 300);

        parabola_toggle = Toggle("set/unset F2 to infinity", false);

        handles.push_back (&vertex);
        handles.push_back (&focus1);
        handles.push_back (&focus2);
        handles.push_back (&parabola_toggle);
    }

    void draw_vertex_foci (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool /*save*/,
                         std::ostringstream * /*timer_stream*/)
    {
        init_vertex_foci_ctrl_geom(cr, notify, width, height);


        if (!parabola_toggle.on )
        {
            if (focus2.pos == Point(infinity(),infinity()))
                focus2.pos = Point(m_width/2, m_height/2);
            double df1f2 = distance (focus1.pos, focus2.pos);
            if (df1f2 > 20 )
            {
                Line axis(focus1.pos,focus2.pos);
                vertex.pos = projection (vertex.pos, axis);
            }
            else if (df1f2 > 1)
            {
                Line axis(focus1.pos,vertex.pos);
                focus2.pos = projection (focus2.pos, axis);
            }
            else
            {
                Line axis(focus1.pos,vertex.pos);
                focus2.pos = focus1.pos;
            }
        }
        else
        {
            focus2.pos = Point(infinity(),infinity());
        }

        cs.set (vertex.pos, focus1.pos, focus2.pos);
        cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0);
        cairo_set_line_width (cr, 0.5);
        draw (cr, cs, m_window);
        cairo_stroke(cr);

        draw_label(cr, focus1, "F1");
        if (!parabola_toggle.on)  draw_label(cr, focus2, "F2");
        draw_label(cr, vertex, "V");
        cairo_stroke(cr);

        *notify << cs.categorise() << ": " << cs << std::endl;
    }

    void init_vertex_foci_ctrl_geom (cairo_t* /*cr*/,
                                     std::ostringstream* /*notify*/,
                                     int width, int /*height*/)
    {
        if ( set_common_control_geometry )
        {
            set_common_control_geometry = false;

            Point toggle_sp( width - 200, 10);
            parabola_toggle.bounds = Rect (toggle_sp, toggle_sp + Point(190,30));
        }
    }


/*
 *  TEST FITTING
 */
    void init_fitting()
    {
        set_common_control_geometry = true;
        handles.clear();

        psh.pts.resize(5);
        psh.pts[0] = Point(450, 250);
        psh.pts[1] = Point(250, 100);
        psh.pts[2] = Point(250, 400);
        psh.pts[3] = Point(400, 320);
        psh.pts[4] = Point(50, 250);

        fitting_slider.set (0, 5, 1, 0, "more handles");

        handles.push_back(&psh);
        handles.push_back(&fitting_slider);
    }

    void draw_fitting (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool /*save*/,
                         std::ostringstream * /*timer_stream*/)
    {
        init_fitting_ctrl_geom(cr, notify, width, height);

        size_t n = (size_t)(fitting_slider.value()) + 5;
        if (n < psh.pts.size())
        {
            psh.pts.resize(n);
        }
        else if (n > psh.pts.size())
        {
            psh.push_back (std::fabs (width - 100) * uniform() + 50,
                           std::fabs (height - 100) * uniform() + 50);
        }

        cs.set (psh.pts);

        cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0);
        cairo_set_line_width (cr, 0.5);
        draw (cr, cs, m_window);
        cairo_stroke(cr);
        *notify << cs.categorise() << ": " << cs << std::endl;
    }

    void init_fitting_ctrl_geom (cairo_t* /*cr*/,
                                 std::ostringstream* /*notify*/,
                                 int /*width*/, int height)
    {
        if ( set_common_control_geometry )
        {
            set_common_control_geometry = false;
            fitting_slider.geometry (Point(50, height - 50), 100);
        }
    }


/*
 *  TEST ECCENTRICITY
 */
    void init_eccentricity()
    {
        set_common_control_geometry = true;
        handles.clear();

        p1 = Point (100, 100);
        p2 = Point (100, 400);
        focus1 = Point (300, 250);

        eccentricity_slider.set (0, 3, 0, 1, "eccentricity");

        handles.push_back (&p1);
        handles.push_back (&p2);
        handles.push_back (&focus1);
        handles.push_back (&eccentricity_slider);
    }

    void draw_eccentricity (cairo_t *cr, std::ostringstream *notify,
                            int width, int height, bool /*save*/,
                            std::ostringstream * /*timer_stream*/)
    {
        init_eccentricity_ctrl_geom(cr, notify, width, height);

        Line directrix (p1.pos, p2.pos);

        cs.set (focus1.pos, directrix, eccentricity_slider.value());

        cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0);
        cairo_set_line_width (cr, 0.5);
        draw (cr, cs, m_window);
        cairo_stroke(cr);

        draw_label (cr, focus1, "F");
        draw_line (cr, directrix, m_window);
        draw_label(cr, p1, "directrix");
        cairo_stroke(cr);

        *notify << cs.categorise() << ": " << cs << std::endl;
    }

    void init_eccentricity_ctrl_geom (cairo_t* /*cr*/,
                                      std::ostringstream* /*notify*/,
                                      int /*width*/, int height)
    {
        if ( set_common_control_geometry )
        {
            set_common_control_geometry = false;
            eccentricity_slider.geometry (Point (10, height - 50), 300);
        }
    }



/*
 *  TEST DEGENERATE
 */
    void init_degenerate()
    {
        set_common_control_geometry = true;
        handles.clear();

        psh.pts.resize(4);
        psh.pts[0] = Point(450, 250);
        psh.pts[1] = Point(250, 100);
        psh.pts[2] = Point(250, 400);
        psh.pts[3] = Point(400, 320);



        handles.push_back(&psh);
    }

    void draw_degenerate (cairo_t *cr, std::ostringstream *notify,
                          int width, int height, bool /*save*/,
                          std::ostringstream * /*timer_stream*/)
    {
        init_degenerate_ctrl_geom(cr, notify, width, height);

        Line l1 (psh.pts[0], psh.pts[1]);
        Line l2 (psh.pts[2], psh.pts[3]);
        cs.set (l1, l2);
        cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0);
        cairo_set_line_width (cr, 0.5);
        draw (cr, cs, m_window);
        cairo_stroke(cr);

        *notify << cs.categorise() << ": " << cs << std::endl;
    }

    void init_degenerate_ctrl_geom (cairo_t* /*cr*/,
                                    std::ostringstream* /*notify*/,
                                    int /*width*/, int /*height*/)
    {
        if ( set_common_control_geometry )
        {
            set_common_control_geometry = false;
        }
    }


/*
 *  TEST ROOTS
 */
    void init_roots()
    {
        init_common();

        p1.pos = Point(180, 50);

        x_y_toggle = Toggle("X/Y roots", true);

        handles.push_back(&p1);
        handles.push_back(&x_y_toggle);
    }

    void draw_roots (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);
        init_roots_ctrl_geom(cr, notify, width, height);


        Dim2 DIM = x_y_toggle.on ? X : Y;
        Line l(p1.pos, DIM * (-M_PI/2) + M_PI/2);

        cairo_set_line_width(cr, 0.2);
        cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0);
        draw_line(cr, l, m_window);
        cairo_stroke(cr);

        cairo_set_source_rgba(cr, 0.8, 0.0, 0.0, 1.0);
        std::vector<double> values;
        try
        {
            cs.roots(values, p1.pos[DIM], DIM);
        }
        catch(Geom::Exception e)
        {
            std::cerr << e.what() << std::endl;
        }
        for (double value : values)
        {
            Point p(value, value);
            p[DIM] = p1.pos[DIM];
            draw_handle(cr, p);
        }
        cairo_stroke(cr);

        *notify << "                 ";
        for ( unsigned int i = 0; i < values.size(); ++i )
        {
            *notify << "v" << i << " = " << values[i] << "  ";
        }
    }

    void init_roots_ctrl_geom (cairo_t* /*cr*/, std::ostringstream* /*notify*/,
                               int width, int height)
    {
        if ( set_control_geometry )
        {
            set_control_geometry = false;

            Point T(width - 120, height - 60);
            x_y_toggle.bounds = Rect( T, T + Point(100,25) );
        }
    }

/*
 *  TEST NEAREST POINT
 */

    void init_nearest_time()
    {
        init_common();
        p1.pos = Point(180, 50);
        handles.push_back(&p1);
    }

    void draw_nearest_time (cairo_t *cr, std::ostringstream *notify,
                             int width, int height, bool save,
                             std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);

        Point P;
        try
        {
            P = cs.nearestTime (p1.pos);
        }
        catch (LogicalError e)
        {
            std::cerr << e.what() << std::endl;
        }


        cairo_set_source_rgba(cr, 0.8, 0.1, 0.1, 1.0);
        draw_line_seg(cr, p1.pos, P);
        cairo_stroke(cr);

        cairo_set_source_rgba(cr, 0.1, 0.1, 0.9, 1.0);
        draw_handle(cr, P);
        cairo_stroke(cr);
        cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 1.0);
        draw_label(cr, p1, "Q");
        draw_text(cr, P + Point(5, 5), "P");
        cairo_stroke(cr);
    }

/*
 *  TEST BOUND
 */
    void init_bound()
    {
        init_common();
        p1.pos = Point(50, 200);
        p2.pos = Point(50, 400);
        p3.pos = Point(50, 500);
        handles.push_back(&p1);
        handles.push_back(&p2);
        handles.push_back(&p3);
    }

    void draw_bound (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);

        try
        {
            p1.pos = cs.nearestTime (p1.pos);
            p2.pos = cs.nearestTime (p2.pos);
            p3.pos = cs.nearestTime (p3.pos);
        }
        catch (LogicalError e)
        {
            std::cerr << e.what() << std::endl;
        }

        Rect bound = cs.arc_bound (p1.pos, p2.pos, p3.pos);
        cairo_set_source_rgba(cr, 0.8, 0.1, 0.1, 1.0);
        cairo_set_line_width (cr, 0.5);
        cairo_rectangle (cr, bound);
        cairo_stroke(cr);

        cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 1.0);
        draw_label (cr, p1, "initial");
        draw_label (cr, p2, "inner");
        draw_label (cr, p3, "final");
        cairo_stroke(cr);

    }

/*
 *  TEST CLIP
 */
    void init_clip()
    {
        init_common();
    }

    void draw_clip (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);
        //init_clip_ctrl_geom(cr, notify, width, height);


        Rect R(Point (100, 100),Point (width-100, height-100));
        std::vector<RatQuad> rq;
#ifdef  CLIP_WITH_CAIRO_SUPPORT
        clipper_cr aclipper(cr, cs, R);
        aclipper.clip (rq);
#else
        clip (rq, cs, R);
#endif
        cairo_set_source_rgba(cr, 0.8, 0.1, 0.1, 1.0);
        cairo_set_line_width (cr, 0.5);
        cairo_rectangle (cr, Rect (Point (100, 100),Point (width-100, height-100)));
        for (auto & i : rq)
        {
            cairo_d2_sb (cr, i.toCubic().toSBasis());
        }
        cairo_stroke(cr);
    }

/*
 *  TEST TANGENT
 */
    void init_tangent()
    {
        init_common();

        p1.pos = Point(180, 50);

        handles.push_back(&p1);
    }

    void draw_tangent (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);

        p1.pos = cs.nearestTime (p1.pos);
        Line l = cs.tangent(p1.pos);

        draw_label (cr, p1, "P");
        cairo_set_source_rgba(cr, 0.8, 0.0, 0.0, 1.0);
        draw_line(cr, l, m_window);
        cairo_stroke(cr);
    }

/*
 *  TEST DUAL
 */
    void init_dual()
    {
        init_common();
    }

    void draw_dual (cairo_t *cr, std::ostringstream *notify,
                         int width, int height, bool save,
                         std::ostringstream * timer_stream)
    {
        draw_common(cr, notify, width, height, save, timer_stream);

        cairo_set_source_rgba(cr, 0.8, 0.0, 0.0, 1.0);
        xAx dc = cs.dual();
        // we need some trick to make the dual visible in the window
        std::string dckind = dc.categorise();
        std::optional<Point> T = dc.centre();
        if (T)  dc = dc.translate (-*T);
        dc = dc.scale (1e-5, 1e-5);
        dc = dc.translate (Point(width/2, height/2));
        draw (cr, dc, m_window);
        cairo_stroke(cr);
        *notify << "\n dual: " << dckind << ": " << dc;
    }


    void draw_segment (cairo_t* cr, Point const& p1, Point const&  p2)
    {
        cairo_move_to(cr, p1);
        cairo_line_to(cr, p2);
    }

    void draw (cairo_t* cr, xAx const& cs, const Rect& _window)
    {

        // offset
        //Point O(400, 300);
        Point O(0, 0);
        std::vector<double> r1, r2;

        size_t N = (size_t)(2 *_window.width());
        double dx = 0.5;//width / N;
        //std::cout << "dx = " << dx << std::endl;
        double x = _window.left() - O[X];
        for (size_t i = 0; i < N; ++i, x += dx)
        {
            if (r1.empty())
            {
                cs.roots(r1, x, X);
                if (r1.size() == 1)
                {
                    r1.push_back(r1.front());
                }
                if (i != 0 && r1.size() == 2)
                {
                    Point p1(x-dx, r1[0]);
                    Point p2(x-dx, r1[1]);
                    p1 += O; p2 += O;
                    if (_window.contains(p1) && _window.contains(p2))
                        draw_segment(cr, p1, p2);
                }
                continue;
            }
            cs.roots(r2, x, X);
            if (r2.empty())
            {
                Point p1(x-dx, r1[0]);
                Point p2(x-dx, r1[1]);
                p1 += O; p2 += O;
                if (_window.contains(p1) && _window.contains(p2))
                    draw_segment(cr, p1, p2);
                r1.clear();
                continue;
            }
            if (r2.size() == 1)
            {
                r2.push_back(r2.front());
            }

            Point p1(x-dx, r1[0]);
            Point p2(x, r2[0]);
            p1 += O; p2 += O;
            if (_window.contains(p1) && _window.contains(p2))
                draw_segment(cr, p1, p2);

            p1 = Point(x-dx, r1[1]) + O;
            p2 = Point(x, r2[1]) + O;
            if (_window.contains(p1) && _window.contains(p2))
                draw_segment(cr, p1, p2);

            using std::swap;
            swap(r1, r2);
        }
    }

    void draw_label(cairo_t* cr, PointHandle const& ph, const char* label)
    {
        draw_text(cr, ph.pos+op, label);
    }

//    void draw_label(cairo_t* cr, Line const& l, const char* label)
//    {
//        draw_text(cr, projection(Point(m_width/2-30, m_height/2-30), l)+op, label);
//    }

    void init_menu()
    {
        handles.clear();
    }

    void draw_menu( cairo_t * /*cr*/, std::ostringstream *notify,
                    int /*width*/, int /*height*/, bool /*save*/,
                    std::ostringstream */*timer_stream*/ )
    {
        *notify << std::endl;
        for (int i = SHOW_MENU; i < TOTAL_ITEMS; ++i)
        {
            *notify << "   " << keys[i] << " -  " <<  menu_items[i] << std::endl;
        }
    }


    void key_hit(GdkEventKey *e) override
    {
        char choice = std::toupper(e->keyval);
        switch ( choice )
        {
            case 'A':
                init_menu();
                draw_f = &ConicSectionToy::draw_menu;
                break;
            case 'B':
                init_common();
                draw_f = &ConicSectionToy::draw_vertex_foci;
                break;
            case 'C':
                init_fitting();
                draw_f = &ConicSectionToy::draw_fitting;
                break;
            case 'D':
                init_eccentricity();
                draw_f = &ConicSectionToy::draw_eccentricity;
                break;
            case 'E':
                init_degenerate();
                draw_f = &ConicSectionToy::draw_degenerate;
                break;
            case 'F':
                init_roots();
                draw_f = &ConicSectionToy::draw_roots;
                break;
            case 'G':
                init_nearest_time();
                draw_f = &ConicSectionToy::draw_nearest_time;
                break;
            case 'H':
                init_bound();
                draw_f = &ConicSectionToy::draw_bound;
                break;
            case 'K':
                init_clip();
                draw_f = &ConicSectionToy::draw_clip;
                break;
            case 'J':
                init_tangent();
                draw_f = &ConicSectionToy::draw_tangent;
                break;
            case 'I':
                init_dual();
                draw_f = &ConicSectionToy::draw_dual;
                break;

        }
        redraw();
    }

    void draw( cairo_t *cr, std::ostringstream *notify,
                       int width, int height, bool save,
                       std::ostringstream *timer_stream ) override
    {
        if (timer_stream == 0)  timer_stream = notify;
        m_width = width;
        m_height = height;
        m_length = (m_width > m_height) ? m_width : m_height;
        m_length *= 2;
        m_window = Rect (Point (0, 0), Point (m_width, m_height));
        (this->*draw_f)(cr, notify, width, height, save, timer_stream);
        Toy::draw(cr, notify, width, height, save, timer_stream);
    }

public:
    ConicSectionToy()
    {
        op = Point(5,5);
    }

private:
    typedef void (ConicSectionToy::* draw_func_t) (cairo_t*, std::ostringstream*, int, int, bool, std::ostringstream*);
    draw_func_t draw_f;
    bool set_common_control_geometry;
    bool set_control_geometry;
    Point op;
    double m_width, m_height, m_length;
    Rect m_window;

    xAx cs;
    PointHandle vertex, focus1, focus2;
    Toggle parabola_toggle;

    PointSetHandle psh;
    Slider fitting_slider;

    PointHandle p1, p2, p3;
    Toggle x_y_toggle;

    Slider eccentricity_slider;
};


const char* ConicSectionToy::menu_items[] =
{
    "show this menu",
    "vertex and foci",
    "fitting",
    "eccentricity",
    "degenerate",
    "roots",
    "nearest point",
    "bound",
    "clip",
    "tangent",
    "dual"
};

const char ConicSectionToy::keys[] =
{
     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'K', 'J', 'I'
};


int main(int argc, char **argv)
{
    //std::cout.precision(20);
    init( argc, argv, new ConicSectionToy(), 800, 600 );
    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 :