• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
other_imp.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "other_imp.h"
19 
20 #include <math.h>
21 
22 #include "bogus_imp.h"
23 #include "point_imp.h"
24 #include "line_imp.h"
25 #include "circle_imp.h"
26 
27 #include "../misc/screeninfo.h"
28 #include "../misc/common.h"
29 #include "../misc/kigtransform.h"
30 #include "../misc/kigpainter.h"
31 #include "../misc/goniometry.h"
32 #include "../kig/kig_view.h"
33 
34 #include <klocale.h>
35 
36 #include <cmath>
37 #include <utility>
38 using namespace std;
39 
40 const int AngleImp::radius = 30;
41 
42 AngleImp::~AngleImp()
43 {
44 }
45 
46 ObjectImp* AngleImp::transform( const Transformation& ) const
47 {
48  // TODO ?
49  return new InvalidImp;
50 }
51 
52 void AngleImp::draw( KigPainter& p ) const
53 {
54  if ( mangle == M_PI / 2 && mmarkRightAngle )
55  {
56  p.drawRightAngle( mpoint, mstartangle, AngleImp::radius );
57  }
58  else
59  {
60  p.drawAngle( mpoint, mstartangle, mangle, AngleImp::radius );
61  }
62 }
63 
64 AngleImp::AngleImp( const Coordinate& pt, double start_angle_in_radials,
65  double angle_in_radials, bool markRightAngle )
66  : mpoint( pt ), mstartangle( start_angle_in_radials ),
67  mangle( angle_in_radials ), mmarkRightAngle(markRightAngle)
68 {
69 }
70 
71 bool AngleImp::contains( const Coordinate& p, int width, const KigWidget& w ) const
72 {
73  double radius = AngleImp::radius * w.screenInfo().pixelWidth();
74 
75  if ( mangle == M_PI / 2 && mmarkRightAngle )
76  {
77  //rotate around -mstartangle
78  double fixedX = cos( mstartangle ) * ( p.x - mpoint.x ) + sin( mstartangle ) * ( p.y - mpoint.y );
79  double fixedY = -sin( mstartangle ) * ( p.x - mpoint.x ) + cos( mstartangle ) * ( p.y - mpoint.y );
80 
81  if ( fabs( fixedX - radius * sin( M_PI / 4 ) ) < w.screenInfo().normalMiss( width ) )
82  {
83  return ( fixedY <= radius * sin( M_PI / 4 ) ) && ( fixedY > 0 );
84  }
85  else if ( fabs( fixedY - radius * sin( M_PI / 4 ) ) < w.screenInfo().normalMiss( width ) )
86  {
87  return ( fixedX <= radius * sin( M_PI / 4 ) ) && ( fixedX > 0 );
88  }
89 
90  return false;
91  }
92  else
93  {
94  if ( fabs( (p-mpoint).length() - radius ) > w.screenInfo().normalMiss( width ) )
95  return false;
96 
97  Coordinate vect = p - mpoint;
98  double angle = atan2( vect.y, vect.x );
99  while ( angle < mstartangle ) angle += 2*M_PI;
100  return angle <= mstartangle + mangle;
101  }
102 }
103 
104 bool AngleImp::inRect( const Rect& r, int width, const KigWidget& w ) const
105 {
106  // TODO ?
107  return r.contains( mpoint, w.screenInfo().normalMiss( width ) );
108 }
109 
110 Coordinate AngleImp::attachPoint() const
111 {
112  return mpoint;
113 }
114 
115 int AngleImp::numberOfProperties() const
116 {
117  return Parent::numberOfProperties() + 3;
118 }
119 
120 const QByteArrayList AngleImp::propertiesInternalNames() const
121 {
122  QByteArrayList l = Parent::propertiesInternalNames();
123  l << "angle-radian";
124  l << "angle-degrees";
125  l << "angle-bisector";
126  assert( l.size() == AngleImp::numberOfProperties() );
127  return l;
128 }
129 
130 const QByteArrayList AngleImp::properties() const
131 {
132  QByteArrayList l = Parent::properties();
133  l << I18N_NOOP( "Angle in Radians" );
134  l << I18N_NOOP( "Angle in Degrees" );
135  l << I18N_NOOP( "Angle Bisector" );
136  assert( l.size() == AngleImp::numberOfProperties() );
137  return l;
138 }
139 
140 const ObjectImpType* AngleImp::impRequirementForProperty( int which ) const
141 {
142  if ( which < Parent::numberOfProperties() )
143  return Parent::impRequirementForProperty( which );
144  else return AngleImp::stype();
145 }
146 
147 const char* AngleImp::iconForProperty( int which ) const
148 {
149  int numprop = 0;
150  if ( which < Parent::numberOfProperties() )
151  return Parent::iconForProperty( which );
152  if ( which == Parent::numberOfProperties() + numprop++ )
153  return "angle_size"; // size in radians
154  else if ( which == Parent::numberOfProperties() + numprop++ )
155  return "angle_size"; // size in degrees
156  else if ( which == Parent::numberOfProperties() + numprop++ )
157  return "angle_bisector"; // angle bisector..
158  else assert( false );
159  return "";
160 }
161 
162 ObjectImp* AngleImp::property( int which, const KigDocument& w ) const
163 {
164  int numprop = 0;
165  if ( which < Parent::numberOfProperties() )
166  return Parent::property( which, w );
167  if ( which == Parent::numberOfProperties() + numprop++ )
168  return new DoubleImp( size() );
169  else if ( which == Parent::numberOfProperties() + numprop++ )
170  return new DoubleImp( Goniometry::convert( size(), Goniometry::Rad, Goniometry::Deg ) );
171  else if ( which == Parent::numberOfProperties() + numprop++ )
172  {
173  const double angle = mstartangle + mangle / 2;
174  Coordinate p2 = mpoint + Coordinate( cos( angle ), sin( angle ) ) * 10;
175  return new RayImp( mpoint, p2 );
176  }
177  else assert( false );
178  return new InvalidImp;
179 }
180 
181 double AngleImp::size() const
182 {
183  return mangle;
184 }
185 
186 ObjectImp* AngleImp::copy() const
187 {
188  return new AngleImp( mpoint, mstartangle, mangle, mmarkRightAngle );
189 }
190 
191 VectorImp::VectorImp( const Coordinate& a, const Coordinate& b )
192  : mdata( a, b )
193 {
194 }
195 
196 VectorImp::~VectorImp()
197 {
198 }
199 
200 ObjectImp* VectorImp::transform( const Transformation& t ) const
201 {
202  Coordinate ta = t.apply( mdata.a );
203  Coordinate tb = t.apply( mdata.b );
204  if ( ta.valid() && tb.valid() ) return new VectorImp( ta, tb );
205  else return new InvalidImp;
206 }
207 
208 void VectorImp::draw( KigPainter& p ) const
209 {
210  p.drawVector( mdata.a, mdata.b );
211 }
212 
213 bool VectorImp::contains( const Coordinate& o, int width, const KigWidget& w ) const
214 {
215  return internalContainsPoint( o, w.screenInfo().normalMiss( width ) );
216 }
217 
218 bool VectorImp::inRect( const Rect& r, int width, const KigWidget& w ) const
219 {
220  return lineInRect( r, mdata.a, mdata.b, width, this, w );
221 }
222 
223 int VectorImp::numberOfProperties() const
224 {
225  return Parent::numberOfProperties() + 5;
226 }
227 
228 const QByteArrayList VectorImp::propertiesInternalNames() const
229 {
230  QByteArrayList ret = Parent::propertiesInternalNames();
231  ret << "length";
232  ret << "vect-mid-point";
233  ret << "length-x";
234  ret << "length-y";
235  ret << "vector-opposite";
236  assert( ret.size() == VectorImp::numberOfProperties() );
237  return ret;
238 }
239 
240 const QByteArrayList VectorImp::properties() const
241 {
242  QByteArrayList ret = Parent::properties();
243  ret << I18N_NOOP( "Length" );
244  ret << I18N_NOOP( "Midpoint" );
245  ret << I18N_NOOP( "X length" );
246  ret << I18N_NOOP( "Y length" );
247  ret << I18N_NOOP( "Opposite Vector" );
248  assert( ret.size() == VectorImp::numberOfProperties() );
249  return ret;
250 }
251 
252 const ObjectImpType* VectorImp::impRequirementForProperty( int which ) const
253 {
254  if ( which < Parent::numberOfProperties() )
255  return Parent::impRequirementForProperty( which );
256  else return VectorImp::stype();
257 }
258 
259 const char* VectorImp::iconForProperty( int which ) const
260 {
261  if ( which < Parent::numberOfProperties() )
262  return Parent::iconForProperty( which );
263  else if ( which == Parent::numberOfProperties() )
264  return "distance"; // length
265  else if ( which == Parent::numberOfProperties() + 1 )
266  return "bisection"; // mid point
267  else if ( which == Parent::numberOfProperties() + 2 )
268  return "distance"; // length-x
269  else if ( which == Parent::numberOfProperties() + 3 )
270  return "distance"; // length-y
271  else if ( which == Parent::numberOfProperties() + 4 )
272  return "opposite-vector"; // opposite vector
273  else assert( false );
274  return "";
275 }
276 
277 ObjectImp* VectorImp::property( int which, const KigDocument& w ) const
278 {
279  if ( which < Parent::numberOfProperties() )
280  return Parent::property( which, w );
281  else if ( which == Parent::numberOfProperties() )
282  return new DoubleImp( length() );
283  else if ( which == Parent::numberOfProperties() + 1 )
284  return new PointImp( ( mdata.a + mdata.b ) / 2 );
285  else if ( which == Parent::numberOfProperties() + 2 )
286  return new DoubleImp( fabs( mdata.a.x - mdata.b.x ) );
287  else if ( which == Parent::numberOfProperties() + 3 )
288  return new DoubleImp( fabs( mdata.a.y - mdata.b.y ) );
289  else if ( which == Parent::numberOfProperties() + 4 ) // opposite
290  return new VectorImp( mdata.a, 2*mdata.a-mdata.b );
291  else assert( false );
292  return new InvalidImp;
293 }
294 
295 VectorImp* VectorImp::copy() const
296 {
297  return new VectorImp( mdata.a, mdata.b );
298 }
299 
300 const Coordinate VectorImp::dir() const
301 {
302  return mdata.dir();
303 }
304 
305 void AngleImp::visit( ObjectImpVisitor* vtor ) const
306 {
307  vtor->visit( this );
308 }
309 
310 void VectorImp::visit( ObjectImpVisitor* vtor ) const
311 {
312  vtor->visit( this );
313 }
314 
315 double VectorImp::length() const
316 {
317  return ( mdata.a - mdata.b ).length();
318 }
319 
320 ArcImp::ArcImp( const Coordinate& center, const double radius,
321  const double startangle, const double angle )
322  : CurveImp(), mcenter( center ), mradius( radius ),
323  msa( startangle ), ma( angle )
324 {
325  if ( ma < 0 )
326  {
327  // we want a positive angle..
328  msa = msa + ma;
329  ma = -ma;
330  };
331 }
332 
333 ArcImp::~ArcImp()
334 {
335 }
336 
337 ArcImp* ArcImp::copy() const
338 {
339  return new ArcImp( mcenter, mradius, msa, ma );
340 }
341 
342 ObjectImp* ArcImp::transform( const Transformation& t ) const
343 {
344  //
345  // if the transformation is nonhomothetic, the result is a conic arc,
346  // not a circular arc
347  //
348  if ( ! t.isHomothetic() )
349  {
350  //CircleImp support = CircleImp( mcenter, mradius );
351  ConicCartesianData data = CircleImp( mcenter, mradius ).cartesianData();
352  //return new InvalidImp();
353  ConicArcImp conicarc = ConicArcImp( data, msa, ma );
354  return conicarc.transform ( t );
355  }
356 
357  Coordinate nc = t.apply( mcenter );
358  double nr = t.apply( mradius );
359  // transform msa...
360  double nmsa = msa;
361  if ( t.getAffineDeterminant() > 0 )
362  {
363  nmsa = msa - t.getRotationAngle();
364  } else
365  {
366  Coordinate ar = t.apply2by2only( Coordinate( cos(msa), sin(msa) ) );
367  nmsa = atan2( ar.y, ar.x );
368  nmsa -= ma;
369  }
370  while ( nmsa < -M_PI ) nmsa += 2*M_PI;
371  while ( nmsa > M_PI ) nmsa -= 2*M_PI;
372  if ( nc.valid() ) return new ArcImp( nc, nr, nmsa, ma );
373  else return new InvalidImp;
374 }
375 
376 void ArcImp::draw( KigPainter& p ) const
377 {
378  p.drawArc( mcenter, mradius, msa, ma );
379 }
380 
381 bool ArcImp::contains( const Coordinate& p, int width, const KigWidget& w ) const
382 {
383  return internalContainsPoint( p, w.screenInfo().normalMiss( width ) );
384 }
385 
386 bool ArcImp::inRect( const Rect&, int, const KigWidget& ) const
387 {
388  // TODO
389  return false;
390 }
391 
392 bool ArcImp::valid() const
393 {
394  return true;
395 }
396 
397 int ArcImp::numberOfProperties() const
398 {
399  return Parent::numberOfProperties() + 10;
400 }
401 
402 const QByteArrayList ArcImp::properties() const
403 {
404  QByteArrayList ret = Parent::properties();
405  ret << I18N_NOOP( "Center" );
406  ret << I18N_NOOP( "Radius" );
407  ret << I18N_NOOP( "Angle" );
408  ret << I18N_NOOP( "Angle in Degrees" );
409  ret << I18N_NOOP( "Angle in Radians" );
410  ret << I18N_NOOP( "Sector Surface" );
411  ret << I18N_NOOP( "Arc Length" );
412  ret << I18N_NOOP( "Support Circle" );
413  ret << I18N_NOOP( "First End Point" );
414  ret << I18N_NOOP( "Second End Point" );
415  assert( ret.size() == ArcImp::numberOfProperties() );
416  return ret;
417 }
418 
419 const QByteArrayList ArcImp::propertiesInternalNames() const
420 {
421  QByteArrayList ret = Parent::propertiesInternalNames();
422  ret << "center";
423  ret << "radius";
424  ret << "angle";
425  ret << "angle-degrees";
426  ret << "angle-radians";
427  ret << "sector-surface";
428  ret << "arc-length";
429  ret << "support";
430  ret << "end-point-A";
431  ret << "end-point-B";
432  return ret;
433 }
434 
435 const char* ArcImp::iconForProperty( int which ) const
436 {
437  int numprop = 0;
438  if ( which < Parent::numberOfProperties() )
439  return Parent::iconForProperty( which );
440  else if ( which == Parent::numberOfProperties() + numprop++ )
441  return "arc_center"; // center
442  else if ( which == Parent::numberOfProperties() + numprop++ )
443  return "";
444  else if ( which == Parent::numberOfProperties() + numprop++ )
445  return "angle";
446  else if ( which == Parent::numberOfProperties() + numprop++ )
447  return "angle_size";
448  else if ( which == Parent::numberOfProperties() + numprop++ )
449  return "angle_size";
450  else if ( which == Parent::numberOfProperties() + numprop++ )
451  return "";
452  else if ( which == Parent::numberOfProperties() + numprop++ )
453  return "";
454  else if ( which == Parent::numberOfProperties() + numprop++ )
455  return "";
456  else if ( which == Parent::numberOfProperties() + numprop++ )
457  return "";
458  else if ( which == Parent::numberOfProperties() + numprop++ )
459  return "";
460  else assert( false );
461  return "";
462 }
463 
464 ObjectImp* ArcImp::property( int which, const KigDocument& d ) const
465 {
466  int numprop = 0;
467  if ( which < Parent::numberOfProperties() )
468  return Parent::property( which, d );
469  else if ( which == Parent::numberOfProperties() + numprop++ )
470  return new PointImp( mcenter );
471  else if ( which == Parent::numberOfProperties() + numprop++ )
472  return new DoubleImp( mradius );
473  else if ( which == Parent::numberOfProperties() + numprop++ )
474  return new AngleImp( mcenter, msa, ma, false );
475  else if ( which == Parent::numberOfProperties() + numprop++ )
476  return new IntImp( static_cast<int>( Goniometry::convert( ma, Goniometry::Rad, Goniometry::Deg ) ) );
477  else if ( which == Parent::numberOfProperties() + numprop++ )
478  return new DoubleImp( ma );
479  else if ( which == Parent::numberOfProperties() + numprop++ )
480  return new DoubleImp( sectorSurface() );
481  else if ( which == Parent::numberOfProperties() + numprop++ )
482  return new DoubleImp( mradius * ma );
483  else if ( which == Parent::numberOfProperties() + numprop++ )
484  return new CircleImp( mcenter, mradius );
485  else if ( which == Parent::numberOfProperties() + numprop++ )
486  return new PointImp( firstEndPoint() );
487  else if ( which == Parent::numberOfProperties() + numprop++ )
488  return new PointImp( secondEndPoint() );
489  else assert( false );
490  return new InvalidImp;
491 }
492 
493 double ArcImp::sectorSurface() const
494 {
495  return mradius * mradius * ma / 2;
496 }
497 
498 const ObjectImpType* ArcImp::impRequirementForProperty( int which ) const
499 {
500  if ( which < Parent::numberOfProperties() )
501  return Parent::impRequirementForProperty( which );
502  else
503  return ArcImp::stype();
504 }
505 
506 void ArcImp::visit( ObjectImpVisitor* vtor ) const
507 {
508  vtor->visit( this );
509 }
510 
511 double ArcImp::getParam( const Coordinate& c, const KigDocument& ) const
512 {
513  Coordinate d = (c - mcenter).normalize();
514  double angle = atan2( d.y, d.x );
515  angle -= msa;
516 // mp: problems with large arcs
517  while ( angle > ma/2 + M_PI ) angle -= 2*M_PI;
518  while ( angle < ma/2 - M_PI ) angle += 2*M_PI;
519 //
520  angle = max( 0., min( angle, ma ) );
521  angle /= ma;
522  return angle;
523 }
524 
525 const Coordinate ArcImp::getPoint( double p, const KigDocument& ) const
526 {
527  double angle = msa + p * ma;
528  Coordinate d = Coordinate( cos( angle ), sin( angle ) ) * mradius;
529  return mcenter + d;
530 }
531 
532 const Coordinate ArcImp::center() const
533 {
534  return mcenter;
535 }
536 
537 double ArcImp::radius() const
538 {
539  return mradius;
540 }
541 
542 double ArcImp::startAngle() const
543 {
544  return msa;
545 }
546 
547 double ArcImp::angle() const
548 {
549  return ma;
550 }
551 
552 Coordinate ArcImp::firstEndPoint() const
553 {
554  double angle = msa;
555  return mcenter + Coordinate( cos( angle ), sin( angle ) ) * mradius;
556 }
557 
558 Coordinate ArcImp::secondEndPoint() const
559 {
560  double angle = msa + ma;
561  return mcenter + Coordinate( cos( angle ), sin( angle ) ) * mradius;
562 }
563 
564 const Coordinate VectorImp::a() const
565 {
566  return mdata.a;
567 }
568 
569 const Coordinate VectorImp::b() const
570 {
571  return mdata.b;
572 }
573 
574 bool ArcImp::equals( const ObjectImp& rhs ) const
575 {
576  return rhs.inherits( ArcImp::stype() ) &&
577  static_cast<const ArcImp&>( rhs ).radius() == radius() &&
578  static_cast<const ArcImp&>( rhs ).startAngle() == startAngle() &&
579  static_cast<const ArcImp&>( rhs ).angle() == angle();
580 }
581 
582 bool AngleImp::equals( const ObjectImp& rhs ) const
583 {
584  return rhs.inherits( AngleImp::stype() ) &&
585  static_cast<const AngleImp&>( rhs ).point() == point() &&
586  static_cast<const AngleImp&>( rhs ).startAngle() == startAngle() &&
587  static_cast<const AngleImp&>( rhs ).angle() == angle();
588 }
589 
590 bool VectorImp::equals( const ObjectImp& rhs ) const
591 {
592  return rhs.inherits( VectorImp::stype() ) &&
593  static_cast<const VectorImp&>( rhs ).a() == a() &&
594  static_cast<const VectorImp&>( rhs ).b() == b();
595 }
596 
597 const ObjectImpType* AngleImp::stype()
598 {
599  static const ObjectImpType t(
600  Parent::stype(), "angle",
601  I18N_NOOP( "angle" ),
602  I18N_NOOP( "Select this angle" ),
603  I18N_NOOP( "Select angle %1" ),
604  I18N_NOOP( "Remove an Angle" ),
605  I18N_NOOP( "Add an Angle" ),
606  I18N_NOOP( "Move an Angle" ),
607  I18N_NOOP( "Attach to this angle" ),
608  I18N_NOOP( "Show an Angle" ),
609  I18N_NOOP( "Hide an Angle" )
610  );
611  return &t;
612 }
613 const ObjectImpType* VectorImp::stype()
614 {
615  static const ObjectImpType t(
616  Parent::stype(), "vector",
617  I18N_NOOP( "vector" ),
618  I18N_NOOP( "Select this vector" ),
619  I18N_NOOP( "Select vector %1" ),
620  I18N_NOOP( "Remove a Vector" ),
621  I18N_NOOP( "Add a Vector" ),
622  I18N_NOOP( "Move a Vector" ),
623  I18N_NOOP( "Attach to this vector" ),
624  I18N_NOOP( "Show a Vector" ),
625  I18N_NOOP( "Hide a Vector" )
626  );
627  return &t;
628 }
629 const ObjectImpType* ArcImp::stype()
630 {
631  static const ObjectImpType t(
632  Parent::stype(), "arc",
633  I18N_NOOP( "arc" ),
634  I18N_NOOP( "Select this arc" ),
635  I18N_NOOP( "Select arc %1" ),
636  I18N_NOOP( "Remove an Arc" ),
637  I18N_NOOP( "Add an Arc" ),
638  I18N_NOOP( "Move an Arc" ),
639  I18N_NOOP( "Attach to this arc" ),
640  I18N_NOOP( "Show an Arc" ),
641  I18N_NOOP( "Hide an Arc" )
642  );
643  return &t;
644 }
645 
646 const ObjectImpType* AngleImp::type() const
647 {
648  return AngleImp::stype();
649 }
650 
651 const ObjectImpType* VectorImp::type() const
652 {
653  return VectorImp::stype();
654 }
655 
656 const ObjectImpType* ArcImp::type() const
657 {
658  return ArcImp::stype();
659 }
660 
661 bool ArcImp::containsPoint( const Coordinate& p, const KigDocument& ) const
662 {
663  return internalContainsPoint( p, test_threshold );
664 }
665 
666 bool ArcImp::internalContainsPoint( const Coordinate& p, double threshold ) const
667 {
668  return isOnArc( p, mcenter, mradius, msa, ma, threshold );
669 }
670 
671 bool AngleImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
672 {
673  if ( which < Parent::numberOfProperties() )
674  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
675  return false;
676 }
677 
678 bool VectorImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
679 {
680  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
681 }
682 
683 bool ArcImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
684 {
685  int pnum = 0;
686 
687  if ( which < Parent::numberOfProperties() )
688  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
689  else if ( which == Parent::numberOfProperties() + pnum++ )
690  return false; // center
691  else if ( which == Parent::numberOfProperties() + pnum++ )
692  return false; // radius
693  else if ( which == Parent::numberOfProperties() + pnum++ )
694  return false; // angle
695  else if ( which == Parent::numberOfProperties() + pnum++ )
696  return false; // angle in degrees
697  else if ( which == Parent::numberOfProperties() + pnum++ )
698  return false; // angle in radians
699  else if ( which == Parent::numberOfProperties() + pnum++ )
700  return false; // sector surface
701  else if ( which == Parent::numberOfProperties() + pnum++ )
702  return false; // arc length
703  else if ( which == Parent::numberOfProperties() + pnum++ )
704  return false; // support
705  else if ( which == Parent::numberOfProperties() + pnum++ )
706  return true; // first end-point
707  else if ( which == Parent::numberOfProperties() + pnum++ )
708  return true; // second end-point
709  else return false;
710  return false;
711 }
712 
713 Rect AngleImp::surroundingRect() const
714 {
715  return Rect( mpoint, 0, 0 );
716 }
717 
718 Rect VectorImp::surroundingRect() const
719 {
720  return Rect( mdata.a, mdata.b );
721 }
722 
723 Rect ArcImp::surroundingRect() const
724 {
725  // the returned rect should contain the center point(?), the two end
726  // points, and all extreme x and y positions in between.
727  //Rect ret( mcenter, 0, 0 );
728  double a = msa;
729  //ret.setContains( mcenter + mradius*Coordinate( cos( a ), sin( a ) ) );
730  Rect ret ( mcenter + mradius*Coordinate( cos( a ), sin( a ) ), 0, 0 );
731  a = msa + ma;
732  ret.setContains( mcenter + mradius*Coordinate( cos( a ), sin( a ) ) );
733  for ( a = -2*M_PI; a <= 2*M_PI; a+=M_PI/2 )
734  {
735  Coordinate d = mcenter + mradius*Coordinate( cos( a ), sin( a ) );
736  if ( msa <= a && a <= msa + ma )
737  ret.setContains( d );
738  }
739  return ret;
740 }
741 
742 const Coordinate VectorImp::getPoint( double param, const KigDocument& ) const
743 {
744  return mdata.a + mdata.dir() * param;
745 }
746 
747 double VectorImp::getParam( const Coordinate& p, const KigDocument& ) const
748 {
749  Coordinate pt = calcPointOnPerpend( mdata, p );
750  pt = calcIntersectionPoint( mdata, LineData( p, pt ) );
751  // if pt is over the end of the vector we set it to one of the end
752  // points of the vector...
753  if ( ( pt - mdata.a ).length() > dir().length() )
754  pt = mdata.b;
755  else if ( ( pt - mdata.b ).length() > dir().length() )
756  pt = mdata.a;
757  if ( mdata.b == mdata.a ) return 0;
758  return ( ( pt - mdata.a ).length() ) / ( dir().length() );
759 }
760 
761 bool VectorImp::containsPoint( const Coordinate& p, const KigDocument& ) const
762 {
763  return internalContainsPoint( p, test_threshold );
764 }
765 
766 bool VectorImp::internalContainsPoint( const Coordinate& p, double threshold ) const
767 {
768  return isOnSegment( p, mdata.a, mdata.b, threshold );
769 }
770 
771 LineData VectorImp::data() const
772 {
773  return mdata;
774 }
ArcImp::~ArcImp
~ArcImp()
Definition: other_imp.cc:333
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
ObjectImp::inherits
bool inherits(const ObjectImpType *t) const
Returns true if this ObjectImp inherits the ObjectImp type represented by t.
Definition: object_imp.cc:279
AngleImp::AngleImp
AngleImp(const Coordinate &pt, double start_angle_in_radials, double angle_in_radials, bool markRightAngle)
Construct an Angle with a given center, start angle and dimension (both in radians).
Definition: other_imp.cc:64
VectorImp::data
LineData data() const
Get the LineData for this vector.
Definition: other_imp.cc:771
point_imp.h
ScreenInfo::normalMiss
double normalMiss(int width) const
Definition: screeninfo.cc:88
AngleImp::~AngleImp
~AngleImp()
Definition: other_imp.cc:42
LineData
Simple class representing a line.
Definition: misc/common.h:49
ArcImp::sectorSurface
double sectorSurface() const
Return the size of the sector surface of this arc.
Definition: other_imp.cc:493
LineData::dir
const Coordinate dir() const
The direction of the line.
Definition: misc/common.h:72
ArcImp::numberOfProperties
int numberOfProperties() const
Definition: other_imp.cc:397
AngleImp::point
const Coordinate point() const
Return the center of this angle.
Definition: other_imp.h:79
LineData::b
Coordinate b
Another point on the line.
Definition: misc/common.h:68
Goniometry::Deg
Definition: goniometry.h:31
ObjectImpVisitor::visit
void visit(const ObjectImp *imp)
Definition: object_imp.cc:81
CircleImp
An ObjectImp representing a circle.
Definition: circle_imp.h:27
ObjectImp::impRequirementForProperty
virtual const ObjectImpType * impRequirementForProperty(int which) const
Definition: object_imp.cc:76
ObjectImp::property
virtual ObjectImp * property(int which, const KigDocument &d) const
Definition: object_imp.cc:70
RayImp
An ObjectImp representing a ray.
Definition: line_imp.h:136
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
VectorImp::internalContainsPoint
bool internalContainsPoint(const Coordinate &p, double threshold) const
Definition: other_imp.cc:766
ConicCartesianData
Cartesian Conic Data.
Definition: conic-common.h:37
VectorImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: other_imp.cc:252
ArcImp::firstEndPoint
Coordinate firstEndPoint() const
Return the start point of this arc.
Definition: other_imp.cc:552
VectorImp::VectorImp
VectorImp(const Coordinate &a, const Coordinate &b)
Construct a Vector with a given start point and end point.
Definition: other_imp.cc:191
VectorImp::getParam
double getParam(const Coordinate &, const KigDocument &) const
Definition: other_imp.cc:747
VectorImp::dir
const Coordinate dir() const
Return the direction of this vector.
Definition: other_imp.cc:300
AngleImp::equals
bool equals(const ObjectImp &rhs) const
Returns true if this ObjectImp is equal to rhs.
Definition: other_imp.cc:582
VectorImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the VectorImp type.
Definition: other_imp.cc:613
circle_imp.h
KigPainter::drawVector
void drawVector(const Coordinate &a, const Coordinate &b)
draw a vector ( with an arrow etc.
Definition: kigpainter.cpp:692
AngleImp::transform
ObjectImp * transform(const Transformation &) const
Return this ObjectImp, transformed by the transformation t.
Definition: other_imp.cc:46
VectorImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: other_imp.cc:651
ConicArcImp
A conic arc, which is given by the cartesian equation and two angles.
Definition: conic_imp.h:172
VectorImp::length
double length() const
Return the length of this vector.
Definition: other_imp.cc:315
ObjectImp::propertiesInternalNames
virtual const QByteArrayList propertiesInternalNames() const
Definition: object_imp.cc:63
ArcImp::valid
bool valid() const
Definition: other_imp.cc:392
ObjectImp::stype
static const ObjectImpType * stype()
The ObjectImpType representing the base ObjectImp class.
Definition: object_imp.cc:284
calcPointOnPerpend
Coordinate calcPointOnPerpend(const LineData &l, const Coordinate &t)
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: common.cpp:37
IntImp
This ObjectImp is a BogusImp containing only an int value.
Definition: bogus_imp.h:128
VectorImp::draw
void draw(KigPainter &p) const
Definition: other_imp.cc:208
ArcImp::radius
double radius() const
Return the radius of this arc.
Definition: other_imp.cc:537
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
AngleImp::inRect
bool inRect(const Rect &r, int width, const KigWidget &) const
Definition: other_imp.cc:104
VectorImp::surroundingRect
Rect surroundingRect() const
Definition: other_imp.cc:718
Coordinate::length
double length() const
Length.
Definition: coordinate.cpp:144
Transformation::isHomothetic
bool isHomothetic() const
Returns whether this is a homothetic (affine) transformation.
Definition: kigtransform.cpp:681
VectorImp
An ObjectImp representing a vector.
Definition: other_imp.h:99
Transformation::getRotationAngle
double getRotationAngle() const
Definition: kigtransform.cpp:718
AngleImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: other_imp.cc:120
KigWidget::screenInfo
const ScreenInfo & screenInfo() const
the part of the document we're currently showing i.e.
Definition: kig_view.cpp:272
VectorImp::iconForProperty
const char * iconForProperty(int which) const
Definition: other_imp.cc:259
ArcImp::contains
bool contains(const Coordinate &p, int width, const KigWidget &w) const
Definition: other_imp.cc:381
isOnSegment
bool isOnSegment(const Coordinate &o, const Coordinate &a, const Coordinate &b, const double fault)
is o on the segment defined by point a and point b ? this calls isOnLine(), but also checks if o is "...
Definition: common.cpp:212
VectorImp::getPoint
const Coordinate getPoint(double param, const KigDocument &) const
Definition: other_imp.cc:742
Transformation::apply2by2only
const Coordinate apply2by2only(const Coordinate &c) const
Definition: kigtransform.cpp:723
test_threshold
const double test_threshold
Definition: common.cpp:510
ObjectImp::iconForProperty
virtual const char * iconForProperty(int which) const
Definition: object_imp.cc:187
ArcImp::iconForProperty
const char * iconForProperty(int which) const
Definition: other_imp.cc:435
Rect::contains
bool contains(const Coordinate &p) const
Definition: rect.cc:222
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
ArcImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: other_imp.cc:419
ArcImp::angle
double angle() const
Return the dimension in radians of this arc.
Definition: other_imp.cc:547
bogus_imp.h
CircleImp::cartesianData
const ConicCartesianData cartesianData() const
Return the cartesian representation of this conic.
Definition: circle_imp.cc:297
VectorImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: other_imp.cc:277
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Transformation::getAffineDeterminant
double getAffineDeterminant() const
Definition: kigtransform.cpp:711
Transformation
Class representing a transformation.
Definition: kigtransform.h:37
KigPainter::drawArc
void drawArc(const Coordinate &center, double radius, double startangle, double angle)
draw the arc ( a part of a circle ), of the circle with center center, radius radius, with size angle, starting at the angle startAngle.
Definition: kigpainter.cpp:957
ArcImp::inRect
bool inRect(const Rect &r, int width, const KigWidget &si) const
Definition: other_imp.cc:386
ArcImp::transform
ObjectImp * transform(const Transformation &t) const
Return this ObjectImp, transformed by the transformation t.
Definition: other_imp.cc:342
ArcImp::secondEndPoint
Coordinate secondEndPoint() const
Return the end point of this arc.
Definition: other_imp.cc:558
AngleImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: other_imp.cc:646
AngleImp::angle
double angle() const
Return the dimension in radians of this angle.
Definition: other_imp.h:87
LineData::a
Coordinate a
One point on the line.
Definition: misc/common.h:64
VectorImp::visit
void visit(ObjectImpVisitor *vtor) const
Definition: other_imp.cc:310
ArcImp::getPoint
const Coordinate getPoint(double p, const KigDocument &d) const
Definition: other_imp.cc:525
ConicArcImp::transform
ObjectImp * transform(const Transformation &t) const
Return this ObjectImp, transformed by the transformation t.
Definition: conic_imp.cc:482
AngleImp::surroundingRect
Rect surroundingRect() const
Definition: other_imp.cc:713
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
ArcImp::equals
bool equals(const ObjectImp &rhs) const
Returns true if this ObjectImp is equal to rhs.
Definition: other_imp.cc:574
AngleImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: other_imp.cc:162
ObjectImp::isPropertyDefinedOnOrThroughThisImp
virtual bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: object_imp.cc:326
ArcImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the ArcImp type.
Definition: other_imp.cc:629
Rect::setContains
void setContains(Coordinate p)
this makes sure p is in the rect, extending it if necessary...
Definition: rect.cc:240
Goniometry::convert
static double convert(const double angle, const Goniometry::System from, const Goniometry::System to)
The most useful method of this class: convert the specified angle from the system from to the system ...
Definition: goniometry.cc:87
calcIntersectionPoint
Coordinate calcIntersectionPoint(const LineData &l1, const LineData &l2)
this calcs the point where the lines l and m intersect...
Definition: common.cpp:57
ArcImp::center
const Coordinate center() const
Return the center of this arc.
Definition: other_imp.cc:532
ArcImp::startAngle
double startAngle() const
Return the start angle in radians of this arc.
Definition: other_imp.cc:542
AngleImp::numberOfProperties
int numberOfProperties() const
Definition: other_imp.cc:115
AngleImp::properties
const QByteArrayList properties() const
Definition: other_imp.cc:130
VectorImp::a
const Coordinate a() const
Return the start point of this vector.
Definition: other_imp.cc:564
ArcImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: other_imp.cc:683
AngleImp::startAngle
double startAngle() const
Return the start angle in radians of this angle.
Definition: other_imp.h:83
lineInRect
bool lineInRect(const Rect &r, const Coordinate &a, const Coordinate &b, const int width, const ObjectImp *imp, const KigWidget &w)
Is the line, segment, ray or vector inside r ? We need the imp to distinguish between rays...
Definition: common.cpp:401
Transformation::apply
const Coordinate apply(const double x0, const double x1, const double x2) const
Apply this Tranformation.
Definition: kigtransform.cpp:611
ArcImp::getParam
double getParam(const Coordinate &c, const KigDocument &d) const
Definition: other_imp.cc:511
Goniometry::Rad
Definition: goniometry.h:31
VectorImp::numberOfProperties
int numberOfProperties() const
Definition: other_imp.cc:223
ArcImp::internalContainsPoint
bool internalContainsPoint(const Coordinate &p, double threshold) const
Definition: other_imp.cc:666
AngleImp::attachPoint
Coordinate attachPoint() const
Returns a reference point where to attach labels; when this returns an invalidCoord then the attachme...
Definition: other_imp.cc:110
VectorImp::inRect
bool inRect(const Rect &r, int width, const KigWidget &) const
Definition: other_imp.cc:218
VectorImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: other_imp.cc:228
AngleImp::iconForProperty
const char * iconForProperty(int which) const
Definition: other_imp.cc:147
VectorImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: other_imp.cc:678
ArcImp::copy
ArcImp * copy() const
Returns a copy of this ObjectImp.
Definition: other_imp.cc:337
line_imp.h
AngleImp::copy
ObjectImp * copy() const
Returns a copy of this ObjectImp.
Definition: other_imp.cc:186
VectorImp::contains
bool contains(const Coordinate &p, int width, const KigWidget &) const
Definition: other_imp.cc:213
CurveImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CurveImp type.
Definition: curve_imp.cc:27
AngleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AngleImp type.
Definition: other_imp.cc:597
DoubleImp
This ObjectImp is a BogusImp containing only a double value.
Definition: bogus_imp.h:89
ArcImp::draw
void draw(KigPainter &p) const
Definition: other_imp.cc:376
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
isOnArc
bool isOnArc(const Coordinate &o, const Coordinate &c, const double r, const double sa, const double a, const double fault)
Definition: common.cpp:238
ArcImp::property
ObjectImp * property(int which, const KigDocument &d) const
Definition: other_imp.cc:464
ArcImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: other_imp.cc:498
ArcImp
An ObjectImp representing an arc.
Definition: other_imp.h:169
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
ArcImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: other_imp.cc:656
ArcImp::containsPoint
bool containsPoint(const Coordinate &p, const KigDocument &doc) const
Return whether this Curve contains the given point.
Definition: other_imp.cc:661
ArcImp::surroundingRect
Rect surroundingRect() const
Definition: other_imp.cc:723
ScreenInfo::pixelWidth
double pixelWidth() const
Definition: screeninfo.cc:61
AngleImp::draw
void draw(KigPainter &p) const
Definition: other_imp.cc:52
QByteArrayList
QList< QByteArray > QByteArrayList
Definition: objects/common.h:50
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
AngleImp::contains
bool contains(const Coordinate &p, int width, const KigWidget &) const
Definition: other_imp.cc:71
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
VectorImp::transform
ObjectImp * transform(const Transformation &) const
Return this ObjectImp, transformed by the transformation t.
Definition: other_imp.cc:200
VectorImp::~VectorImp
~VectorImp()
Definition: other_imp.cc:196
VectorImp::b
const Coordinate b() const
Return the end point of this vector.
Definition: other_imp.cc:569
AngleImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: other_imp.cc:671
KigPainter::drawAngle
void drawAngle(const Coordinate &point, double startangle, double angle, int radius)
draw the angle with center point, with size angle, starting at the angle startAngle.
Definition: kigpainter.cpp:631
KigPainter::drawRightAngle
void drawRightAngle(const Coordinate &point, double startangle, int diagonal)
draw the angle with center point, with size angle, starting at the angle startAngle.
Definition: kigpainter.cpp:664
VectorImp::equals
bool equals(const ObjectImp &rhs) const
Returns true if this ObjectImp is equal to rhs.
Definition: other_imp.cc:590
AngleImp::size
double size() const
Return the size in radians of this angle.
Definition: other_imp.cc:181
VectorImp::containsPoint
bool containsPoint(const Coordinate &p, const KigDocument &doc) const
Return whether this Curve contains the given point.
Definition: other_imp.cc:761
ObjectImp::numberOfProperties
virtual int numberOfProperties() const
Definition: object_imp.cc:58
ArcImp::visit
void visit(ObjectImpVisitor *vtor) const
Definition: other_imp.cc:506
AngleImp::visit
void visit(ObjectImpVisitor *vtor) const
Definition: other_imp.cc:305
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
ObjectImpVisitor
Definition: object_imp.h:56
ArcImp::properties
const QByteArrayList properties() const
Definition: other_imp.cc:402
ObjectImp::properties
virtual const QByteArrayList properties() const
Definition: object_imp.cc:51
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
VectorImp::copy
VectorImp * copy() const
Returns a copy of this ObjectImp.
Definition: other_imp.cc:295
other_imp.h
AngleImp
An ObjectImp representing an angle.
Definition: other_imp.h:28
ArcImp::ArcImp
ArcImp(const Coordinate &center, const double radius, const double startangle, const double angle)
Construct an Arc with a given center, radius, start angle and dimension (both in radians).
Definition: other_imp.cc:320
CurveImp
This class represents a curve: something which is composed of points, like a line, a circle, a locus.
Definition: curve_imp.h:27
AngleImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: other_imp.cc:140
VectorImp::properties
const QByteArrayList properties() const
Definition: other_imp.cc:240
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal