Flatland
types.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name types.h
11  * @brief Defines common types in flatland
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #include <Box2D/Box2D.h>
48 #include <geometry_msgs/Pose2D.h>
49 
50 #ifndef FLATLAND_SERVER_TYPES_H
51 #define FLATLAND_SERVER_TYPES_H
52 
53 namespace flatland_server {
54 
55 struct Vec2 {
56  double x;
57  double y;
58 
59  Vec2(double x, double y) {
60  this->x = x;
61  this->y = y;
62  }
63 
64  Vec2() : x(0), y(0) {}
65 
66  b2Vec2 Box2D() const { return b2Vec2(x, y); }
67 };
68 
69 struct LineSegment {
70  Vec2 start;
71  Vec2 end;
72 
73  LineSegment(const Vec2 &start, const Vec2 &end) {
74  this->start = start;
75  this->end = end;
76  }
77 
78  LineSegment() {
79  this->start = Vec2(0, 0);
80  this->end = Vec2(0, 0);
81  }
82 };
83 
84 struct Pose {
85  double x;
86  double y;
87  double theta;
88 
89  Pose(double x, double y, double theta) {
90  this->x = x;
91  this->y = y;
92  this->theta = theta;
93  }
94 
95  Pose(const std::array<double, 3> &p) {
96  this->x = p[0];
97  this->y = p[1];
98  this->theta = p[3];
99  }
100 
101  Pose() : x(0), y(0), theta(0) {}
102 
103  bool operator==(const Pose &p) const {
104  return x == p.x && y == p.y && theta == p.theta;
105  }
106 
107  bool operator!=(const Pose &p) const { return !operator==(p); }
108 };
109 
110 struct Color {
111  double r, g, b, a;
112 
113  Color() : r(0), g(0), b(0), a(0) {}
114 
115  Color(double r, double g, double b, double a) {
116  this->r = r;
117  this->g = g;
118  this->b = b;
119  this->a = a;
120  }
121 
122  Color(const std::array<double, 4> &c) {
123  this->r = c[0];
124  this->g = c[1];
125  this->b = c[2];
126  this->a = c[3];
127  }
128 
129  bool operator==(const Color &c) const {
130  return r == c.r && g == c.g && b == c.b && a == c.a;
131  }
132 
133  bool operator!=(const Color &c) const { return !operator==(c); }
134 };
135 }
136 
137 #endif
Definition: body.h:55
Definition: types.h:84
Definition: types.h:55
Definition: types.h:110
double theta
theta
Definition: types.h:87
Definition: types.h:69