primitives.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PAPYRUSPRIMITIVES_H
00021 #define PAPYRUSPRIMITIVES_H
00022
00023 #include <cmath>
00024
00025 namespace Papyrus
00026 {
00033 struct Point {
00034 Point( double xval=0.0, double yval=0.0 ): x(xval), y(yval) { }
00035 Point( const Point& p ): x(p.x), y(p.y) { }
00036
00037 double x;
00038 double y;
00039
00040 void invalidate() { x = NAN; y = NAN; }
00041
00042 virtual operator bool() { return ( not isnan(x) and not isnan(y) ); }
00043 };
00044
00054 template<typename PointType>
00055 struct LineSegment {
00056 LineSegment ( double x1=0.0, double y1=0.0, double x2=0.0, double y2=0.0 ): p0(x1,y1), p1(x2,y2) { }
00057 LineSegment ( const PointType& point0, const PointType& point1 ): p0(point0), p1(point1) { }
00058 LineSegment ( const LineSegment& l ): p0(l.p0), p1(l.p1) { }
00059
00060 PointType p0, p1;
00061
00062 void invalidate() { p0.invalidate(); p1.invalidate(); }
00063
00064 operator bool() { return ( p0 and p1 ); }
00065
00066 PointType& operator [](int i) { if ( i <= 0 ) return p0; else return p1; }
00067 const PointType& operator [](int i) const { if ( i <= 0 ) return p0; else return p1; }
00068 };
00069
00070 }
00071
00072 #endif