00001
00022 #ifndef KIG_MISC_COMMON_H
00023 #define KIG_MISC_COMMON_H
00024
00025 #include "coordinate.h"
00026 #include "rect.h"
00027
00028 #include <tqrect.h>
00029 #include <tdeversion.h>
00030
00031 #include <vector>
00032 #include <assert.h>
00033
00034 #ifdef KDE_IS_VERSION
00035 #if KDE_IS_VERSION( 3, 1, 0 )
00036 #define KIG_USE_KDOUBLEVALIDATOR
00037 #else
00038 #undef KIG_USE_KDOUBLEVALIDATOR
00039 #endif
00040 #else
00041 #undef KIG_USE_KDOUBLEVALIDATOR
00042 #endif
00043
00044 class ObjectImp;
00045 class KigWidget;
00046
00047 extern const double double_inf;
00048
00054 double getDoubleFromUser( const TQString& caption, const TQString& label, double value,
00055 TQWidget* parent, bool* ok, double min, double max, int decimals );
00056
00060 class LineData {
00061 public:
00067 LineData() : a(), b() {}
00071 LineData( const Coordinate& na, const Coordinate& nb ) : a( na ), b( nb ) {}
00075 Coordinate a;
00079 Coordinate b;
00083 const Coordinate dir() const { return b - a; }
00087 double length() const { return ( b - a ).length(); }
00088
00092 bool isParallelTo( const LineData& l ) const;
00093
00097 bool isOrthogonalTo( const LineData& l ) const;
00098 };
00099
00103 bool operator==( const LineData& l, const LineData& r );
00104
00109 Coordinate calcRotatedPoint( const Coordinate& a, const Coordinate& c, const double arc );
00110
00115 Coordinate calcPointOnPerpend( const LineData& l, const Coordinate& t );
00116
00121 Coordinate calcPointOnPerpend( const Coordinate& dir, const Coordinate& t );
00122
00127 Coordinate calcPointOnParallel( const LineData& l, const Coordinate& t );
00128
00133 Coordinate calcPointOnParallel( const Coordinate& dir, const Coordinate& t );
00134
00135
00139 Coordinate calcIntersectionPoint( const LineData& l, const LineData& m );
00140
00150 const Coordinate calcCircleLineIntersect( const Coordinate& c,
00151 const double sqr,
00152 const LineData& l,
00153 int side );
00154
00164 const Coordinate calcArcLineIntersect( const Coordinate& c, const double sqr,
00165 const double sa, const double angle,
00166 const LineData& l, int side );
00167
00172 const Coordinate calcPointProjection( const Coordinate& p,
00173 const LineData& l );
00174
00178 double calcDistancePointLine( const Coordinate& p,
00179 const LineData& l );
00180
00185 void calcBorderPoints( Coordinate& p1, Coordinate& p2, const Rect& r );
00189 void calcBorderPoints( double& xa, double& xb, double& ya, double& yb, const Rect& r);
00193 const LineData calcBorderPoints( const LineData& l, const Rect& r );
00194
00198 void calcRayBorderPoints( const Coordinate& a, Coordinate& b, const Rect& r );
00199
00204 const Coordinate calcCenter(
00205 const Coordinate& a, const Coordinate& b, const Coordinate& c );
00206
00210 void calcRayBorderPoints( const double xa, const double xb, double& ya,
00211 double& yb, const Rect& r );
00212
00216 const Coordinate calcMirrorPoint( const LineData& l,
00217 const Coordinate& p );
00218
00222 bool areCollinear( const Coordinate& p1, const Coordinate& p2,
00223 const Coordinate& p3 );
00224
00229 bool isSingular( const double& a, const double& b,
00230 const double& c, const double& d );
00231
00236 bool isOnLine( const Coordinate& o, const Coordinate& a,
00237 const Coordinate& b, const double fault );
00238
00244 bool isOnSegment( const Coordinate& o, const Coordinate& a,
00245 const Coordinate& b, const double fault );
00246
00247 bool isOnRay( const Coordinate& o, const Coordinate& a,
00248 const Coordinate& b, const double fault );
00249
00250 bool isOnArc( const Coordinate& o, const Coordinate& c, const double r,
00251 const double sa, const double a, const double fault );
00252
00253 Coordinate calcCircleRadicalStartPoint( const Coordinate& ca,
00254 const Coordinate& cb,
00255 double sqra, double sqrb );
00256
00262 bool lineInRect( const Rect& r, const Coordinate& a, const Coordinate& b,
00263 const int width, const ObjectImp* imp, const KigWidget& w );
00264
00265 template <typename T>
00266 T kigMin( const T& a, const T& b )
00267 {
00268 return a < b ? a : b;
00269 }
00270
00271 template <typename T>
00272 T kigMax( const T& a, const T& b )
00273 {
00274 return a > b ? a : b;
00275 }
00276
00277 template <typename T>
00278 T kigAbs( const T& a )
00279 {
00280 return a >= 0 ? a : -a;
00281 }
00282
00283 template <typename T>
00284 int kigSgn( const T& a )
00285 {
00286 return a == 0 ? 0 : a > 0 ? +1 : -1;
00287 }
00288
00289 extern const double test_threshold;
00290
00291 #endif