cgma
Cubit2DPoint.cpp
Go to the documentation of this file.
00001 //- Class: Cubit2DPoint
00002 //- Description: This file defines the Cubit2DPoint class.
00003 //- Owner: Steve Storm
00004 //- Checked by:
00005 
00006 #include <math.h>
00007 #include "Cubit2DPoint.hpp"
00008 #include "CubitMessage.hpp"
00009 
00010 #include "DLIList.hpp"
00011 
00012 void
00013 Cubit2DPoint::min_max( const Cubit2DPoint &pnt2, 
00014                        double &xmin, double &xmax,
00015                        double &ymin, double &ymax ) const
00016 {
00017    if( xVal < pnt2.x() )
00018    {
00019       xmin = xVal;
00020       xmax = pnt2.x();
00021    }
00022    else
00023    {
00024       xmin = pnt2.x();
00025       xmax = xVal;
00026    }
00027 
00028    if( yVal < pnt2.y() )
00029    {
00030       ymin = yVal;
00031       ymax = pnt2.y();
00032    }
00033    else
00034    {
00035       ymin = pnt2.y();
00036       ymax = yVal;
00037    }
00038 }
00039 
00040 void 
00041 Cubit2DPoint::update_min_max( Cubit2DPoint &min,
00042                               Cubit2DPoint &max ) const
00043 {
00044    min.x( CUBIT_MIN( xVal, min.x() ) );
00045    min.y( CUBIT_MIN( yVal, min.y() ) );
00046 
00047    max.x( CUBIT_MAX( xVal, max.x() ) );
00048    max.y( CUBIT_MAX( yVal, max.y() ) );
00049 }  
00050 
00051 CubitBoolean 
00052 Cubit2DPoint::is_on_line_segment( const Cubit2DPoint &end1,
00053                                   const Cubit2DPoint &end2,
00054                                   double tol ) const
00055 {
00056    // Check bounding box
00057    double xmin, xmax, ymin, ymax;
00058    end1.min_max( end2, xmin, xmax, ymin, ymax );
00059    if( xVal < xmin-tol || yVal < ymin-tol ||
00060        xVal > xmax+tol || yVal > ymax+tol ) 
00061    {
00062       return CUBIT_FALSE;
00063    }
00064 
00065    // Check area of triangle (formula in if is twice the area)
00066    
00067     if( fabs( end1.x()*end2.y() + end1.y()*xVal +
00068           end2.x()*yVal - end2.y()*xVal -
00069           end1.x()*yVal - end1.y()*end2.x() ) < tol )
00070       return CUBIT_TRUE;
00071    
00072    return CUBIT_FALSE;
00073 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines