-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinate.hpp
57 lines (48 loc) · 1.45 KB
/
coordinate.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// ---------------------------------------------------------------------------
// This software is in the public domain, furnished "as is", without technical
// support, and with no warranty, express or implied, as to its usefulness for
// any purpose.
//
// COORDINATE.HPP
// Represents a latitude / longitude coordinate
//
// Author: Thomas Brüggemann
// ---------------------------------------------------------------------------
#ifndef COORDINATE_HPP
#define COORDINATE_HPP
#include <string>
#include "patches.hpp"
class Coordinate
{
public:
double longitude;
double latitude;
Coordinate();
Coordinate(double lon, double lat);
inline std::string toString();
inline int isLeft(Coordinate startLine, Coordinate endLine);
};
Coordinate::Coordinate()
{
};
Coordinate::Coordinate(double lon, double lat)
{
this->longitude = lon;
this->latitude = lat;
};
// TO STRING
inline std::string Coordinate::toString()
{
std::string result = "(" + patches::to_string(this->longitude) + ", " + patches::to_string(this->latitude) + ")";
return result;
};
// IS LEFT
// Return: >0 for point left of the line through start and end
// =0 for point on the line
// <0 for point right of the line
inline int Coordinate::isLeft(Coordinate startLine, Coordinate endLine)
{
return ((endLine.longitude - startLine.longitude) * (this->latitude - startLine.latitude)
- (this->longitude - startLine.longitude) * (endLine.latitude - startLine.latitude));
};
#endif