Debian Codegraph @

src/coordinate.cpp

raw symbols SCIP
1 // Copyright 2005 by Anthony Liekens [email protected]
2 #include <math.h>
3
4 #include "coordinate.h"
5
6 #include "settings.h"
7
8 Coordinate::Coordinate() {
9 x = y = 0;
10 }
11
12 Coordinate::Coordinate( double x, double y ) {
13 this->x = x;
14 this->y = y;
15 }
16
17 void
18 Coordinate::setX( double x ) {
19 this->x = x;
20 }
21
22 void
23 Coordinate::setY( double y ) {
24 this->y = y;
25 }
26
27 void
28 Coordinate::setXMapped( int x ) {
29 this->x = ( (double)x - Settings::getGameOffsetX() ) / Settings::getGameWidth();
30 }
31
32 void
33 Coordinate::setYMapped( int y ) {
34 this->y = (double)y / Settings::getGameHeight();
35 }
36
37 double
38 Coordinate::getX() const {
39 return x;
40 }
41
42 double
43 Coordinate::getY() const {
44 return y;
45 }
46
47 int
48 Coordinate::getXMapped() const {
49 return Settings::getGameOffsetX() + ( int )( Settings::getGameWidth() * x );
50 }
51
52 int
53 Coordinate::getYMapped() const {
54 return ( int )( Settings::getGameHeight() * y );
55 }
56
57 double
58 Coordinate::distance( const Coordinate& c ) const {
59 double dx = c.getX() - getX();
60 double dy = c.getY() - getY();
61 return sqrt( dx * dx + dy * dy );
62 }
63
64 bool
65 Coordinate::operator==( const Coordinate &that) const
66 {
67 return x == that.x && y == that.y;
68 }