Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

LineSegOps.h

Go to the documentation of this file.
00001 /************************************************************** ggt-head beg
00002  *
00003  * GGT: Generic Graphics Toolkit
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: LineSegOps.h,v $
00010  * Date modified: $Date: 2003/03/17 00:11:12 $
00011  * Version:       $Revision: 1.6 $
00012  * -----------------------------------------------------------------
00013  *
00014  *********************************************************** ggt-head end */
00015 /*************************************************************** ggt-cpr beg
00016 *
00017 * GGT: The Generic Graphics Toolkit
00018 * Copyright (C) 2001,2002 Allen Bierbaum
00019 *
00020 * This library is free software; you can redistribute it and/or
00021 * modify it under the terms of the GNU Lesser General Public
00022 * License as published by the Free Software Foundation; either
00023 * version 2.1 of the License, or (at your option) any later version.
00024 *
00025 * This library is distributed in the hope that it will be useful,
00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00028 * Lesser General Public License for more details.
00029 *
00030 * You should have received a copy of the GNU Lesser General Public
00031 * License along with this library; if not, write to the Free Software
00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033 *
00034  ************************************************************ ggt-cpr end */
00035 #ifndef _GMTL_LINESEGOPS_H_
00036 #define _GMTL_LINESEGOPS_H_
00037 
00038 #include <gmtl/LineSeg.h>
00039 
00040 namespace gmtl {
00041 
00050 template< class DATA_TYPE >
00051 Point<DATA_TYPE, 3> findNearestPt( const LineSeg<DATA_TYPE>& lineseg,
00052                                    const Point<DATA_TYPE, 3>& pt )
00053 {
00054    // result = origin + dir * dot((pt-origin), dir)
00055    return ( lineseg.mOrigin + lineseg.mDir *
00056             dot(pt - lineseg.mOrigin, lineseg.mDir) );
00057 }
00058 
00067 template< class DATA_TYPE >
00068 inline DATA_TYPE distance( const LineSeg<DATA_TYPE>& lineseg,
00069                            const Point<DATA_TYPE, 3>& pt )
00070 {
00071    return gmtl::length( pt - findNearestPt( lineseg, pt ) );
00072 }
00073 
00082 template< class DATA_TYPE >
00083 inline DATA_TYPE distanceSquared( const LineSeg<DATA_TYPE>& lineseg,
00084                            const Point<DATA_TYPE, 3>& pt )
00085 {
00086    return gmtl::lengthSquared( pt - findNearestPt( lineseg, pt ) );
00087 }
00088 
00089 //--- LineSeg Comparitor ---//
00098 template< class DATA_TYPE >
00099 inline bool operator==( const LineSeg<DATA_TYPE>& ls1, const LineSeg<DATA_TYPE>& ls2 )
00100 {
00101    return ( (ls1.mOrigin == ls2.mOrigin) && (ls1.mDir == ls2.mDir) );
00102 }
00103 
00112 template< class DATA_TYPE >
00113 inline bool operator!=( const LineSeg<DATA_TYPE>& ls1,
00114                         const LineSeg<DATA_TYPE>& ls2 )
00115 {
00116    return ( ! (ls1 == ls2) );
00117 }
00118 
00131 template< class DATA_TYPE >
00132 inline bool isEqual( const LineSeg<DATA_TYPE>& ls1,
00133                      const LineSeg<DATA_TYPE>& ls2,
00134                      const DATA_TYPE& eps )
00135 {
00136    gmtlASSERT( eps >= 0 );
00137    return ( (isEqual(ls1.mOrigin, ls2.mOrigin, eps)) &&
00138             (isEqual(ls1.mDir, ls2.mDir, eps)) );
00139 }
00140 
00141 } // namespace gmtl
00142 #endif

Generated on Mon Apr 7 15:28:54 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002