proj home

Files   Classes   Functions   Hierarchy  

Public Member Functions | Public Attributes | List of all members
point2< T > Class Template Reference

2D point. More...

#include <point.h>

Inheritance diagram for point2< T >:
Inheritance graph
Collaboration diagram for point2< T >:
Collaboration graph

Public Member Functions

 point2 ()
 Set the default values to zero.
 point2 (T x0, T y0)
 Construct a 2D point.
 operator stringc () const
 Write out a point as a string.
void serializeInverse (stringc &s)
 Interpret or read in the point.
void serializeInverseBrackets (stringc &s)
 Read the point in that is in human friendly format with brackets and a comma from the string.
ostreamprint (ostream &os) const
 Write out the point.
istream & serializeInverse (istream &istr)
 Read in a point from a stream.
point2< T > & operator+= (point2< T > const &p)
 Modify this point by adding to itself.
point2< T > const operator+ (point2< T > const &p) const
 Create a tempory adding the two points.
point2< T > & operator-= (point2< T > const &p)
 Modify this point by subtracting from itself.
point2< T > const operator- (point2< T > const &p) const
 Create a tempory subtracting the two points.
point2< T > & operator*= (point2< T > const &p)
 Modify this point by multiplying to itself.
point2< T > const operator* (point2< T > const &p) const
 Create a tempory multiplying the two points.
point2< T > & operator/= (point2< T > const &p)
 Modify this point by dividing to itself.
point2< T > const operator/ (point2< T > const &p) const
 Create a tempory dividing the two points.
bool const operator== (point2< T > const &p) const
 Compare the two points for equality.
template<typename W >
point2< T > & operator+= (W const &w)
 Modify this point by adding component wise to itself.
template<typename W >
point2< T > const operator+ (W const &w) const
 Create a tempory adding component wise the two points.
template<typename W >
point2< T > & operator-= (W const &w)
 Modify this point by subtracting component wise to itself.
template<typename W >
point2< T > const operator- (W const &w) const
 Create a tempory subtracting component wise the two points.
template<typename W >
point2< T > & operator*= (W const &w)
 Modify this point by multiplying component wise to itself.
template<typename W >
point2< T > const operator* (W const &p) const
 Create a tempory multiplying component wise the two points.
template<typename W >
point2< T > & operator/= (W const &w)
 Modify this point by dividing component wise to itself.
template<typename W >
point2< T > const operator/ (W const &p) const
 Create a tempory dividing component wise the two points.
template<typename W >
boolc operator!= (W const &w) const
 Not test applied to each element.
T const & operator[] (uintc i) const
 Access the elements with integers.
Toperator[] (uintc i)
 Access a reference to an element.
void rotate90 ()
 Rotate 90 degrees in a anti clockwise direction.
T const dot () const
 A distance measure.
T const dot (point2< T > const &w) const
 The dot product of two 2D points.
T const distance () const
 The pythagorean distance between two points.
void normalize ()
 Make this vector a unit vector.
template<typename Z >
Z const sumInRatio (Z const &A, Z const &B) const
 Use this point as a ratio to sum two other numbers.
boolc isinsideunitbox () const
 Is this point on or inside the unit box.

Public Attributes

T x
 The x component/dimension.
T y
 The y component/dimension.

Detailed Description

template<typename T>
class point2< T >

2D point.

The class provides both direct memory management though adding and modifying the point itself by {+,-,*,/}= operators, or the generation of temporaries throught {+,-,*,/} operators.

Reading and writing to strings and streams is also supported.

Definition at line 31 of file point.h.

Constructor & Destructor Documentation

template<typename T>
point2< T >::point2 ( )
inline

Set the default values to zero.

Definition at line 41 of file point.h.

: x(0), y(0) {}
template<typename T>
point2< T >::point2 ( T  x0,
T  y0 
)
inline

Construct a 2D point.

Definition at line 43 of file point.h.

: x(x0), y(y0) {}

Member Function Documentation

template<typename T>
T const point2< T >::distance ( ) const
inline

The pythagorean distance between two points.

Definition at line 160 of file point.h.

Referenced by arc::distance(), d3minboundary::eval(), halfspaceD2draw::rotate(), linetest::test01(), and mathlibtest::test015().

{ return sqrt(x*x + y*y); }
template<typename T>
T const point2< T >::dot ( ) const
inline
template<typename T>
T const point2< T >::dot ( point2< T > const &  w) const
inline

The dot product of two 2D points.

Definition at line 156 of file point.h.

{ return x*w.x + y*w.y; }
template<typename T>
boolc point2< T >::isinsideunitbox ( ) const
inline

Is this point on or inside the unit box.

Definition at line 173 of file point.h.

{
if (x<(T)0)
return false;
if (y<(T)0)
return false;
if (x>(T)1)
return false;
if (y>(T)1)
return false;
return true;
}
template<typename T>
void point2< T >::normalize ( )
inline

Make this vector a unit vector.

Definition at line 164 of file point.h.

Referenced by ruler::addStraightRuler(), d2arrow::d2arrow(), and test01().

{ assert(distance()!=0); *this *= 1.0/distance(); }
template<typename T>
point2< T >::operator stringc ( ) const
inline

Write out a point as a string.

Definition at line 46 of file point.h.

{
string s;
{ stringstream ss; ss << x; s+=ss.str(); }
s += " ";
{ stringstream ss; ss << y; s+=ss.str(); }
return s;
}
template<typename T>
template<typename W >
boolc point2< T >::operator!= ( W const &  w) const
inline

Not test applied to each element.

Definition at line 134 of file point.h.

{ if (x!=w.x) return true; if (y!=w.y) return true; return false; }
template<typename T>
point2<T> const point2< T >::operator* ( point2< T > const &  p) const
inline

Create a tempory multiplying the two points.

Definition at line 86 of file point.h.

{ point2<T> z(*this); z*=p; return z; }
template<typename T>
template<typename W >
point2<T> const point2< T >::operator* ( W const &  p) const
inline

Create a tempory multiplying component wise the two points.

Definition at line 122 of file point.h.

{ point2<T> z(*this); z.x*=p; z.y*=p; return z; }
template<typename T>
point2<T>& point2< T >::operator*= ( point2< T > const &  p)
inline

Modify this point by multiplying to itself.

Definition at line 83 of file point.h.

{ x*=p.x; y*=p.y; return *this; }
template<typename T>
template<typename W >
point2<T>& point2< T >::operator*= ( W const &  w)
inline

Modify this point by multiplying component wise to itself.

Definition at line 118 of file point.h.

{ x*=w; y*=w; return *this; }
template<typename T>
point2<T> const point2< T >::operator+ ( point2< T > const &  p) const
inline

Create a tempory adding the two points.

Definition at line 73 of file point.h.

{ point2<T> z(*this); z+=p; return z; }
template<typename T>
template<typename W >
point2<T> const point2< T >::operator+ ( W const &  w) const
inline

Create a tempory adding component wise the two points.

Definition at line 106 of file point.h.

{ point2<T> z(*this); z.x+=w; z.y+=w; return z; }
template<typename T>
point2<T>& point2< T >::operator+= ( point2< T > const &  p)
inline

Modify this point by adding to itself.

Definition at line 70 of file point.h.

{ x+=p.x; y+=p.y; return *this; }
template<typename T>
template<typename W >
point2<T>& point2< T >::operator+= ( W const &  w)
inline

Modify this point by adding component wise to itself.

Definition at line 102 of file point.h.

{ x+=w; y+=w; return *this; }
template<typename T>
point2<T> const point2< T >::operator- ( point2< T > const &  p) const
inline

Create a tempory subtracting the two points.

Definition at line 79 of file point.h.

{ return point2<T>(this->x-p.x,this->y-p.y); } // seg faulted too.
template<typename T>
template<typename W >
point2<T> const point2< T >::operator- ( W const &  w) const
inline

Create a tempory subtracting component wise the two points.

Definition at line 114 of file point.h.

{ point2<T> z(*this); z.x-=w; z.y-=w; return z; }
template<typename T>
point2<T>& point2< T >::operator-= ( point2< T > const &  p)
inline

Modify this point by subtracting from itself.

Definition at line 76 of file point.h.

{ x-=p.x; y-=p.y; return *this; }
template<typename T>
template<typename W >
point2<T>& point2< T >::operator-= ( W const &  w)
inline

Modify this point by subtracting component wise to itself.

Definition at line 110 of file point.h.

{ x-=w; y-=w; return *this; }
template<typename T>
point2<T> const point2< T >::operator/ ( point2< T > const &  p) const
inline

Create a tempory dividing the two points.

