papyrus logo

primitives.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the papyrus library.                             *
00006  *                                                                         *
00007  *   papyrus is free software; you can redistribute it and/or modify       *
00008  *   it under the terms of the GNU Lesser General Public License           *
00009  *   version 3.0 as published by the Free Software Foundation.             *
00010  *                                                                         *
00011  *   papyrus is distributed in the hope that it will be useful,            *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Lesser General Public License version 3.0 for more details.       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with the papyrus library. If not, see                   *
00018  *   <http://www.gnu.org/licenses/>.                                       *
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

Generated on Fri Apr 16 12:40:11 2010 for papyrus by doxygen 1.6.1