1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//- Class: Cubit2DPoint<--- Skipping configuration 'DBL_MAX' since the value of 'DBL_MAX' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'DBL_MIN' since the value of 'DBL_MIN' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'M_PI' since the value of 'M_PI' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
//- Description: This file defines the Cubit2DPoint class.
//- Owner: Steve Storm
//- Checked by:

#include <math.h>
#include "Cubit2DPoint.hpp"
#include "CubitMessage.hpp"

#include "DLIList.hpp"

void
Cubit2DPoint::min_max( const Cubit2DPoint &pnt2, 
                       double &xmin, double &xmax,
                       double &ymin, double &ymax ) const
{
   if( xVal < pnt2.x() )
   {
      xmin = xVal;
      xmax = pnt2.x();
   }
   else
   {
      xmin = pnt2.x();
      xmax = xVal;
   }

   if( yVal < pnt2.y() )
   {
      ymin = yVal;
      ymax = pnt2.y();
   }
   else
   {
      ymin = pnt2.y();
      ymax = yVal;
   }
}

void 
Cubit2DPoint::update_min_max( Cubit2DPoint &min,
                              Cubit2DPoint &max ) const
{
   min.x( CUBIT_MIN( xVal, min.x() ) );
   min.y( CUBIT_MIN( yVal, min.y() ) );

   max.x( CUBIT_MAX( xVal, max.x() ) );
   max.y( CUBIT_MAX( yVal, max.y() ) );
}  

CubitBoolean 
Cubit2DPoint::is_on_line_segment( const Cubit2DPoint &end1,
                                  const Cubit2DPoint &end2,
                                  double tol ) const
{
   // Check bounding box
   double xmin, xmax, ymin, ymax;
   end1.min_max( end2, xmin, xmax, ymin, ymax );
   if( xVal < xmin-tol || yVal < ymin-tol ||
       xVal > xmax+tol || yVal > ymax+tol ) 
   {
      return CUBIT_FALSE;
   }

   // Check area of triangle (formula in if is twice the area)
   
	if( fabs( end1.x()*end2.y() + end1.y()*xVal +
	      end2.x()*yVal - end2.y()*xVal -
	      end1.x()*yVal - end1.y()*end2.x() ) < tol )
      return CUBIT_TRUE;
   
   return CUBIT_FALSE;
}