Definition at line 92 of file point.h.

{ point2<T> z(*this); z/=p; return z; }
template<typename T>
template<typename W >
point2<T> const point2< T >::operator/ ( W const &  p) const
inline

Create a tempory dividing component wise the two points.

Definition at line 130 of file point.h.

{ point2<T> z(*this); z.x/=p; z.y/=p; return z; }
template<typename T>
point2<T>& point2< T >::operator/= ( point2< T > const &  p)
inline

Modify this point by dividing to itself.

Definition at line 89 of file point.h.

{ x/=p.x; y/=p.y; return *this; }
template<typename T>
template<typename W >
point2<T>& point2< T >::operator/= ( W const &  w)
inline

Modify this point by dividing component wise to itself.

Definition at line 126 of file point.h.

{ x/=w; y/=w; return *this; }
template<typename T>
bool const point2< T >::operator== ( point2< T > const &  p) const
inline

Compare the two points for equality.

Definition at line 97 of file point.h.

{ return (x==p.x)&&(y==p.y); }
template<typename T>
T const& point2< T >::operator[] ( uintc  i) const
inline

Access the elements with integers.

Definition at line 139 of file point.h.

{ assert(i<2); if ((i%2)==0) return x; return y; }
template<typename T>
T& point2< T >::operator[] ( uintc  i)
inline

Access a reference to an element.

Definition at line 142 of file point.h.

{ assert(i<2); if ((i%2)==0) return x; return y; }
template<typename T>
ostream& point2< T >::print ( ostream os) const
inline

Write out the point.

Definition at line 61 of file point.h.

{ return os << x << " " << y; }
template<typename T>
void point2< T >::rotate90 ( )
inline

Rotate 90 degrees in a anti clockwise direction.

Definition at line 148 of file point.h.

Referenced by arc::distance(), and arc::distanceSquared().

{ T t=x; x=-y; y=t; }
template<typename T>
void point2< T >::serializeInverse ( stringc s)
inline

Interpret or read in the point.

Definition at line 55 of file point.h.

Referenced by operator>>(), pointtest::test03(), and mazematrixD2test::unittest01().

{ stringstream ss(s); ss >> x >> y; }
template<typename T>
istream& point2< T >::serializeInverse ( istream &  istr)
inline

Read in a point from a stream.

Definition at line 64 of file point.h.

{ return istr >> x >> y; }
template<typename T >
void point2< T >::serializeInverseBrackets ( stringc s)

Read the point in that is in human friendly format with brackets and a comma from the string.

Definition at line 574 of file point.h.

Referenced by maze003::maze003(), and boxOBBhalfspaceD2test::unittest02().

{
uintc sz(s.size());
string s2(s);
for (uint i=0; i<sz; ++i)
{
char ch = s[i];
if (ch=='(')
s2[i] = ' ';
if (ch==')')
s2[i] = ' ';
if (ch==',')
s2[i] = ' ';
}
}
template<typename T>
template<typename Z >
Z const point2< T >::sumInRatio ( Z const &  A,
Z const &  B 
) const
inline

Use this point as a ratio to sum two other numbers.

Definition at line 169 of file point.h.

{ assert(x+y!=0); return (A*x+B*y)/(x+y); }

Member Data Documentation

template<typename T>
T point2< T >::x

The x component/dimension.

Definition at line 36 of file point.h.

Referenced by mazematrixmapD2< T, W >::add(), ruler::addAngleRuler(), protractor::addCirclesText(), plotpolar::addcrosses(), plotpolar::adddatapointsinPolarDegrees(), plotpolar::adddatapointsinPolarRadians(), partitionstest::addpoint(), addpoint(), addpointinsidemesh(), addrandompointtomeshptvector(), ruler::addStraightRuler(), halfspaceD2draw::alphacalculate(), mazematrixD2createmaze< T >::buildpropermaze(), buttonpanel01::buttonpanel01(), maze001::celldraw(), mazedisp01::celldraw(), mazedisp02::celldraw(), mazedisp03::celldraw(), mazedisp02::celldraw2(), mazedisp03::celldraw2(), mazedisp03::cellmidpoint(), buttonpanel02::centerpos(), maze001::constructgraphics(), arc::constructPhi0TwoPoints(), arc::constructRadiusTwoPoints(), protractor::converttocartesian(), mazedisp03::currentposdraw(), d2arrow::d2arrow(), randomgenerator::domain(), point2< int >::dot(), d2simplexOutline::draw(), d2simplexFill::draw(), d3circlepartitiondraw::draw(), mazedisp01::draw(), mazedisp02::draw(), namefont::draw(), regionD2tessdisplaypoints< TS, Indx >::draw(), buttonpanel02::drawcircle(), polytopeD2tessdisp01< VPTS, VPOLY >::eval(), maze004::eval(), maze005::eval(), transrotate2D::eval(), mazedisp03::f01(), disk::intersects(), lineIntersection(), lineSegmentIntersection(), d2func::make(), simplexD1listlinked< VI, INDX >::makelinks(), d2homogeneous::matrixMultiply(), maze001::maze001(), maze003::maze003(), zprmouse::mouseratio(), zprmouse::mouseratioInv(), point2< int >::operator*(), point2< int >::operator*=(), point2< int >::operator+(), spiralindex< T >::operator++(), point2< int >::operator+=(), point2< int >::operator-(), point2< int >::operator-=(), point2< int >::operator/(), point2< int >::operator/=(), point2< int >::operator==(), operator>(), buttonpanel02::process(), halfspaceD2draw::rotate(), d2homogeneous::setTranslate(), bsptree001::special(), mazedisp03::staticgraphics(), halfspaceD2test::test01(), mathlibtest::test01(), delaunaysimpleD2test::test01(), test01(), test11(), timmingexperiment04(), d3circlepartitiondraw::translate(), d3tesstransform::translate(), buttonpanel02::update(), pathlinesegdraw::update(), spiralindex< T >::valid(), and zprmouse::world().

template<typename T>
T point2< T >::y

The y component/dimension.

Definition at line 38 of file point.h.

Referenced by mazematrixmapD2< T, W >::add(), ruler::addAngleRuler(), protractor::addCirclesText(), plotpolar::addcrosses(), plotpolar::adddatapointsinPolarDegrees(), plotpolar::adddatapointsinPolarRadians(), partitionstest::addpoint(), addpoint(), addpointinsidemesh(), addrandompointtomeshptvector(), ruler::addStraightRuler(), halfspaceD2draw::alphacalculate(), mazematrixD2createmaze< T >::buildpropermaze(), buttonpanel01::buttonpanel01(), maze001::celldraw(), mazedisp01::celldraw(), mazedisp02::celldraw(), mazedisp03::celldraw(), mazedisp02::celldraw2(), mazedisp03::celldraw2(), mazedisp03::cellmidpoint(), buttonpanel02::centerpos(), maze001::constructgraphics(), arc::constructPhi0TwoPoints(), arc::constructRadiusTwoPoints(), protractor::converttocartesian(), mazedisp03::currentposdraw(), d2arrow::d2arrow(), randomgenerator::domain(), point2< int >::dot(), d2simplexOutline::draw(), d2simplexFill::draw(), d3circlepartitiondraw::draw(), mazedisp01::draw(), mazedisp02::draw(), namefont::draw(), regionD2tessdisplaypoints< TS, Indx >::draw(), buttonpanel02::drawcircle(), polytopeD2tessdisp01< VPTS, VPOLY >::eval(), maze004::eval(), maze005::eval(), transrotate2D::eval(), mazedisp03::f01(), disk::intersects(), lineIntersection(), lineSegmentIntersection(), d2func::make(), simplexD1listlinked< VI, INDX >::makelinks(), d2homogeneous::matrixMultiply(), maze001::maze001(), maze003::maze003(), zprmouse::mouseratio(), zprmouse::mouseratioInv(), point2< int >::operator*(), point2< int >::operator*=(), point2< int >::operator+(), point2< int >::operator+=(), point2< int >::operator-(), point2< int >::operator-=(), point2< int >::operator/(), point2< int >::operator/=(), point2< int >::operator==(), operator>(), buttonpanel02::process(), halfspaceD2draw::rotate(), d2homogeneous::setTranslate(), bsptree001::special(), mazedisp03::staticgraphics(), halfspaceD2test::test01(), mathlibtest::test01(), test01(), test11(), timmingexperiment04(), d3circlepartitiondraw::translate(), d3tesstransform::translate(), buttonpanel02::update(), pathlinesegdraw::update(), spiralindex< T >::valid(), and zprmouse::world().


The documentation for this class was generated from the following file: