dpoint2.h File Reference

#include "GeomExport.h"
#include "maxheap.h"
#include "point2.h"
#include "assert1.h"
#include <iosfwd>

Classes

class  DPoint2
 Description: This class describes a 2D point using double precision x and y coordinates. More...
 
class  DRay2
 This class describes a vector in space using an origin point p, and a unit direction vector in double precision. More...
 

Functions

double Length (const DPoint2 &p)
 Returns the 'Length' of the point. More...
 
int MaxComponent (const DPoint2 &p)
 Returns the component with the maximum absolute value. More...
 
int MinComponent (const DPoint2 &p)
 Returns the component with the minimum absolute value. More...
 
DPoint2 Normalize (const DPoint2 &p)
 Returns a unit vector. More...
 
DPoint2 operator* (double m, const DPoint2 &p)
 Multiply a DPoint2 by a scalar. More...
 
DPoint2 operator* (const DPoint2 &p, double m)
 Multiply a DPoint2 by a scalar. More...
 
DPoint2 operator/ (const DPoint2 &p, double d)
 Divide a DPoint2 by a scalar. More...
 
std::ostream & operator<< (std::ostream &s, const DPoint2 &p)
 Output a DPoint2 to a std::ostream as text. More...
 
Point2 Point2FromDPoint2 (const DPoint2 &from)
 
double DotProd (const DPoint2 &a, const DPoint2 &b)
 Returns the dot product of two DPoint2s. More...
 
int DoublePrecisionLineSegmentIntersection (const DPoint2 &seg1Start, const DPoint2 &seg1End, const DPoint2 &seg2Start, const DPoint2 &seg2End, DPoint2 &intersectPoint)
 Double-Precision Line Segment Intersection test. More...
 
int DoublePrecisionLineIntersection (const DPoint2 &line1PointA, const DPoint2 &line1PointB, const DPoint2 &line2PointA, const DPoint2 &line2PointB, DPoint2 &intersectPoint)
 Double-Precision Line Intersection test. More...
 

Function Documentation

double Length ( const DPoint2 p)
inline

Returns the 'Length' of the point.

This is sqrt(v.x*v.x+v.y*v.y)

Parameters
pthe DPoint2 to test
Returns
the length value
229  {
230  return (double)sqrt(v.x*v.x + v.y*v.y);
231 }
int MaxComponent ( const DPoint2 p)

Returns the component with the maximum absolute value.

Parameters
pthe DPoint2 to test
Returns
the maximum component (0=x, 1=y).
int MinComponent ( const DPoint2 p)

Returns the component with the minimum absolute value.

0=x, 1=y.

Parameters
pthe DPoint2 to test
Returns
the minimum component (0=x, 1=y).
DPoint2 Normalize ( const DPoint2 p)

Returns a unit vector.

This is a DPoint2 with each component divided by the point Length().

Parameters
pthe DPoint2 to test
Returns
the unit vector for the specified DPoint2
DPoint2 operator* ( double  m,
const DPoint2 p 
)
inline

Multiply a DPoint2 by a scalar.

Parameters
mthe multiplier
pthe DPoint2
Returns
the resulting DPoint2
274  {
275  return(DPoint2(a.x*f, a.y*f));
276 }
Description: This class describes a 2D point using double precision x and y coordinates.
Definition: dpoint2.h:23
DPoint2 operator* ( const DPoint2 p,
double  m 
)
inline

Multiply a DPoint2 by a scalar.

Parameters
pthe DPoint2
mthe multiplier
Returns
the resulting DPoint2
278  {
279  return(DPoint2(a.x*f, a.y*f));
280 }
Description: This class describes a 2D point using double precision x and y coordinates.
Definition: dpoint2.h:23
DPoint2 operator/ ( const DPoint2 p,
double  d 
)
inline

Divide a DPoint2 by a scalar.

Parameters
pthe DPoint2
dthe divisor
Returns
the resulting DPoint2
282  {
283  DbgAssert(f != 0.0);
284  double invF = 1.0 / f; // Mimic 2019 behavior
285  return(DPoint2(a.x * invF, a.y * invF));
286 }
Description: This class describes a 2D point using double precision x and y coordinates.
Definition: dpoint2.h:23
#define DbgAssert(expr)
Definition: assert1.h:72
std::ostream& operator<< ( std::ostream &  s,
const DPoint2 p 
)

Output a DPoint2 to a std::ostream as text.

Parameters
sthe std::ostream
pthe DPoint2
Returns
the DPoint2 text value
Point2 Point2FromDPoint2 ( const DPoint2 from)
inline
290 {
291  return Point2(from.x, from.y);
292 }
Definition: point2.h:43
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
double DotProd ( const DPoint2 a,
const DPoint2 b 
)

Returns the dot product of two DPoint2s.

int DoublePrecisionLineSegmentIntersection ( const DPoint2 seg1Start,
const DPoint2 seg1End,
const DPoint2 seg2Start,
const DPoint2 seg2End,
DPoint2 intersectPoint 
)

Double-Precision Line Segment Intersection test.

Determines if two line segments intersect.

Parameters
seg1Startendpoint 1 for the first line segment
seg1Endendpoint 2 for the first line segment
seg2Startendpoint 1 for the second line segment
seg2Endendpoint 2 for the second line segment
intersectPointif the lines intersect, this will return the intersection point.
Returns
Intersection determination (0: No intersection, 1: Lines intersect (intersection location in 'intersectPoint'), 2: Lines parallel (no intersection))
int DoublePrecisionLineIntersection ( const DPoint2 line1PointA,
const DPoint2 line1PointB,
const DPoint2 line2PointA,
const DPoint2 line2PointB,
DPoint2 intersectPoint 
)

Double-Precision Line Intersection test.

Determines if two infinite lines cross, and if so, where.

Parameters
line1PointApoint 1 on the first line
line1PointBpoint 2 on the first line
line2PointApoint 1 on the second line
line2PointBpoint 2 on the second line
intersectPointif the lines intersect, this will return the intersection point.
Returns
Intersection determination (0: Lines parallel, 1: Lines intersect (intersection location in 'intersectPoint'))