• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kig

Coordinate Class Reference

#include <coordinate.h>

List of all members.


Detailed Description

The Coordinate class is the basic class representing a 2D location by its x and y components.

It has all relevant arithmetic operators properly defined, and should be straightforward to use..

Definition at line 33 of file coordinate.h.


Public Member Functions

 Coordinate ()
 Coordinate (const Coordinate &p)
 Coordinate (double x, double y)
double distance (const Coordinate &p) const
double length () const
const Coordinate normalize (double length=1) const
Coordinate & operator *= (int r)
Coordinate & operator *= (double r)
Coordinate & operator+= (const Coordinate &c)
const Coordinate operator- () const
Coordinate & operator-= (const Coordinate &c)
Coordinate & operator/= (double r)
Coordinate & operator= (const Coordinate &c)
const Coordinate orthogonal () const
const Coordinate round () const
double squareLength () const
QPoint toQPoint () const
bool valid () const
 ~Coordinate ()

Static Public Member Functions

static Coordinate fromQPoint (const QPoint &p)
static Coordinate invalidCoord ()

Public Attributes

double x
double y

Friends

double operator * (const Coordinate &a, const Coordinate &b)
const Coordinate operator * (const Coordinate &a, double r)
bool operator!= (const Coordinate &, const Coordinate &)
const Coordinate operator+ (const Coordinate &a, const Coordinate &b)
const Coordinate operator- (const Coordinate &a, const Coordinate &b)
const Coordinate operator/ (const Coordinate &a, double r)
QDebug & operator<< (QDebug &s, const Coordinate &t)
bool operator== (const Coordinate &, const Coordinate &)

Constructor & Destructor Documentation

Coordinate::Coordinate ( double  x,
double  y 
)

Constructor.

Construct a new Coordinate, with a given x and y value.

Definition at line 80 of file coordinate.cpp.

Coordinate::Coordinate ( const Coordinate &  p  ) 

Copy Constructor.

Construct a new Coordinate, and give it the same value as p.

Definition at line 86 of file coordinate.cpp.

Coordinate::Coordinate (  ) 

Default Constructor.

Constructs a new Coordinate, with x and y initialized to 0.

Definition at line 74 of file coordinate.cpp.

Coordinate::~Coordinate (  )  [inline]

Definition at line 54 of file coordinate.h.


Member Function Documentation

double Coordinate::distance ( const Coordinate &  p  )  const

Distance to another Coordinate.

Definition at line 139 of file coordinate.cpp.

Coordinate Coordinate::fromQPoint ( const QPoint &  p  )  [static]

Definition at line 28 of file coordinate.cpp.

Coordinate Coordinate::invalidCoord (  )  [static]

Create an invalid Coordinate.

This is a special value of a Coordinate that signals that something went wrong..

See also:
Coordinate::valid

For internal use only.

We represent an invalid coordinate by setting x or y to positive or negative infinity. This is handy, since it doesn't require us to adapt most of the functions, it doesn't need extra space, and most of the times that we should get an invalid coord, we get one automatically..

Definition at line 171 of file coordinate.cpp.

double Coordinate::length (  )  const

Length.

Returns the length or norm of this coordinate. I.e. return the distance from this Coordinate to the origin.

See also:
squareLength

Definition at line 144 of file coordinate.cpp.

const Coordinate Coordinate::normalize ( double  length = 1  )  const

Normalize.

This sets the length to length, while keeping the x/y ratio untouched...

Definition at line 154 of file coordinate.cpp.

Coordinate & Coordinate::operator *= ( int  r  ) 

Scale.

Scales this Coordinate by a factor r

Definition at line 125 of file coordinate.cpp.

Coordinate & Coordinate::operator *= ( double  r  ) 

Scale.

Scales this Coordinate by a factor r

Definition at line 118 of file coordinate.cpp.

Coordinate & Coordinate::operator+= ( const Coordinate &  c  ) 

Add.

Add c to this Coordinate

Definition at line 104 of file coordinate.cpp.

const Coordinate Coordinate::operator- (  )  const

Inverse.

Returns the inverse of this Coordinate.

Definition at line 92 of file coordinate.cpp.

Coordinate & Coordinate::operator-= ( const Coordinate &  c  ) 

Subtract.

Subtract c from this Coordinate

Definition at line 111 of file coordinate.cpp.

Coordinate & Coordinate::operator/= ( double  r  ) 

Scale.

Scales this Coordinate by a factor 1/r

Definition at line 132 of file coordinate.cpp.

Coordinate & Coordinate::operator= ( const Coordinate &  c  ) 

Definition at line 97 of file coordinate.cpp.

const Coordinate Coordinate::orthogonal (  )  const

Orthogonal.

Returns a vector which is orthogonal on this vector. This relation always holds:

 Coordinate a = ...;
 assert( a*a.orthogonal() ) == 0;
 

Definition at line 149 of file coordinate.cpp.

const Coordinate Coordinate::round (  )  const

Round.

Returns this coordinate, rounded to the nearest integral values.

Definition at line 160 of file coordinate.cpp.

double Coordinate::squareLength (  )  const [inline]

Square length.

Equivalent to the square of length, but a bit more efficient because no square root has to be calculated.

See also:
length

Definition at line 163 of file coordinate.h.

QPoint Coordinate::toQPoint (  )  const

Definition at line 165 of file coordinate.cpp.

bool Coordinate::valid (  )  const

Return whether this is a valid Coordinate.

See also:
Coordinate::invalidCoord

Definition at line 176 of file coordinate.cpp.


Friends And Related Function Documentation

double operator * ( const Coordinate &  a,
const Coordinate &  b 
) [friend]

Scalar Product.

Returns the scalar product of a and b.

Definition at line 181 of file coordinate.cpp.

const Coordinate operator * ( const Coordinate &  a,
double  r 
) [friend]

Scale.

Returns this a, scaled by a factor of r.

Definition at line 49 of file coordinate.cpp.

bool operator!= ( const Coordinate &  a,
const Coordinate &  b 
) [friend]

Not Equal.

Tests two Coordinates for inequality.

Definition at line 69 of file coordinate.cpp.

const Coordinate operator+ ( const Coordinate &  a,
const Coordinate &  b 
) [friend]

Add.

Returns the sum of a and b.

Definition at line 39 of file coordinate.cpp.

const Coordinate operator- ( const Coordinate &  a,
const Coordinate &  b 
) [friend]

Subtract.

Returns the difference between a and b.

Definition at line 44 of file coordinate.cpp.

const Coordinate operator/ ( const Coordinate &  a,
double  r 
) [friend]

Scale.

Returns a, scaled by a factor of 1/r.

Definition at line 59 of file coordinate.cpp.

QDebug& operator<< ( QDebug &  s,
const Coordinate &  t 
) [friend]

Definition at line 33 of file coordinate.cpp.

bool operator== ( const Coordinate &  a,
const Coordinate &  b 
) [friend]

Equal.

Tests two Coordinates for equality.

Definition at line 64 of file coordinate.cpp.


Member Data Documentation

double Coordinate::x

X Component.

The X Component of this Coordinate.

Definition at line 126 of file coordinate.h.

double Coordinate::y

Y Component.

The Y Component of this Coordinate.

Definition at line 129 of file coordinate.h.


The documentation for this class was generated from the following files:
  • coordinate.h
  • coordinate.cpp

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal