lineSegment2D.cpp

Go to the documentation of this file.
00001 
00015 #include <dlrGeometry/lineSegment2D.h>
00016 #include <dlrNumeric/utilities.h>
00017 
00018 namespace dnum = dlr::numeric;
00019 
00020 namespace dlr {
00021 
00022   namespace geometry {
00023     
00024     // The assignment operator deep copies its argument.
00025     LineSegment2D&
00026     LineSegment2D::
00027     operator=(const LineSegment2D& source)
00028     {
00029       if(&source != this) {
00030         m_startPoint = source.m_startPoint;
00031         m_endPoint = source.m_endPoint;
00032       }
00033       return *this;
00034     }
00035 
00036 
00037     /* ======= Non-member functions. ======= */
00038 
00039     std::istream&
00040     operator>>(std::istream& stream, LineSegment2D& lineSegment)
00041     {
00042       // If stream is in a bad state, we can't read from it.
00043       if (!stream){
00044         return stream;
00045       }
00046     
00047       double startPointX;
00048       double startPointY;
00049       double endPointX;
00050       double endPointY;
00051         
00052       // Construct an InputStream instance so we can use our
00053       // convenience functions.
00054       dlr::common::InputStream inputStream(
00055         stream, dlr::common::InputStream::SKIP_WHITESPACE);
00056 
00057       inputStream.expect("LineSegment2D");
00058       inputStream.expect("{");
00059       inputStream >> startPointX;
00060       inputStream.expect(",");
00061       inputStream >> startPointY;
00062       inputStream.expect(",");
00063       inputStream >> endPointX;
00064       inputStream.expect(",");
00065       inputStream >> endPointY;
00066       inputStream.expect("}");
00067 
00068       // If reading failed, don't change lineSegment.
00069       if (!stream){
00070         return stream;
00071       }
00072       
00073       lineSegment.setValue(startPointX, startPointY,
00074                            endPointX, endPointY);
00075       return stream;
00076     }
00077     
00078 
00079     std::ostream&
00080     operator<<(std::ostream& stream, const LineSegment2D& lineSegment)
00081     {
00082       stream << "LineSegment2D { "
00083              << lineSegment.getStartPoint().x() << ", "
00084              << lineSegment.getStartPoint().y() << ", "
00085              << lineSegment.getEndPoint().x() << ", "
00086              << lineSegment.getEndPoint().y() << " }";
00087       return stream;
00088     }
00089 
00090     
00091   } // namespace geometry
00092     
00093 } // namespace dlr

Generated on Wed Nov 25 11:45:25 2009 for dlrGeometry Utility Library by  doxygen 1.5.8