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

kig

Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
Coordinate Class Reference

#include <coordinate.h>

Public Member Functions

 Coordinate (double x, double y)
 
 Coordinate (const Coordinate &p)
 
 Coordinate ()
 
 ~Coordinate ()
 
double distance (const Coordinate &p) const
 
double length () const
 
const Coordinate normalize (double length=1) const
 
Coordinate & operator*= (double r)
 
Coordinate & operator*= (int 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
 

Static Public Member Functions

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

Public Attributes

double x
 
double y
 

Friends

bool operator!= (const Coordinate &, const Coordinate &)
 
const Coordinate operator* (const Coordinate &a, double r)
 
double operator* (const Coordinate &a, const Coordinate &b)
 
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 &)
 

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.

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

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*= ( double  r)

Scale.

Scales this Coordinate by a factor r

Definition at line 118 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+= ( 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

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,
double  r 
)
friend

Scale.

Returns this a, scaled by a factor of r.

Definition at line 49 of file coordinate.cpp.

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,
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal