Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * line_segment.cpp - A line segment 00004 * 00005 * Created: Thu Oct 02 17:05:52 2008 00006 * Copyright 2008 Daniel Beck 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <geometry/line_segment.h> 00025 00026 namespace fawkes { 00027 00028 /** @class fawkes::LineSegment <geometry/line_segment.h> 00029 * A line segment. 00030 * @author Daniel Beck 00031 */ 00032 00033 /** Constructor. 00034 * @param a the starting point of the line segment 00035 * @param b the endpoint of of the line segment 00036 */ 00037 LineSegment::LineSegment(const HomPoint& a, const HomPoint& b) 00038 : m_p1(a), 00039 m_p2(b) 00040 { 00041 register_primitives(); 00042 } 00043 00044 /** Constructor. 00045 * @param p the starting point of the line segment 00046 * @param v a vector defining orientation and length of the line 00047 * segment 00048 */ 00049 LineSegment::LineSegment(const HomPoint& p, const HomVector& v) 00050 : m_p1(p), 00051 m_p2(p+v) 00052 { 00053 register_primitives(); 00054 } 00055 00056 /** Copy constructor. 00057 * @param l another line segment 00058 */ 00059 LineSegment::LineSegment(const LineSegment& l) 00060 : m_p1(l.m_p1), 00061 m_p2(l.m_p2) 00062 { 00063 clear_primitives(); 00064 register_primitives(); 00065 } 00066 00067 /** Destructor. */ 00068 LineSegment::~LineSegment() 00069 { 00070 } 00071 00072 /** Get the length of the line segment. 00073 * @return the length of the line segment 00074 */ 00075 float 00076 LineSegment::length() const 00077 { 00078 HomVector v; 00079 v = m_p2 - m_p1; 00080 return v.length(); 00081 } 00082 00083 /** Get the starting point. 00084 * @return the starting point 00085 */ 00086 const HomPoint& 00087 LineSegment::p1() const 00088 { 00089 return m_p1; 00090 } 00091 00092 /** Get the endpoint. 00093 * @return the endpoint 00094 */ 00095 const HomPoint& 00096 LineSegment::p2() const 00097 { 00098 return m_p2; 00099 } 00100 00101 void 00102 LineSegment::register_primitives() 00103 { 00104 add_primitive(&m_p1); 00105 add_primitive(&m_p2); 00106 } 00107 00108 void 00109 LineSegment::post_transform() 00110 { 00111 } 00112 00113 std::ostream& 00114 LineSegment::print(std::ostream& stream) const 00115 { 00116 stream << "P1: " << m_p1 << " P2: " << m_p2; 00117 return stream; 00118 } 00119 00120 } // end namespace fawkes