-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructs.hpp
More file actions
88 lines (76 loc) · 2.08 KB
/
structs.hpp
File metadata and controls
88 lines (76 loc) · 2.08 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file structs.hpp
* @author The CS2 TA Team
* @version 1.0
* @date 2013-2015
* @copyright This code is in the public domain.
*
* @brief The Tuple struct for representing lattice point in the Euclidean
* 2-D plane.
*/
#ifndef __STRUCTS_H__
#define __STRUCTS_H__
#include <cmath>
#include <iostream>
using namespace std;
/**
* @brief Struct representing a lattice point in the (Euclidean) 2-D plane.
*
* The Tuple struct is a representation of a lattice point in the (Euclidean)
* 2-D plane. The stuct provides functionalities such as printing and angle
* computations.
*/
struct Tuple
{
/**
* @brief Represents the x-coordinate of the point
*/
int x;
/**
* @brief Represents the y-coordinate of the point
*/
int y;
/**
* @brief Initializes the struct
*
* @param x: first argument representing the x-coordinate
* @param y: second argument representing the y-coordinate
*/
Tuple(int x, int y)
{
this->x = x;
this->y = y;
}
/**
* @brief Prints the tuple in a human-readable format of (x, y)
*/
void printTuple()
{
cout << "(" << x << ", " << y << ")" << endl;
}
/**
* @brief Computes the angle with respect to the positive x axis
* @returns angle that this point makes with respect to positive x axis.
*/
double angle_wrt_x_axis()
{
return atan2((double) this->y, (double) this->x);
}
/**
* @brief Computes the angle that the line joining this point to the
* passed point makes with respect to the horizontal line
* going through the passed point.
*
* @param pt: Pointer to point through which we draw a horizontal line and
* compute angle relative to.
* @returns Angle that the two points make relative to x axis defined by
* passed point.
*/
double angle_wrt_pt(Tuple *pt)
{
double dy = (double) this->y - (double) pt->y;
double dx = (double) this->x - (double) pt->x;
return atan2(dy, dx);
}
};
#endif