1 // Copyright 2005 by Anthony Liekens anthony@liekens.net
2 #include <math.h>
3 
4 #include "coordinate.h"
5 
6 #include "settings.h"
7 
Coordinate()8 Coordinate::Coordinate() {
9 	x = y = 0;
10 }
11 
Coordinate(double x,double y)12 Coordinate::Coordinate( double x, double y ) {
13 	this->x = x;
14 	this->y = y;
15 }
16 
17 void
setX(double x)18 Coordinate::setX( double x ) {
19 	this->x = x;
20 }
21 
22 void
setY(double y)23 Coordinate::setY( double y ) {
24 	this->y = y;
25 }
26 
27 void
setXMapped(int x)28 Coordinate::setXMapped( int x ) {
29 	this->x = ( (double)x - Settings::getGameOffsetX() ) / Settings::getGameWidth();
30 }
31 
32 void
setYMapped(int y)33 Coordinate::setYMapped( int y ) {
34 	this->y = (double)y / Settings::getGameHeight();
35 }
36 
37 double
getX() const38 Coordinate::getX() const {
39 	return x;
40 }
41 
42 double
getY() const43 Coordinate::getY() const {
44 	return y;
45 }
46 
47 int
getXMapped() const48 Coordinate::getXMapped() const {
49 	return Settings::getGameOffsetX() + ( int )( Settings::getGameWidth() * x );
50 }
51 
52 int
getYMapped() const53 Coordinate::getYMapped() const {
54 	return ( int )( Settings::getGameHeight() * y );
55 }
56 
57 double
distance(const Coordinate & c) const58 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
operator ==(const Coordinate & that) const65 Coordinate::operator==( const Coordinate &that) const
66 {
67   return x == that.x && y == that.y;
68 }
69