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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • misc
coordinate.cpp
Go to the documentation of this file.
1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "coordinate.h"
19 
20 #include <qglobal.h>
21 #include <cmath>
22 #include <kdebug.h>
23 
24 #include "common.h"
25 
26 using namespace std;
27 
28 Coordinate Coordinate::fromQPoint( const QPoint& p )
29 {
30  return Coordinate( p.x(), p.y() );
31 }
32 
33 QDebug& operator<<( QDebug& s, const Coordinate& t )
34 {
35  s << "x:" << t.x << "y:" << t.y;
36  return s;
37 }
38 
39 const Coordinate operator+ ( const Coordinate& a, const Coordinate& b )
40 {
41  return Coordinate ( a.x + b.x, a.y + b.y );
42 }
43 
44 const Coordinate operator- ( const Coordinate& a, const Coordinate& b )
45 {
46  return Coordinate ( a.x - b.x, a.y - b.y );
47 }
48 
49 const Coordinate operator* ( const Coordinate& a, double r )
50 {
51  return Coordinate ( r*a.x, r*a.y );
52 }
53 
54 const Coordinate operator* ( double r, const Coordinate& a )
55 {
56  return Coordinate ( r*a.x, r*a.y );
57 }
58 
59 const Coordinate operator/ ( const Coordinate& a, double r )
60 {
61  return Coordinate ( a.x/r, a.y/r );
62 }
63 
64 bool operator==( const Coordinate& a, const Coordinate& b )
65 {
66  return a.x == b.x && a.y == b.y;
67 }
68 
69 bool operator!=( const Coordinate& a, const Coordinate& b )
70 {
71  return !operator==( a, b );
72 }
73 
74 Coordinate::Coordinate()
75  : x(0),
76  y(0)
77 {
78 }
79 
80 Coordinate::Coordinate( double nx, double ny )
81  : x( nx ),
82  y( ny )
83 {
84 }
85 
86 Coordinate::Coordinate( const Coordinate& p )
87  : x( p.x ),
88  y( p.y )
89 {
90 }
91 
92 const Coordinate Coordinate::operator-() const
93 {
94  return Coordinate ( -x, -y );
95 }
96 
97 Coordinate& Coordinate::operator=( const Coordinate& p )
98 {
99  x = p.x;
100  y = p.y;
101  return *this;
102 }
103 
104 Coordinate& Coordinate::operator+=( const Coordinate& p )
105 {
106  x += p.x;
107  y += p.y;
108  return *this;
109 }
110 
111 Coordinate& Coordinate::operator-=( const Coordinate& p )
112 {
113  x -= p.x;
114  y -= p.y;
115  return *this;
116 }
117 
118 Coordinate& Coordinate::operator*=( double r )
119 {
120  x *= r;
121  y *= r;
122  return *this;
123 }
124 
125 Coordinate& Coordinate::operator*=( int r )
126 {
127  x *= r;
128  y *= r;
129  return *this;
130 }
131 
132 Coordinate& Coordinate::operator/=( double r )
133 {
134  x /= r;
135  y /= r;
136  return *this;
137 }
138 
139 double Coordinate::distance( const Coordinate& p ) const
140 {
141  return (p - *this).length();
142 }
143 
144 double Coordinate::length() const
145 {
146  return sqrt(x*x+y*y);
147 }
148 
149 const Coordinate Coordinate::orthogonal() const
150 {
151  return Coordinate( -y, x );
152 }
153 
154 const Coordinate Coordinate::normalize( double l ) const
155 {
156  double oldlength = length();
157  return ( *this * l ) / oldlength;
158 }
159 
160 const Coordinate Coordinate::round() const
161 {
162  return Coordinate( qRound( x ), qRound( y ) );
163 }
164 
165 QPoint Coordinate::toQPoint() const
166 {
167  Coordinate t = round();
168  return QPoint( (int) t.x, (int) t.y );
169 }
170 
171 Coordinate Coordinate::invalidCoord()
172 {
173  return Coordinate( double_inf, double_inf );
174 }
175 
176 bool Coordinate::valid() const
177 {
178  return fabs( x ) != double_inf && fabs( y ) != double_inf;
179 }
180 
181 double operator*( const Coordinate& a, const Coordinate& b )
182 {
183  return a.x * b.x + a.y * b.y;
184 }
Coordinate::operator+=
Coordinate & operator+=(const Coordinate &c)
Add.
Definition: coordinate.cpp:104
operator+
const Coordinate operator+(const Coordinate &a, const Coordinate &b)
Definition: coordinate.cpp:39
Coordinate::toQPoint
QPoint toQPoint() const
Definition: coordinate.cpp:165
operator/
const Coordinate operator/(const Coordinate &a, double r)
Definition: coordinate.cpp:59
operator!=
bool operator!=(const Coordinate &a, const Coordinate &b)
Definition: coordinate.cpp:69
Coordinate::Coordinate
Coordinate()
Default Constructor.
Definition: coordinate.cpp:74
Coordinate::operator-=
Coordinate & operator-=(const Coordinate &c)
Subtract.
Definition: coordinate.cpp:111
Coordinate::operator=
Coordinate & operator=(const Coordinate &c)
Definition: coordinate.cpp:97
operator-
const Coordinate operator-(const Coordinate &a, const Coordinate &b)
Definition: coordinate.cpp:44
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
Coordinate::length
double length() const
Length.
Definition: coordinate.cpp:144
Coordinate::normalize
const Coordinate normalize(double length=1) const
Normalize.
Definition: coordinate.cpp:154
Coordinate::operator*=
Coordinate & operator*=(double r)
Scale.
Definition: coordinate.cpp:118
Coordinate::operator-
const Coordinate operator-() const
Inverse.
Definition: coordinate.cpp:92
Coordinate::distance
double distance(const Coordinate &p) const
Distance to another Coordinate.
Definition: coordinate.cpp:139
operator==
bool operator==(const Coordinate &a, const Coordinate &b)
Definition: coordinate.cpp:64
Coordinate::fromQPoint
static Coordinate fromQPoint(const QPoint &p)
Definition: coordinate.cpp:28
common.h
operator*
const Coordinate operator*(const Coordinate &a, double r)
Definition: coordinate.cpp:49
Coordinate::invalidCoord
static Coordinate invalidCoord()
Create an invalid Coordinate.
Definition: coordinate.cpp:171
double_inf
const double double_inf
Definition: common.cpp:509
operator<<
QDebug & operator<<(QDebug &s, const Coordinate &t)
Definition: coordinate.cpp:33
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
Coordinate::orthogonal
const Coordinate orthogonal() const
Orthogonal.
Definition: coordinate.cpp:149
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
Coordinate::operator/=
Coordinate & operator/=(double r)
Scale.
Definition: coordinate.cpp:132
coordinate.h
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
Coordinate::round
const Coordinate round() const
Round.
Definition: coordinate.cpp:160
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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