proj home

Files   Classes   Functions   Hierarchy  

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

List of all members.

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.

00041 : 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.

00043 : 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(), point2< int >::normalize(), halfspaceD2draw::rotate(), linetest::test01(), and mathlibtest::test015().

00161     { return sqrt(x*x + y*y); }

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.

00157     { return x*w.x + y*w.y; }

template<typename T>
T const point2< T >::dot (  )  const [inline]
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.

00174   {
00175     if (x<(T)0)
00176       return false;
00177     if (y<(T)0)
00178       return false;
00179  
00180     if (x>(T)1)
00181       return false;
00182     if (y>(T)1)
00183       return false;
00184 
00185     return true;
00186   }

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().

00165     { 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.

00047   { 
00048     string s;
00049     { stringstream ss; ss << x; s+=ss.str(); }
00050     s += " ";
00051     { stringstream ss; ss << y; s+=ss.str(); }
00052     return s;
00053   }

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.

00135     { if (x!=w.x) return true; if (y!=w.y) return true; return false; }

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.

00123     { point2<T> z(*this); z.x*=p; z.y*=p; return z; }

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.

00087     { point2<T> z(*this); z*=p; return z; }

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.

00119     { x*=w; y*=w; return *this; }

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.

00084     { x*=p.x; y*=p.y; return *this; }

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.

00107     { point2<T> z(*this); z.x+=w; z.y+=w; return z; }

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.

00074     { point2<T> z(*this); z+=p; return z; }

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.

00103     { x+=w; y+=w; return *this; }

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.

00071     { x+=p.x; y+=p.y; return *this; }

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.

00115     { point2<T> z(*this); z.x-=w; z.y-=w; return z; }

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.

00080       { point2<T> z(*this); z-=p; return z; } seg faulted?
00081     { return point2<T>(this->x-p.x,this->y-p.y); } // seg faulted too.

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.

00111     { x-=w; y-=w; return *this; }

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.

00077     { x-=p.x; y-=p.y; return *this; }

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.

00131     { point2<T> z(*this); z.x/=p; z.y/=p; return z; }

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.

00093     { point2<T> z(*this); z/=p; return z; }

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.

00127     { x/=w; y/=w; return *this; }

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.

00090     { x/=p.x; y/=p.y; 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.

00098     { return (x==p.x)&&(y==p.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.

00143     { assert(i<2); if ((i%2)==0) return x; return 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.

00140     { 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.

00062     { 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().

00149     { T t=x; x=-y; y=t; }

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.

00065     { return istr >> x >> y; }

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>>(), point2< T >::serializeInverseBrackets(), pointtest::test03(), and mazematrixD2test::unittest01().

00056     {  stringstream ss(s); ss >> x >> y; }

template<typename T >
void point2< T >::serializeInverseBrackets ( stringc s  )  [inline]

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.

References point2< T >::serializeInverse().

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

00575 {
00576   uintc sz(s.size());
00577   string s2(s);
00578 
00579   for (uint i=0; i<sz; ++i)
00580   {
00581     char ch = s[i];
00582     if (ch=='(')
00583       s2[i] = ' '; 
00584     if (ch==')')
00585       s2[i] = ' '; 
00586     if (ch==',')
00587       s2[i] = ' '; 
00588   }
00589 
00590   serializeInverse(s2);
00591 }

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.

00170     { 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(), menusystem::addnewline(), partitionstest::addpoint(), addpoint(), addpointinsidemesh(), addrandompointtomeshptvector(), ruler::addStraightRuler(), halfspaceD2draw::alphacalculate(), mazematrixD2createmaze< T >::buildpropermaze(), buttonpanel01::buttonpanel01(), mazedisp03::celldraw(), mazedisp02::celldraw(), mazedisp01::celldraw(), maze001::celldraw(), mazedisp03::celldraw2(), mazedisp02::celldraw2(), mazedisp03::cellmidpoint(), buttonpanel02::centerpos(), maze001::constructgraphics(), arc::constructPhi0TwoPoints(), arcsconnected::constructR0(), arc::constructRadiusTwoPoints(), protractor::converttocartesian(), mazedisp03::currentposdraw(), d2arrow::d2arrow(), point2< int >::distance(), randomgenerator::domain(), point2< int >::dot(), mazedisp02::draw(), mazedisp01::draw(), d2simplexFill::draw(), d2simplexOutline::draw(), namefont::draw(), regionD2tessdisplaypoints< TS, Indx >::draw(), d3circlepartitiondraw::draw(), buttonpanel02::drawcircle(), maze005::eval(), maze004::eval(), transrotate2D::eval(), polytopeD2tessdisp01< VPTS, VPOLY >::eval(), mazedisp03::f01(), disk::intersects(), point2< int >::isinsideunitbox(), circleD2test::keyboard01(), boxOBBhalfspaceD2test::keyboard01(), lineIntersection(), lineSegmentIntersection(), d2func::make(), simplexD1listlinked< VI, INDX >::makelinks(), d2homogeneous::matrixMultiply(), maze001::maze001(), maze003::maze003(), zprmouse::mouseratio(), zprmouse::mouseratioInv(), point2< int >::operator stringc(), 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/=(), point2< int >::operator==(), operator>(), point2< int >::operator[](), point2< int >::print(), buttonpanel02::process(), menusystem::reset(), halfspaceD2draw::rotate(), point2< int >::rotate90(), point2< int >::serializeInverse(), d2homogeneous::setTranslate(), bsptree001::special(), mazedisp03::staticgraphics(), point2< int >::sumInRatio(), mathlibtest::test01(), halfspaceD2test::test01(), test01(), test11(), timmingexperiment04(), d3circlepartitiondraw::translate(), d3tesstransform::translate(), buttonpanel02::update(), pathlinesegdraw::update(), circleD2test::update01(), 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(), menusystem::addnewline(), partitionstest::addpoint(), addpoint(), addpointinsidemesh(), addrandompointtomeshptvector(), ruler::addStraightRuler(), halfspaceD2draw::alphacalculate(), mazematrixD2createmaze< T >::buildpropermaze(), buttonpanel01::buttonpanel01(), mazedisp03::celldraw(), mazedisp02::celldraw(), mazedisp01::celldraw(), maze001::celldraw(), mazedisp03::celldraw2(), mazedisp02::celldraw2(), mazedisp03::cellmidpoint(), buttonpanel02::centerpos(), maze001::constructgraphics(), arc::constructPhi0TwoPoints(), arc::constructRadiusTwoPoints(), protractor::converttocartesian(), mazedisp03::currentposdraw(), d2arrow::d2arrow(), point2< int >::distance(), randomgenerator::domain(), point2< int >::dot(), mazedisp02::draw(), mazedisp01::draw(), d2simplexFill::draw(), d2simplexOutline::draw(), namefont::draw(), regionD2tessdisplaypoints< TS, Indx >::draw(), d3circlepartitiondraw::draw(), buttonpanel02::drawcircle(), maze005::eval(), maze004::eval(), transrotate2D::eval(), polytopeD2tessdisp01< VPTS, VPOLY >::eval(), mazedisp03::f01(), disk::intersects(), point2< int >::isinsideunitbox(), circleD2test::keyboard01(), boxOBBhalfspaceD2test::keyboard01(), lineIntersection(), lineSegmentIntersection(), d2func::make(), simplexD1listlinked< VI, INDX >::makelinks(), d2homogeneous::matrixMultiply(), maze001::maze001(), maze003::maze003(), zprmouse::mouseratio(), zprmouse::mouseratioInv(), point2< int >::operator stringc(), 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/=(), point2< int >::operator==(), operator>(), point2< int >::operator[](), point2< int >::print(), buttonpanel02::process(), menusystem::reset(), halfspaceD2draw::rotate(), point2< int >::rotate90(), point2< int >::serializeInverse(), d2homogeneous::setTranslate(), bsptree001::special(), mazedisp03::staticgraphics(), point2< int >::sumInRatio(), mathlibtest::test01(), halfspaceD2test::test01(), test01(), test11(), timmingexperiment04(), d3circlepartitiondraw::translate(), d3tesstransform::translate(), buttonpanel02::update(), pathlinesegdraw::update(), circleD2test::update01(), spiralindex< T >::valid(), and zprmouse::world().


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

Generated on 27 Nov 2012 for Chelton Evans Source by  doxygen 1.6.1