summaryrefslogtreecommitdiffstats
path: root/kig/objects/conic_types.cc
blob: 343963695aef72eb082fdabe0601c06cc59bd0dc (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
// Copyright (C)  2003  Dominique Devriese <devriese@kde.org>

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

#include "conic_types.h"

#include "bogus_imp.h"
#include "conic_imp.h"
#include "point_imp.h"
#include "circle_imp.h"
#include "line_imp.h"
#include "object_calcer.h"
#include "../misc/conic-common.h"
#include "../misc/common.h"
#include "../kig/kig_commands.h"
#include "../kig/kig_part.h"

#include <klocale.h>

static const char conic_constructstatement[] = I18N_NOOP( "Construct a conic through this point" );

static const struct ArgsParser::spec argsspecConicB5P[] =
{
  { PointImp::stype(), conic_constructstatement,
    I18N_NOOP( "Select a point for the new conic to go through..." ), true },
  { PointImp::stype(), conic_constructstatement,
    I18N_NOOP( "Select a point for the new conic to go through..." ), true },
  { PointImp::stype(), conic_constructstatement,
    I18N_NOOP( "Select a point for the new conic to go through..." ), true },
  { PointImp::stype(), conic_constructstatement,
    I18N_NOOP( "Select a point for the new conic to go through..." ), true },
  { PointImp::stype(), conic_constructstatement,
    I18N_NOOP( "Select a point for the new conic to go through..." ),true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicB5PType )

ConicB5PType::ConicB5PType()
  : ArgsParserObjectType( "ConicB5P", argsspecConicB5P, 5 )
{
}

ConicB5PType::~ConicB5PType()
{
}

ObjectImp* ConicB5PType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents, 1 ) ) return new InvalidImp;
  std::vector<Coordinate> points;

  for ( Args::const_iterator i = parents.begin(); i != parents.end(); ++i )
    points.push_back( static_cast<const PointImp*>( *i )->coordinate() );

  ConicCartesianData d =
    calcConicThroughPoints( points, zerotilt, parabolaifzt, ysymmetry );
  if ( d.valid() )
    return new ConicImpCart( d );
  else return new InvalidImp;
}

const ConicB5PType* ConicB5PType::instance()
{
  static const ConicB5PType t;
  return &t;
}

static const ArgsParser::spec argsspecConicBAAP[] =
{
  { AbstractLineImp::stype(), I18N_NOOP( "Construct a conic with this asymptote" ),
    I18N_NOOP( "Select the first asymptote of the new conic..." ), false },
  { AbstractLineImp::stype(), I18N_NOOP( "Construct a conic with this asymptote" ),
    I18N_NOOP( "Select the second asymptote of the new conic..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct a conic through this point" ),
    I18N_NOOP( "Select a point for the new conic to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicBAAPType )

ConicBAAPType::ConicBAAPType()
  : ArgsParserObjectType( "ConicBAAP", argsspecConicBAAP, 3 )
{
}

ConicBAAPType::~ConicBAAPType()
{
}

const ConicBAAPType* ConicBAAPType::instance()
{
  static const ConicBAAPType t;
  return &t;
}

ObjectImp* ConicBAAPType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) )
    return new InvalidImp;
  const LineData la = static_cast<const AbstractLineImp*>( parents[0] )->data();
  const LineData lb = static_cast<const AbstractLineImp*>( parents[1] )->data();
  const Coordinate c = static_cast<const PointImp*>( parents[2] )->coordinate();

  return new ConicImpCart( calcConicByAsymptotes( la, lb, c ) );
}

ObjectImp* ConicBFFPType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents, 2 ) ) return new InvalidImp;
  std::vector<Coordinate> cs;

  for ( Args::const_iterator i = parents.begin(); i != parents.end(); ++i )
    cs.push_back( static_cast<const PointImp*>( *i )->coordinate() );

  return new ConicImpPolar( calcConicBFFP( cs, type() ) );
}

ConicBFFPType::ConicBFFPType( const char* fullname, const ArgsParser::spec* spec, int n )
  : ArgsParserObjectType( fullname, spec, n )
{
}

ConicBFFPType::~ConicBFFPType()
{
}

static const char constructellipsewithfocusstat[] =
  I18N_NOOP( "Construct an ellipse with this focus" );

static const ArgsParser::spec argsspecEllipseBFFP[] =
{
  { PointImp::stype(), constructellipsewithfocusstat,
    I18N_NOOP( "Select the first focus of the new ellipse..." ), false },
  { PointImp::stype(), constructellipsewithfocusstat,
    I18N_NOOP( "Select the second focus of the new ellipse..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct an ellipse through this point" ),
    I18N_NOOP( "Select a point for the new ellipse to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( EllipseBFFPType )

EllipseBFFPType::EllipseBFFPType()
  : ConicBFFPType( "EllipseBFFP", argsspecEllipseBFFP, 3 )
{
}

EllipseBFFPType::~EllipseBFFPType()
{
}

int EllipseBFFPType::type() const
{
  return 1;
}

const EllipseBFFPType* EllipseBFFPType::instance()
{
  static const EllipseBFFPType t;
  return &t;
}

static const char constructhyperbolawithfocusstat[] =
  I18N_NOOP( "Construct a hyperbola with this focus" );

static const ArgsParser::spec argsspecHyperbolaBFFP[] =
{
  { PointImp::stype(), constructhyperbolawithfocusstat,
    I18N_NOOP( "Select the first focus of the new hyperbola..." ), false },
  { PointImp::stype(), constructhyperbolawithfocusstat,
    I18N_NOOP( "Select the second focus of the new hyperbola..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct a hyperbola through this point" ),
    I18N_NOOP( "Select a point for the new hyperbola to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( HyperbolaBFFPType )

HyperbolaBFFPType::HyperbolaBFFPType()
  : ConicBFFPType( "HyperbolaBFFP", argsspecHyperbolaBFFP, 3 )
{
}

HyperbolaBFFPType::~HyperbolaBFFPType()
{
}

const HyperbolaBFFPType* HyperbolaBFFPType::instance()
{
  static const HyperbolaBFFPType t;
  return &t;
}

int HyperbolaBFFPType::type() const
{
  return -1;
}

const ConicBDFPType* ConicBDFPType::instance()
{
  static const ConicBDFPType t;
  return &t;
}

static const struct ArgsParser::spec argsspecConicBDFP[] =
{
  { AbstractLineImp::stype(), I18N_NOOP( "Construct a conic with this line as directrix" ),
    I18N_NOOP( "Select the directrix of the new conic..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct a conic with this point as focus" ),
    I18N_NOOP( "Select the focus of the new conic..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct a conic through this point" ),
    I18N_NOOP( "Select a point for the new conic to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicBDFPType )

ConicBDFPType::ConicBDFPType()
  : ArgsParserObjectType( "ConicBDFP", argsspecConicBDFP, 3 )
{
}

ConicBDFPType::~ConicBDFPType()
{
}

ObjectImp* ConicBDFPType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents, 2 ) ) return new InvalidImp;

  const LineData line = static_cast<const AbstractLineImp*>( parents[0] )->data();
  const Coordinate focus =
    static_cast<const PointImp*>( parents[1] )->coordinate();

  Coordinate point;
  if ( parents.size() == 3 )
    point = static_cast<const PointImp*>( parents[2] )->coordinate();
  else
  {
    /* !!!! costruisci point come punto medio dell'altezza tra fuoco e d. */
    Coordinate ba = line.dir();
    Coordinate fa = focus - line.b;
    double balsq = ba.x*ba.x + ba.y*ba.y;
    double scal = (fa.x*ba.x + fa.y*ba.y)/balsq;
    point = 0.5*(line.a + focus + scal*ba);
  };
  return new ConicImpPolar( calcConicBDFP( line, focus, point ) );
}

static const char constructparabolathroughpointstat[] =
  I18N_NOOP( "Construct a parabola through this point" );

static const ArgsParser::spec argsspecParabolaBTP[] =
{
  { PointImp::stype(), constructparabolathroughpointstat,
    I18N_NOOP( "Select a point for the new parabola to go through..." ), true },
  { PointImp::stype(), constructparabolathroughpointstat,
    I18N_NOOP( "Select a point for the new parabola to go through..." ), true },
  { PointImp::stype(), constructparabolathroughpointstat,
    I18N_NOOP( "Select a point for the new parabola to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ParabolaBTPType )

ParabolaBTPType::ParabolaBTPType()
  : ArgsParserObjectType( "ParabolaBTP", argsspecParabolaBTP, 3 )
{
}

ParabolaBTPType::~ParabolaBTPType()
{
}

const ParabolaBTPType* ParabolaBTPType::instance()
{
  static const ParabolaBTPType t;
  return &t;
}

ObjectImp* ParabolaBTPType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents, 2 ) ) return new InvalidImp;

  std::vector<Coordinate> points;
  for ( Args::const_iterator i = parents.begin(); i != parents.end(); ++i )
    points.push_back( static_cast<const PointImp*>( *i )->coordinate() );

  ConicCartesianData d =
    calcConicThroughPoints( points, zerotilt, parabolaifzt, ysymmetry );
  if ( d.valid() )
    return new ConicImpCart( d );
  else
    return new InvalidImp;
}

static const ArgsParser::spec argsspecConicPolarPoint[] =
{
  { ConicImp::stype(), I18N_NOOP( "Construct a polar point wrt. this conic" ),
    I18N_NOOP( "Select the conic wrt. which you want to construct a polar point..." ), false },
  { AbstractLineImp::stype(), I18N_NOOP( "Construct the polar point of this line" ),
    I18N_NOOP( "Select the line of which you want to construct the polar point..." ), false }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicPolarPointType )

ConicPolarPointType::ConicPolarPointType()
  : ArgsParserObjectType( "ConicPolarPoint", argsspecConicPolarPoint, 2 )
{
}

ConicPolarPointType::~ConicPolarPointType()
{
}

const ConicPolarPointType* ConicPolarPointType::instance()
{
  static const ConicPolarPointType t;
  return &t;
}

ObjectImp* ConicPolarPointType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) ) return new InvalidImp;

  const ConicCartesianData c = static_cast<const ConicImp*>( parents[0] )->cartesianData();
  const LineData l = static_cast<const AbstractLineImp*>( parents[1] )->data();
  const Coordinate p = calcConicPolarPoint( c, l );
  if ( p.valid() ) return new PointImp( p );
  else return new InvalidImp;
}

static const ArgsParser::spec argsspecConicPolarLine[] =
{
  { ConicImp::stype(), I18N_NOOP( "Construct a polar line wrt. this conic" ),
    I18N_NOOP( "Select the conic wrt. which you want to construct a polar point..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct the polar line of this point" ),
    I18N_NOOP( "Select the line of which you want to construct the polar point..." ), false }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicPolarLineType )

ConicPolarLineType::ConicPolarLineType()
  : ArgsParserObjectType( "ConicPolarLine", argsspecConicPolarLine, 2 )
{
}

ConicPolarLineType::~ConicPolarLineType()
{
}

const ConicPolarLineType* ConicPolarLineType::instance()
{
  static const ConicPolarLineType t;
  return &t;
}

ObjectImp* ConicPolarLineType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) ) return new InvalidImp;

  const ConicCartesianData c = static_cast<const ConicImp*>( parents[0] )->cartesianData();
  const Coordinate p = static_cast<const PointImp*>( parents[1] )->coordinate();
  bool valid = true;
  const LineData l = calcConicPolarLine( c, p, valid );
  if ( valid ) return new LineImp( l );
  else return new InvalidImp;
}

static const ArgsParser::spec argsspecConicDirectrix[] =
{
  { ConicImp::stype(), I18N_NOOP( "Construct the directrix of this conic" ),
    I18N_NOOP( "Select the conic of which you want to construct the directrix..." ), false }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicDirectrixType )

ConicDirectrixType::ConicDirectrixType()
  : ArgsParserObjectType( "ConicDirectrix", argsspecConicDirectrix, 1 )
{
}

ConicDirectrixType::~ConicDirectrixType()
{
}

const ConicDirectrixType* ConicDirectrixType::instance()
{
  static const ConicDirectrixType t;
  return &t;
}

ObjectImp* ConicDirectrixType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) ) return new InvalidImp;

  const ConicPolarData data =
    static_cast<const ConicImp*>( parents[0] )->polarData();

  double ec = data.ecostheta0;
  double es = data.esintheta0;
  double eccsq = ec*ec + es*es;

  Coordinate a = data.focus1 - data.pdimen/eccsq*Coordinate(ec,es);
  Coordinate b = a + Coordinate(-es,ec);
  return new LineImp( a, b );
}

static const char hyperbolatpstatement[] = I18N_NOOP( "Construct a hyperbola through this point" );

static const ArgsParser::spec argsspecHyperbolaB4P[] =
{
  { PointImp::stype(), hyperbolatpstatement,
    I18N_NOOP( "Select a point for the new hyperbola to go through..." ), true },
  { PointImp::stype(), hyperbolatpstatement,
    I18N_NOOP( "Select a point for the new hyperbola to go through..." ), true },
  { PointImp::stype(), hyperbolatpstatement,
    I18N_NOOP( "Select a point for the new hyperbola to go through..." ), true },
  { PointImp::stype(), hyperbolatpstatement,
    I18N_NOOP( "Select a point for the new hyperbola to go through..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( EquilateralHyperbolaB4PType )

EquilateralHyperbolaB4PType::EquilateralHyperbolaB4PType()
  : ArgsParserObjectType( "EquilateralHyperbolaB4P", argsspecHyperbolaB4P, 4 )
{
}

EquilateralHyperbolaB4PType::~EquilateralHyperbolaB4PType()
{
}

const EquilateralHyperbolaB4PType* EquilateralHyperbolaB4PType::instance()
{
  static const EquilateralHyperbolaB4PType t;
  return &t;
}

ObjectImp* EquilateralHyperbolaB4PType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents, 1 ) ) return new InvalidImp;

  std::vector<Coordinate> pts;
  for ( Args::const_iterator i = parents.begin(); i != parents.end(); ++i )
    pts.push_back( static_cast<const PointImp*>( *i )->coordinate() );

  ConicCartesianData d = calcConicThroughPoints( pts, equilateral );
  if ( d.valid() )
    return new ConicImpCart( d );
  else
    return new InvalidImp;
}

static const ArgsParser::spec argsspecParabolaBDP[] =
{
  { AbstractLineImp::stype(), I18N_NOOP( "Construct a parabola with this directrix" ),
    I18N_NOOP( "Select the directrix of the new parabola..." ), false },
  { PointImp::stype(), I18N_NOOP( "Construct a parabola with this focus" ),
    I18N_NOOP( "Select the focus of the new parabola..." ), true }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ParabolaBDPType )

ParabolaBDPType::ParabolaBDPType()
  : ObjectLPType( "ParabolaBDP", argsspecParabolaBDP, 2 )
{
}

ParabolaBDPType::~ParabolaBDPType()
{
}

const ParabolaBDPType* ParabolaBDPType::instance()
{
  static const ParabolaBDPType t;
  return &t;
}

ObjectImp* ParabolaBDPType::calc( const LineData& l, const Coordinate& c ) const
{
  ConicPolarData ret;
  Coordinate ldir = l.dir();
  ldir = ldir.normalize();
  ret.focus1 = c;
  ret.ecostheta0 = - ldir.y;
  ret.esintheta0 = ldir.x;
  Coordinate fa = c - l.a;
  ret.pdimen = fa.y*ldir.x - fa.x*ldir.y;
  ConicImpPolar* r = new ConicImpPolar( ret );
  kdDebug() << k_funcinfo << r->conicTypeString() << endl;
  return r;
}

static const ArgsParser::spec argsspecConicAsymptote[] =
{
  { ConicImp::stype(), I18N_NOOP( "Construct the asymptotes of this conic" ),
    I18N_NOOP( "Select the conic of which you want to construct the asymptotes..." ), false },
  { IntImp::stype(), "param", "SHOULD NOT BE SEEN", false }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicAsymptoteType )

ConicAsymptoteType::ConicAsymptoteType()
  : ArgsParserObjectType( "ConicAsymptote", argsspecConicAsymptote, 2 )
{
}

ConicAsymptoteType::~ConicAsymptoteType()
{
}

const ConicAsymptoteType* ConicAsymptoteType::instance()
{
  static const ConicAsymptoteType t;
  return &t;
}

ObjectImp* ConicAsymptoteType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) ) return new InvalidImp;

  bool valid = true;
  const LineData ret = calcConicAsymptote(
    static_cast<const ConicImp*>( parents[0] )->cartesianData(),
    static_cast<const IntImp*>( parents[1] )->data(),
    valid );

  if ( valid )
    return new LineImp( ret );
  else
    return new InvalidImp;
}

