Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 8d0c3fa

Browse files
committed
templated PlaneStateSpace
1 parent 11c52aa commit 8d0c3fa

File tree

5 files changed

+29
-55
lines changed

5 files changed

+29
-55
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ set(lib_SRC
5050
"src/rrt/2dplane/2dplane.cpp"
5151
"src/rrt/2dplane/GridStateSpace.cpp"
5252
"src/rrt/2dplane/ObstacleGrid.cpp"
53-
"src/rrt/2dplane/PlaneStateSpace.cpp"
5453
)
5554

5655
add_library("RRT" STATIC ${lib_SRC})

src/rrt/2dplane/GridStateSpace.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace RRT {
1010
* @brief A 2d plane with continuous states and discretized obstacles.
1111
* @details The state space is broken up into a grid with the given discrete height and widths.
1212
*/
13-
class GridStateSpace : public PlaneStateSpace {
13+
class GridStateSpace : public PlaneStateSpace<Eigen::Vector2f> {
1414
public:
1515
GridStateSpace(float width, float height, int discretizedWidth, int discretizedHeight);
1616

src/rrt/2dplane/PlaneStateSpace.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/rrt/2dplane/PlaneStateSpace.hpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,41 @@ namespace RRT {
88
/**
99
* @brief A 2d plane with continuous states and no obstacles.
1010
*/
11-
class PlaneStateSpace : public StateSpace<Eigen::Vector2f> {
11+
template<class POINT_CLASS = Eigen::Vector2f>
12+
class PlaneStateSpace : public StateSpace<POINT_CLASS> {
1213
public:
13-
PlaneStateSpace(float width, float height);
14+
PlaneStateSpace(float width, float height) : _width(width), _height(height) {}
1415

15-
Eigen::Vector2f randomState() const;
16+
POINT_CLASS randomState() const {
17+
return POINT_CLASS(drand48() * width(), drand48() * height());
18+
}
1619

17-
Eigen::Vector2f intermediateState(const Eigen::Vector2f &source, const Eigen::Vector2f &target, float stepSize) const;
20+
POINT_CLASS intermediateState(const POINT_CLASS &source, const POINT_CLASS &target, float stepSize) const {
21+
POINT_CLASS delta = target - source;
22+
delta = delta / delta.norm(); // unit vector
23+
24+
POINT_CLASS val = source + delta * stepSize;
25+
return val;
26+
}
1827

19-
double distance(const Eigen::Vector2f &from, const Eigen::Vector2f &to) const;
28+
29+
double distance(const POINT_CLASS &from, const POINT_CLASS &to) const {
30+
POINT_CLASS delta = from - to;
31+
return sqrtf(powf(delta.x(), 2) + powf(delta.y(), 2));
32+
}
2033

2134
/**
2235
* Returns a boolean indicating whether the given point is within bounds.
2336
*/
24-
bool stateValid(const Eigen::Vector2f &pt) const;
25-
26-
float width() const;
27-
float height() const;
37+
bool stateValid(const POINT_CLASS &pt) const {
38+
return pt.x() >= 0
39+
&& pt.y() >= 0
40+
&& pt.x() < width()
41+
&& pt.y() < height();
42+
}
43+
44+
float width() const { return _width; }
45+
float height() const { return _height; }
2846

2947

3048
private:

third_party/style-configs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 90cc111f04dc1baee0a99f75a5c850282b54bcde

0 commit comments

Comments
 (0)