1 // Copyright (C) 2004 Dominique Devriese <devriese@kde.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
18 #include "tests_type.h"
21 #include "polygon_imp.h"
22 #include "point_imp.h"
23 #include "bogus_imp.h"
24 #include "other_imp.h"
28 static const ArgsParser::spec argsspecAreParallel
[] =
30 { AbstractLineImp::stype(), I18N_NOOP( "Is this line parallel?" ),
31 I18N_NOOP( "Select the first of the two possibly parallel lines..." ), false },
32 { AbstractLineImp::stype(), I18N_NOOP( "Parallel to this line?" ),
33 I18N_NOOP( "Select the other of the two possibly parallel lines..." ), false }
36 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AreParallelType
)
38 AreParallelType::AreParallelType()
39 : ArgsParserObjectType( "AreParallel",
40 argsspecAreParallel
, 2 )
44 AreParallelType::~AreParallelType()
48 const AreParallelType
* AreParallelType::instance()
50 static const AreParallelType t
;
54 ObjectImp
* AreParallelType::calc( const Args
& parents
, const KigDocument
& ) const
56 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
57 const LineData
& l1
= static_cast<const AbstractLineImp
*>( parents
[0] )->data();
58 const LineData
& l2
= static_cast<const AbstractLineImp
*>( parents
[1] )->data();
60 if ( l1
.isParallelTo( l2
) )
61 return new TestResultImp( i18n( "These lines are parallel." ) );
63 return new TestResultImp( i18n( "These lines are not parallel." ) );
67 const ObjectImpType
* AreParallelType::resultId() const
69 return TestResultImp::stype();
72 static const ArgsParser::spec argsspecAreOrthogonal
[] =
74 { AbstractLineImp::stype(), I18N_NOOP( "Is this line orthogonal?" ),
75 I18N_NOOP( "Select the first of the two possibly orthogonal lines..." ), false },
76 { AbstractLineImp::stype(), I18N_NOOP( "Orthogonal to this line?" ),
77 I18N_NOOP( "Select the other of the two possibly orthogonal lines..." ), false }
80 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AreOrthogonalType
)
82 AreOrthogonalType::AreOrthogonalType()
83 : ArgsParserObjectType( "AreOrthogonal",
84 argsspecAreOrthogonal
, 2 )
88 AreOrthogonalType::~AreOrthogonalType()
92 const AreOrthogonalType
* AreOrthogonalType::instance()
94 static const AreOrthogonalType t
;
98 ObjectImp
* AreOrthogonalType::calc( const Args
& parents
, const KigDocument
& ) const
100 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
101 const LineData
& l1
= static_cast<const AbstractLineImp
*>( parents
[0] )->data();
102 const LineData
& l2
= static_cast<const AbstractLineImp
*>( parents
[1] )->data();
104 if ( l1
.isOrthogonalTo( l2
) )
105 return new TestResultImp( i18n( "These lines are orthogonal." ) );
107 return new TestResultImp( i18n( "These lines are not orthogonal." ) );
111 const ObjectImpType
* AreOrthogonalType::resultId() const
113 return TestResultImp::stype();
116 static const ArgsParser::spec argsspecAreCollinear
[] =
118 { PointImp::stype(), I18N_NOOP( "Check collinearity of this point" ),
119 I18N_NOOP( "Select the first of the three possibly collinear points..." ), false },
120 { PointImp::stype(), I18N_NOOP( "and this second point" ),
121 I18N_NOOP( "Select the second of the three possibly collinear points..." ), false },
122 { PointImp::stype(), I18N_NOOP( "with this third point" ),
123 I18N_NOOP( "Select the last of the three possibly collinear points..." ), false }
126 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AreCollinearType
)
128 AreCollinearType::AreCollinearType()
129 : ArgsParserObjectType( "AreCollinear",
130 argsspecAreCollinear
, 3 )
134 AreCollinearType::~AreCollinearType()
138 const AreCollinearType
* AreCollinearType::instance()
140 static const AreCollinearType t
;
144 ObjectImp
* AreCollinearType::calc( const Args
& parents
, const KigDocument
& ) const
146 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
147 const Coordinate
& p1
= static_cast<const PointImp
*>( parents
[0] )->coordinate();
148 const Coordinate
& p2
= static_cast<const PointImp
*>( parents
[1] )->coordinate();
149 const Coordinate
& p3
= static_cast<const PointImp
*>( parents
[2] )->coordinate();
151 if ( areCollinear( p1
, p2
, p3
) )
152 return new TestResultImp( i18n( "These points are collinear." ) );
154 return new TestResultImp( i18n( "These points are not collinear." ) );
157 const ObjectImpType
* AreCollinearType::resultId() const
159 return TestResultImp::stype();
162 static const ArgsParser::spec containsTestArgsSpec
[] =
164 { PointImp::stype(), I18N_NOOP( "Check whether this point is on a curve" ),
165 I18N_NOOP( "Select the point you want to test..." ), false },
166 { CurveImp::stype(), I18N_NOOP( "Check whether the point is on this curve" ),
167 I18N_NOOP( "Select the curve that the point might be on..." ), false }
170 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ContainsTestType
)
172 ContainsTestType::ContainsTestType()
173 : ArgsParserObjectType( "ContainsTest", containsTestArgsSpec
, 2 )
177 ContainsTestType::~ContainsTestType()
181 const ContainsTestType
* ContainsTestType::instance()
183 static const ContainsTestType t
;
187 ObjectImp
* ContainsTestType::calc( const Args
& parents
, const KigDocument
& doc
) const
189 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
190 const Coordinate
& p
= static_cast<const PointImp
*>( parents
[0] )->coordinate();
191 const CurveImp
* c
= static_cast<const CurveImp
*>( parents
[1] );
193 if ( c
->containsPoint( p
, doc
) )
194 return new TestResultImp( i18n( "This curve contains the point." ) );
196 return new TestResultImp( i18n( "This curve does not contain the point." ) );
199 const ObjectImpType
* ContainsTestType::resultId() const
201 return TestResultImp::stype();
205 * containment test of a point in a polygon
208 static const ArgsParser::spec InPolygonTestArgsSpec
[] =
210 { PointImp::stype(), I18N_NOOP( "Check whether this point is in a polygon" ),
211 I18N_NOOP( "Select the point you want to test..." ), false },
212 { PolygonImp::stype(), I18N_NOOP( "Check whether the point is in this polygon" ),
213 I18N_NOOP( "Select the polygon that the point might be in..." ), false }
216 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( InPolygonTestType
)
218 InPolygonTestType::InPolygonTestType()
219 : ArgsParserObjectType( "InPolygonTest", InPolygonTestArgsSpec
, 2 )
223 InPolygonTestType::~InPolygonTestType()
227 const InPolygonTestType
* InPolygonTestType::instance()
229 static const InPolygonTestType t
;
233 ObjectImp
* InPolygonTestType::calc( const Args
& parents
, const KigDocument
& ) const
235 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
236 const Coordinate
& p
= static_cast<const PointImp
*>( parents
[0] )->coordinate();
237 const PolygonImp
* pol
= static_cast<const PolygonImp
*>( parents
[1] );
239 if ( pol
->isInPolygon( p
) )
240 return new TestResultImp( i18n( "This polygon contains the point." ) );
242 return new TestResultImp( i18n( "This polygon does not contain the point." ) );
245 const ObjectImpType
* InPolygonTestType::resultId() const
247 return TestResultImp::stype();
251 * test if a polygon is convex
254 static const ArgsParser::spec ConvexPolygonTestArgsSpec
[] =
256 { PolygonImp::stype(), I18N_NOOP( "Check whether this polygon is convex" ),
257 I18N_NOOP( "Select the polygon you want to test for convexity..." ), false }
260 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ConvexPolygonTestType
)
262 ConvexPolygonTestType::ConvexPolygonTestType()
263 : ArgsParserObjectType( "ConvexPolygonTest", ConvexPolygonTestArgsSpec
, 1 )
267 ConvexPolygonTestType::~ConvexPolygonTestType()
271 const ConvexPolygonTestType
* ConvexPolygonTestType::instance()
273 static const ConvexPolygonTestType t
;
277 ObjectImp
* ConvexPolygonTestType::calc( const Args
& parents
, const KigDocument
& ) const
279 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
280 const PolygonImp
* pol
= static_cast<const PolygonImp
*>( parents
[0] );
282 if ( pol
->isConvex() )
283 return new TestResultImp( i18n( "This polygon is convex." ) );
285 return new TestResultImp( i18n( "This polygon is not convex." ) );
288 const ObjectImpType
* ConvexPolygonTestType::resultId() const
290 return TestResultImp::stype();
297 static const ArgsParser::spec argsspecSameDistanceType
[] =
299 { PointImp::stype(), I18N_NOOP( "Check if this point has the same distance" ),
300 I18N_NOOP( "Select the point which might have the same distance from two other points..." ), false },
301 { PointImp::stype(), I18N_NOOP( "from this point" ),
302 I18N_NOOP( "Select the first of the two other points..." ), false },
303 { PointImp::stype(), I18N_NOOP( "and from this second point" ),
304 I18N_NOOP( "Select the other of the two other points..." ), false }
307 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( SameDistanceType
)
309 SameDistanceType::SameDistanceType()
310 : ArgsParserObjectType( "SameDistanceType", argsspecSameDistanceType
, 3 )
314 SameDistanceType::~SameDistanceType()
318 const SameDistanceType
* SameDistanceType::instance()
320 static const SameDistanceType t
;
324 ObjectImp
* SameDistanceType::calc( const Args
& parents
, const KigDocument
& ) const
326 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
327 const Coordinate
& p1
= static_cast<const PointImp
*>( parents
[0] )->coordinate();
328 const Coordinate
& p2
= static_cast<const PointImp
*>( parents
[1] )->coordinate();
329 const Coordinate
& p3
= static_cast<const PointImp
*>( parents
[2] )->coordinate();
331 if ( fabs( ( p1
- p2
).length() - ( p1
- p3
).length() ) < 10e-5 )
332 return new TestResultImp( i18n( "The two distances are the same." ) );
334 return new TestResultImp( i18n( "The two distances are not the same." ) );
337 const ObjectImpType
* SameDistanceType::resultId() const
339 return TestResultImp::stype();
342 static const ArgsParser::spec vectorEqualityArgsSpec
[] =
344 { VectorImp::stype(), I18N_NOOP( "Check whether this vector is equal to another vector" ),
345 I18N_NOOP( "Select the first of the two possibly equal vectors..." ), false },
346 { VectorImp::stype(), I18N_NOOP( "Check whether this vector is equal to the other vector" ),
347 I18N_NOOP( "Select the other of the two possibly equal vectors..." ), false }
350 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( VectorEqualityTestType
)
352 VectorEqualityTestType::VectorEqualityTestType()
353 : ArgsParserObjectType( "VectorEquality", vectorEqualityArgsSpec
, 2 )
357 VectorEqualityTestType::~VectorEqualityTestType()
361 const VectorEqualityTestType
* VectorEqualityTestType::instance()
363 static const VectorEqualityTestType t
;
367 ObjectImp
* VectorEqualityTestType::calc( const Args
& parents
, const KigDocument
& ) const
369 if ( ! margsparser
.checkArgs( parents
) ) return new InvalidImp
;
370 const Coordinate
& v1
= static_cast<const VectorImp
*>( parents
[0] )->dir();
371 const Coordinate
& v2
= static_cast<const VectorImp
*>( parents
[1] )->dir();
373 if ( ( v1
- v2
).length() < 10e-5 )
374 return new TestResultImp( i18n( "The two vectors are the same." ) );
376 return new TestResultImp( i18n( "The two vectors are not the same." ) );
379 const ObjectImpType
* VectorEqualityTestType::resultId() const
381 return TestResultImp::stype();