static const char radicallinesstatement[] = I18N_NOOP( "Construct the radical lines of this conic" );

static const ArgsParser::spec argsspecConicRadical[] =
{
  { ConicImp::stype(), radicallinesstatement,
    I18N_NOOP( "Select the first of the two conics of which you want to construct the radical line..." ), false },
  { ConicImp::stype(), radicallinesstatement,
    I18N_NOOP( "Select the other of the two conic of which you want to construct the radical line..." ), false },
  { IntImp::stype(), "param", "SHOULD NOT BE SEEN", false },
  { IntImp::stype(), "param", "SHOULD NOT BE SEEN", false }
};

KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConicRadicalType )

ConicRadicalType::ConicRadicalType()
  : ArgsParserObjectType( "ConicRadical", argsspecConicRadical, 4 )
{
}

const ConicRadicalType* ConicRadicalType::instance()
{
  static const ConicRadicalType t;
  return &t;
}

ObjectImp* ConicRadicalType::calc( const Args& parents, const KigDocument& ) const
{
  if ( ! margsparser.checkArgs( parents ) ) return new InvalidImp;
  if ( parents[0]->inherits( CircleImp::stype() ) &&
       parents[1]->inherits( CircleImp::stype() ) )
  {
    if( static_cast<const IntImp*>( parents[2] )->data() != 1 )
      return new InvalidImp;
    else
    {
      const CircleImp* c1 = static_cast<const CircleImp*>( parents[0] );
      const CircleImp* c2 = static_cast<const CircleImp*>( parents[1] );
      const Coordinate a = calcCircleRadicalStartPoint(
        c1->center(), c2->center(), c1->squareRadius(), c2->squareRadius()
        );
      return new LineImp( a, calcPointOnPerpend(
          LineData( c1->center(), c2->center() ), a ) );
    };
  }
  else
  {
    bool valid = true;
    const LineData l = calcConicRadical(
      static_cast<const ConicImp*>( parents[0] )->cartesianData(),
      static_cast<const ConicImp*>( parents[1] )->cartesianData(),
      static_cast<const IntImp*>( parents[2] )->data(),
      static_cast<const IntImp*>( parents[3] )->data(), valid );
    if ( valid )
      return new LineImp( l );
    else
      return new InvalidImp;
  };
}

ConicRadicalType::~ConicRadicalType()
{
}

const ObjectImpType* ConicB5PType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ConicBAAPType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ConicBFFPType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ConicBDFPType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ParabolaBTPType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* EquilateralHyperbolaB4PType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ConicPolarPointType::resultId() const
{
  return PointImp::stype();
}

const ObjectImpType* ConicPolarLineType::resultId() const
{
  return LineImp::stype();
}

const ObjectImpType* ConicDirectrixType::resultId() const
{
  return LineImp::stype();
}

const ObjectImpType* ParabolaBDPType::resultId() const
{
  return ConicImp::stype();
}

const ObjectImpType* ConicAsymptoteType::resultId() const
{
  return LineImp::stype();
}

const ObjectImpType* ConicRadicalType::resultId() const
{
  return LineImp::stype();
}

TQStringList ConicRadicalType::specialActions() const
{
  TQStringList ret;
  ret << i18n( "Switch Radical Lines" );
  return ret;
}

void ConicRadicalType::executeAction( int i, ObjectHolder&, ObjectTypeCalcer& t,
                                      KigPart& d, KigWidget&, NormalMode& ) const
{
  assert( i == 0 );
  std::vector<ObjectCalcer*> parents = t.parents();
  assert( dynamic_cast<ObjectConstCalcer*>( parents[3] ) );
  ObjectConstCalcer* zeroindexo = static_cast<ObjectConstCalcer*>( parents[3] );
  MonitorDataObjects mon( zeroindexo );
  assert( zeroindexo->imp()->inherits( IntImp::stype() ) );
  int oldzeroindex = static_cast<const IntImp*>( zeroindexo->imp() )->data();
  int newzeroindex = oldzeroindex % 3 + 1;
  zeroindexo->setImp( new IntImp( newzeroindex ) );
  KigCommand* kc = new KigCommand( d, "Switch Conic Radical Lines" );
  mon.finish( kc );
  d.history()->addCommand( kc );
}