source: projectionDesigner/trunk/projdesigner/include/gmtl/LineSeg.h @ 4

Last change on this file since 4 was 4, checked in by Torben Dannhauer, 14 years ago
File size: 3.3 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          LineSeg.h,v
10 * Date modified: 2003/03/03 00:54:05
11 * Version:       1.7
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_LINESEG_H_
36#define _GMTL_LINESEG_H_
37
38#include <gmtl/Point.h>
39#include <gmtl/Vec.h>
40#include <gmtl/VecOps.h>
41#include <gmtl/Ray.h>
42
43namespace gmtl {
44
45/**
46 * Describes a line segment. This is represented by a point origin O and a
47 * vector spanning the length of the line segement originating at O. Thus any
48 * point on the line segment can be described as
49 *
50 * P(s) = O + Vs
51 *
52 * where 0 <= s <= 1
53 *
54 * @param DATA_TYPE     the internal type used for the point and vector
55 */
56template <typename DATA_TYPE>
57class LineSeg : public Ray<DATA_TYPE>
58{
59public:
60   /**
61    * Constructs a line segment at the origin with a zero vector.
62    */
63   LineSeg()
64   {}
65
66   /**
67    * Constructs a line segment with the given origin and vector.
68    *
69    * @param origin     the point at which the line segment starts
70    * @param dir        the vector describing the direction and length of the
71    *                   line segment starting at origin
72    */
73   LineSeg( const Point<DATA_TYPE, 3>& origin, const Vec<DATA_TYPE, 3>& dir )
74      : Ray<DATA_TYPE>( origin, dir )
75   {}
76
77   /**
78    * Constructs an exact duplicate of the given line segment.
79    *
80    * @param ray    the line segment to copy
81    */
82   LineSeg( const LineSeg& ray ) : Ray<DATA_TYPE>( ray )
83   {
84   }
85
86   /**
87    * Constructs a line segment with the given beginning and ending points.
88    *
89    * @param beg     the point at the beginning of the line segment
90    * @param end     the point at the end of the line segment
91    */
92   LineSeg( const Point<DATA_TYPE, 3>& beg, const Point<DATA_TYPE, 3>& end )
93      : Ray<DATA_TYPE>()
94   {
95      this->mOrigin = beg;
96      this->mDir = end - beg;
97   }
98
99   /**
100    * Gets the length of this line segment.
101    * @return the length of the line segment
102    */
103   DATA_TYPE getLength() const
104   {
105      return length(this->mDir);
106   }
107};
108
109
110// --- helper types --- //
111typedef LineSeg<float>  LineSegf;
112typedef LineSeg<double> LineSegd;
113}
114
115#endif
Note: See TracBrowser for help on using the repository browser.