Refactored interface

This commit is contained in:
Marc 2018-10-24 21:58:42 +02:00
parent f71f31f174
commit ffb4452acf
12 changed files with 282 additions and 335 deletions

View File

@ -6,39 +6,40 @@
#pragma once
#include "carla/road/element/RoadSegment.h"
#include "carla/Memory.h"
#include "carla/Optional.h"
#include "carla/NonCopyable.h"
#include "carla/road/MapData.h"
#include "carla/road/element/Waypoint.h"
#include <map>
namespace carla {
namespace road {
class Map {
class Map
: EnableSharedFromThis<Map>,
private MovableNonCopyable {
public:
Map(const Map &) = delete;
Map &operator=(const Map &) = delete;
element::Waypoint GetClosestWaypointOnRoad(const geom::Location &) const {
return element::Waypoint();
}
Map(Map &&) = default;
Map &operator=(Map &&) = default;
Optional<element::Waypoint> GetWaypoint(const geom::Location &) const {
return Optional<element::Waypoint>();
}
bool ExistId(element::id_type id) const;
const MapData &GetData() {
return _data;
}
const element::RoadSegment *GetRoad(element::id_type id) const;
std::vector<element::id_type> GetAllIds() const;
uint32_t GetRoadCount() const;
const element::RoadSegment &NearestRoad(const geom::Location &loc);
Map(MapData m)
: _data(std::move(m)) {}
private:
friend class MapBuilder;
MapData _data;
Map() {}
std::map<element::id_type, std::unique_ptr<element::RoadSegment>> _elements;
};
} // namespace road

View File

@ -23,7 +23,7 @@ namespace road {
}
// Set the total length of each road based on the geometries
for (auto &&id_seg :_map._elements) {
for (auto &&id_seg :_map_data._elements) {
double total_length = 0.0;
for (auto &&geom : id_seg.second.get()->_geom) {
total_length += geom.get()->GetLength();
@ -34,17 +34,17 @@ namespace road {
// Create the pointers between RoadSegments based on the ids
for (auto &&id_seg : _temp_sections) {
for (auto &t : id_seg.second.GetPredecessorID()) {
_map._elements[id_seg.first]->PredEmplaceBack(_map._elements[t].get());
_map_data._elements[id_seg.first]->PredEmplaceBack(_map_data._elements[t].get());
}
for (auto &t : id_seg.second.GetSuccessorID()) {
_map._elements[id_seg.first]->SuccEmplaceBack(_map._elements[t].get());
_map_data._elements[id_seg.first]->SuccEmplaceBack(_map_data._elements[t].get());
}
}
// _map is a memeber of MapBuilder so you must especify if
// _map_data is a memeber of MapBuilder so you must especify if
// you want to keep it (will return copy -> Map(const Map &))
// or move it (will return move -> Map(Map &&))
return std::move(_map);
return Map(std::move(_map_data));
}
bool MapBuilder::InterpretRoadFlow() {

View File

@ -27,7 +27,7 @@ namespace road {
T &MakeElement(element::id_type id, Args && ... args) {
auto inst = std::make_unique<T>(std::forward<Args>(args) ...);
T &r = *inst;
_map._elements.emplace(id, std::move(inst));
_map_data._elements.emplace(id, std::move(inst));
return r;
}
@ -35,7 +35,7 @@ namespace road {
private:
Map _map;
MapData _map_data;
std::map<element::id_type, element::RoadSegmentDefinition> _temp_sections;
};

View File

@ -0,0 +1,38 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/road/MapData.h"
using namespace carla::road::element;
namespace carla {
namespace road {
bool MapData::ExistId(id_type id) const {
return _elements.count(id);
}
const RoadSegment *MapData::GetRoad(id_type id) const {
if (ExistId(id)) {
return _elements.find(id)->second.get();
}
return nullptr;
}
std::vector<id_type> MapData::GetAllIds() const {
std::vector<id_type> result;
for (auto &&e : _elements) {
result.emplace_back(e.first);
}
return result;
}
uint32_t MapData::GetRoadCount() const {
return _elements.size();
}
} // namespace road
} // namespace carla

View File

@ -0,0 +1,42 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/NonCopyable.h"
#include "carla/road/element/RoadSegment.h"
#include <map>
namespace carla {
namespace road {
class MapData
: private MovableNonCopyable {
public:
bool ExistId(element::id_type id) const;
const element::RoadSegment *GetRoad(element::id_type id) const;
std::vector<element::id_type> GetAllIds() const;
uint32_t GetRoadCount() const;
const element::RoadSegment &NearestRoad(const geom::Location &loc);
private:
friend class MapBuilder;
friend class Map;
MapData() = default;
std::map<element::id_type, std::unique_ptr<element::RoadSegment>> _elements;
};
} // namespace road
} // namespace carla

View File

@ -0,0 +1,37 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/ListView.h"
#include "carla/road/element/RoadInfoVisitor.h"
namespace carla {
namespace road {
namespace element {
class RoadInfoList {
using SharedPtrList = std::vector<std::shared_ptr<const RoadInfo>>;
public:
RoadInfoList(const SharedPtrList &l) : _list(l) {}
template <typename T>
auto Get() const {
auto begin = MakeRoadInfoIterator<T>(_list.begin(), _list.end());
auto end = MakeRoadInfoIterator<T>(_list.end(), _list.end());
return MakeListView(begin, end);
}
private:
SharedPtrList _list;
};
} // namespace element
} // namespace road
} // namespace carla

View File

@ -30,7 +30,7 @@ namespace element {
class RoadInfoIterator : private RoadInfoVisitor {
public:
static_assert(std::is_same<std::unique_ptr<RoadInfo>, typename IT::value_type>::value, "Not compatible.");
static_assert(std::is_same<std::shared_ptr<RoadInfo>, typename IT::value_type>::value, "Not compatible.");
RoadInfoIterator(IT begin, IT end)
: _it(begin),
@ -65,6 +65,14 @@ namespace element {
return &static_cast<T *>(_it->get());
}
bool operator!=(const RoadInfoIterator &rhs) const {
return _it != rhs._it;
}
bool operator==(const RoadInfoIterator &rhs) const {
return !((*this) != rhs);
}
bool IsAtEnd() const {
return _it == _end;
}

View File

@ -57,8 +57,11 @@ namespace element {
}
// returns info vector given a type and a distance
template <typename T>
std::vector<T> GetInfos(double dist) const;
std::vector<std::shared_ptr<const RoadInfo>> GetInfos(double dist) const {
// @todo
(void)dist;
return std::vector<std::shared_ptr<const RoadInfo>>();
}
void PredEmplaceBack(RoadSegment *s) {
_predecessors.emplace_back(s);
@ -144,17 +147,17 @@ namespace element {
struct LessComp {
using is_transparent = void;
bool operator()(
const std::unique_ptr<RoadInfo> &a,
const std::unique_ptr<RoadInfo> &b) const {
const std::shared_ptr<RoadInfo> &a,
const std::shared_ptr<RoadInfo> &b) const {
return a->d < b->d;
}
bool operator()(
const double &a,
const std::unique_ptr<RoadInfo> &b) const {
const std::shared_ptr<RoadInfo> &b) const {
return a < b->d;
}
bool operator()(
const std::unique_ptr<RoadInfo> &a,
const std::shared_ptr<RoadInfo> &a,
const double &b) const {
return a->d < b;
}
@ -167,7 +170,7 @@ namespace element {
std::vector<bool> _successors_is_start;
std::vector<bool> _predecessors_is_start;
std::vector<std::unique_ptr<Geometry>> _geom;
std::multiset<std::unique_ptr<RoadInfo>, LessComp> _info;
std::multiset<std::shared_ptr<RoadInfo>, LessComp> _info;
double _length = -1.0;
};

View File

@ -58,8 +58,8 @@ namespace element {
// usage MakeInfo<SpeedLimit>(30.0)
template <typename T, typename ... Args>
T *MakeInfo(Args && ... args) {
_info.emplace_back(std::make_unique<T>(std::forward<Args>(args) ...));
return dynamic_cast<T *>(_info.back().get());
_info.emplace_back(std::make_shared<T>(std::forward<Args>(args) ...));
return static_cast<T *>(_info.back().get());
}
const std::vector<id_type> &GetPredecessorID() const {
@ -71,7 +71,7 @@ namespace element {
const std::vector<std::unique_ptr<Geometry>> &GetGeometry() const {
return _geom;
}
const std::vector<std::unique_ptr<RoadInfo>> &GetInfo() const {
const std::vector<std::shared_ptr<RoadInfo>> &GetInfo() const {
return _info;
}
@ -84,7 +84,7 @@ namespace element {
std::vector<bool> _successor_is_start;
std::vector<bool> _predecessors_is_start;
std::vector<std::unique_ptr<Geometry>> _geom;
std::vector<std::unique_ptr<RoadInfo>> _info;
std::vector<std::shared_ptr<RoadInfo>> _info;
};
} // namespace element

View File

@ -0,0 +1,19 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/road/element/Waypoint.h"
namespace carla {
namespace road {
namespace element {
RoadInfoList Waypoint::GetRoadInfo() const {
return RoadInfoList(_map->GetData().GetRoad(_road_id)->GetInfos(_dist));
}
} // namespace element
} // namespace road
} // namespace carla

View File

@ -0,0 +1,54 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/road/Map.h"
#include "carla/geom/Transform.h"
#include "carla/road/element/RoadInfoList.h"
namespace carla {
namespace road {
class Map;
namespace element {
class Waypoint {
public:
Waypoint() = default;
const geom::Transform &GetTransform() const {
return _transform;
}
const id_type &GetRoadId() const {
return _road_id;
}
std::vector<Waypoint> Next(double distance) const {
(void) distance;
return std::vector<Waypoint>();
}
RoadInfoList GetRoadInfo() const;
private:
SharedPtr<Map> _map;
geom::Transform _transform;
id_type _road_id = 0;
double _dist = 0.0;
};
} // namespace element
} // namespace road
} // namespace carla

View File

@ -41,297 +41,24 @@ TEST(road, add_information) {
builder.AddRoadSegmentDefinition(def);
Map m = builder.Build();
const RoadInfoVelocity *r = m.GetRoad(0)->GetInfo<RoadInfoVelocity>(0.0);
const RoadInfoVelocity *r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(0.0);
ASSERT_EQ(r->velocity, 50.0);
r = m.GetRoad(0)->GetInfo<RoadInfoVelocity>(2);
r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(2);
ASSERT_EQ(r->velocity, 90.0);
r = m.GetRoad(0)->GetInfo<RoadInfoVelocity>(3);
r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(3);
ASSERT_EQ(r->velocity, 100.0);
r = m.GetRoad(0)->GetInfo<RoadInfoVelocity>(3.5);
r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(3.5);
ASSERT_EQ(r->velocity, 100.0);
r = m.GetRoad(0)->GetInfo<RoadInfoVelocity>(6);
r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(6);
ASSERT_EQ(r->velocity, 90.0);
r = m.GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(4);
r = m.GetData().GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(4);
ASSERT_EQ(r->velocity, 90.0);
r = m.GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(2.5);
r = m.GetData().GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(2.5);
ASSERT_EQ(r->velocity, 100.0);
r = m.GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(2);
r = m.GetData().GetRoad(0)->GetInfoReverse<RoadInfoVelocity>(2);
ASSERT_EQ(r->velocity, 90.0);
}
/*TEST(road, get_information) {
MapBuilder builder;
RoadSegmentDefinition def(1);
class A : public RoadInfo {
public:
A(double distance)
: RoadInfo(distance) {}
};
class B : public RoadInfo {
public:
B(double distance)
: RoadInfo(distance) {}
};
class C : public RoadInfo {
public:
C(double distance)
: RoadInfo(distance) {}
};
class D : public RoadInfo {
public:
D(double distance)
: RoadInfo(distance) {}
};
def.MakeGeometry<GeometryLine>(0.0, 10.0, 0, carla::geom::Location());
def.MakeGeometry<GeometryLine>(10.0, 20.0, 0, carla::geom::Location(10, 0, 0));
def.MakeInfo<A>(0.0); // ||||||||||,||||||||||
def.MakeInfo<B>(0.0); // ||||------,----------
def.MakeInfo<B>(4.0); // ----||||||,||||||||||
def.MakeInfo<B>(4.0); // ----||||||,||||||||||
def.MakeInfo<C>(5.01); // -----|||||,|||||-----
def.MakeInfo<C>(15.0); // ----------,-----|||||
def.MakeInfo<D>(5.0); // -----|||||,----------
def.MakeInfo<D>(10.0); // ----------,|||||-----
def.MakeInfo<D>(15.0); // ----------,-----|||||
builder.AddRoadSegmentDefinition(def);
Map m = builder.Build();
const RoadSegment *rs = m.GetRoad(1);
ASSERT_EQ(rs->GetInfo<A>(0.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<A>(-0.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<A>(-1.0), nullptr);
ASSERT_EQ(rs->GetInfo<A>(4.5)->d, 0.0);
ASSERT_EQ(rs->GetInfo<A>(10.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<A>(20.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<A>(30.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<B>(0.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<B>(1.0)->d, 0.0);
ASSERT_EQ(rs->GetInfo<B>(3.999)->d, 0.0);
ASSERT_EQ(rs->GetInfo<B>(4.0)->d, 4.0);
ASSERT_EQ(rs->GetInfo<B>(4.001)->d, 4.0);
ASSERT_EQ(rs->GetInfo<C>(0.0), nullptr);
ASSERT_EQ(rs->GetInfo<C>(5.0), nullptr);
ASSERT_EQ(rs->GetInfo<C>(5.01)->d, 5.01);
ASSERT_EQ(rs->GetInfo<C>(5.011)->d, 5.01);
ASSERT_EQ(rs->GetInfo<C>(8.2)->d, 5.01);
ASSERT_EQ(rs->GetInfo<C>(13.8)->d, 5.01);
ASSERT_EQ(rs->GetInfo<C>(18)->d, 15);
ASSERT_EQ(rs->GetInfo<C>(20)->d, 15);
ASSERT_EQ(rs->GetInfo<D>(0), nullptr);
ASSERT_EQ(rs->GetInfo<D>(4), nullptr);
ASSERT_EQ(rs->GetInfo<D>(6)->d, 5);
ASSERT_EQ(rs->GetInfo<D>(12)->d, 10);
ASSERT_EQ(rs->GetInfo<D>(16)->d, 15);
ASSERT_EQ(rs->GetInfo<D>(23)->d, 15);
}*/
/*TEST(road, add_geom_and_info) {
MapBuilder builder;
RoadSegmentDefinition def(1);
class A : public RoadInfo {
public:
A() {}
A(double distance)
: RoadInfo(distance) {}
A(double distance, double _a0)
: RoadInfo(distance),
_a(_a0) {}
double _a = 0;
};
class B : public RoadInfo {};
class C : public RoadInfo {};
def.MakeGeometry<GeometryLine>(1.0, 2.0, 3.0, carla::geom::Location());
def.MakeGeometry<GeometrySpiral>(1.0, 2.0, 3.0, carla::geom::Location(), 1.0, 2.0);
def.MakeGeometry<GeometryArc>(1.0, 2.0, 3.0, carla::geom::Location(), 1.0);
A *a_def0 = def.MakeInfo<A>();
a_def0->d = 1;
a_def0->_a = 2;
def.MakeInfo<A>(3);
def.MakeInfo<A>(4, 5);
def.MakeInfo<B>();
def.MakeInfo<C>();
def.MakeInfo<C>();
builder.AddRoadSegmentDefinition(def);
Map m = builder.Build();
const std::vector<const A *> a = m.GetRoad(1)->GetInfo<A>();
ASSERT_EQ(a.size(), 3U);
ASSERT_EQ(a[0]->d, 1U);
ASSERT_EQ(a[0]->_a, 2U);
ASSERT_EQ(a[1]->d, 3U);
ASSERT_EQ(a[1]->_a, 0U);
ASSERT_EQ(a[2]->d, 4U);
ASSERT_EQ(a[2]->_a, 5U);
const std::vector<const C *> c = m.GetRoad(1)->GetInfo<C>();
ASSERT_EQ(c.size(), 2U);
}
TEST(road, set_and_get_connections) {
MapBuilder builder;
RoadSegmentDefinition def1(1);
RoadSegmentDefinition def2(2);
RoadSegmentDefinition def3(3);
RoadSegmentDefinition def4(4);
def1.AddPredecessorID(4);
def2.AddPredecessorID(1);
def3.AddPredecessorID(1);
def3.AddPredecessorID(2);
def4.AddPredecessorID(3);
def1.AddSuccessorID(2);
def1.AddSuccessorID(3);
def2.AddSuccessorID(3);
def3.AddSuccessorID(4);
builder.AddRoadSegmentDefinition(def1);
builder.AddRoadSegmentDefinition(def2);
builder.AddRoadSegmentDefinition(def3);
builder.AddRoadSegmentDefinition(def4);
Map m = builder.Build();
ASSERT_TRUE(m.ExistId(1));
ASSERT_TRUE(m.ExistId(2));
ASSERT_TRUE(m.ExistId(3));
ASSERT_TRUE(m.ExistId(4));
const RoadSegment *s1 = m.GetRoad(1);
const RoadSegment *s2 = m.GetRoad(2);
const RoadSegment *s3 = m.GetRoad(3);
const RoadSegment *s4 = m.GetRoad(4);
ASSERT_NE(s1, nullptr);
ASSERT_NE(s2, nullptr);
ASSERT_NE(s3, nullptr);
ASSERT_NE(s4, nullptr);
// Road 1
ASSERT_TRUE(s1->HavePredecessors());
ASSERT_TRUE(s1->HaveSuccessors());
std::vector<id_type> pred = s1->GetPredecessorsIds();
std::vector<RoadSegment *> pred_ptr = s1->GetPredecessors();
ASSERT_EQ(pred.size(), 1U);
ASSERT_EQ(pred[0], 4U); // same id
ASSERT_EQ(m.GetRoad(pred[0]), s4); // same memory adress
ASSERT_EQ(s4, pred_ptr[0]); // same memory adress
std::vector<id_type> succ = s1->GetSuccessorsIds();
std::vector<RoadSegment *> succ_ptr = s1->GetSuccessors();
ASSERT_EQ(succ.size(), 2U);
ASSERT_EQ(succ[0], 2U);
ASSERT_EQ(succ[1], 3U);
ASSERT_EQ(m.GetRoad(succ[0]), s2);
ASSERT_EQ(m.GetRoad(succ[1]), s3);
ASSERT_EQ(s2, succ_ptr[0]);
ASSERT_EQ(s3, succ_ptr[1]);
pred.clear();
succ.clear();
pred_ptr.clear();
succ_ptr.clear();
// Road 2
ASSERT_TRUE(s2->HavePredecessors());
ASSERT_TRUE(s2->HaveSuccessors());
pred = s2->GetPredecessorsIds();
pred_ptr = s2->GetPredecessors();
ASSERT_EQ(pred.size(), 1U);
ASSERT_EQ(pred[0], 1U);
ASSERT_EQ(m.GetRoad(pred[0]), s1);
ASSERT_EQ(s1, pred_ptr[0]);
succ = s2->GetSuccessorsIds();
succ_ptr = s2->GetSuccessors();
ASSERT_EQ(succ.size(), 1U);
ASSERT_EQ(succ[0], 3U);
ASSERT_EQ(m.GetRoad(succ[0]), s3);
ASSERT_EQ(s3, succ_ptr[0]);
pred.clear();
succ.clear();
pred_ptr.clear();
succ_ptr.clear();
// Road 3
ASSERT_TRUE(s3->HavePredecessors());
ASSERT_TRUE(s3->HaveSuccessors());
pred = s3->GetPredecessorsIds();
pred_ptr = s3->GetPredecessors();
ASSERT_EQ(pred.size(), 2U);
ASSERT_EQ(pred[0], 1U);
ASSERT_EQ(pred[1], 2U);
ASSERT_EQ(m.GetRoad(pred[0]), s1);
ASSERT_EQ(m.GetRoad(pred[1]), s2);
ASSERT_EQ(s1, pred_ptr[0]);
ASSERT_EQ(s2, pred_ptr[1]);
succ = s3->GetSuccessorsIds();
succ_ptr = s3->GetSuccessors();
ASSERT_EQ(succ.size(), 1U);
ASSERT_EQ(succ[0], 4U);
ASSERT_EQ(m.GetRoad(succ[0]), s4);
ASSERT_EQ(s4, succ_ptr[0]);
pred.clear();
succ.clear();
pred_ptr.clear();
succ_ptr.clear();
// Road 4
ASSERT_TRUE(s4->HavePredecessors());
ASSERT_FALSE(s4->HaveSuccessors());
pred = s4->GetPredecessorsIds();
pred_ptr = s4->GetPredecessors();
ASSERT_EQ(pred.size(), 1U);
ASSERT_EQ(pred[0], 3U);
ASSERT_EQ(m.GetRoad(pred[0]), s3);
ASSERT_EQ(s3, pred_ptr[0]);
succ = s4->GetSuccessorsIds();
succ_ptr = s4->GetSuccessors();
ASSERT_EQ(succ.size(), 0U);
pred.clear();
succ.clear();
pred_ptr.clear();
succ_ptr.clear();
}*/
TEST(road, set_and_get_connections_for) {
MapBuilder builder;
for (int i = 0; i < 10; ++i) {
@ -345,9 +72,9 @@ TEST(road, set_and_get_connections_for) {
builder.AddRoadSegmentDefinition(def);
}
Map m = builder.Build();
for (auto &&r : m.GetAllIds()) {
for (auto &&r : m.GetData().GetAllIds()) {
for (size_t i = 0; i < 10; ++i) {
ASSERT_EQ(m.GetRoad(r)->GetPredecessorsIds().at(i), i);
ASSERT_EQ(m.GetData().GetRoad(r)->GetPredecessorsIds().at(i), i);
}
}
}
@ -379,26 +106,26 @@ TEST(road, geom_line) {
Map m = builder.Build();
ASSERT_EQ(m.GetRoad(1)->GetLength(), 20.0);
AssertNear(m.GetRoad(1)->GetDirectedPointIn(0),
ASSERT_EQ(m.GetData().GetRoad(1)->GetLength(), 20.0);
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(0),
element::DirectedPoint(0, 0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(-1.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(-1.0),
element::DirectedPoint(0, 0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(1.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(1.0),
element::DirectedPoint(1.0, 0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(3.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(3.0),
element::DirectedPoint(3.0, 0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(10.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(10.0),
element::DirectedPoint(10.0, 0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(11.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(11.0),
element::DirectedPoint(10.0, 1.0, 0, Math::pi_half()));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(15.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(15.0),
element::DirectedPoint(10.0, 5.0, 0, Math::pi_half()));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(17.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(17.0),
element::DirectedPoint(12.0, 5.0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(20.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(20.0),
element::DirectedPoint(15.0, 5.0, 0, 0));
AssertNear(m.GetRoad(1)->GetDirectedPointIn(22.0),
AssertNear(m.GetData().GetRoad(1)->GetDirectedPointIn(22.0),
element::DirectedPoint(15.0, 5.0, 0, 0));
}
@ -418,7 +145,7 @@ TEST(road, geom_arc) {
Map m = builder.Build();
ASSERT_EQ(m.GetRoad(1)->GetLength(), 10.0);
ASSERT_EQ(m.GetData().GetRoad(1)->GetLength(), 10.0);
}
TEST(road, geom_spiral) {
@ -438,14 +165,32 @@ TEST(road, geom_spiral) {
Map m = builder.Build();
ASSERT_EQ(m.GetRoad(1)->GetLength(), 10.0);
ASSERT_EQ(m.GetData().GetRoad(1)->GetLength(), 10.0);
// not implemented yet
// debug:
/*const int max = 50;
for (int i = 0; i < max; ++i) {
DirectedPoint dp = m.GetRoad(1)->GetDirectedPointIn((float)i * (10.0f / (float)max));
DirectedPoint dp = m.GetData().GetRoad(1)->GetDirectedPointIn((float)i * (10.0f / (float)max));
printf("(%f,%f)", dp.location.x, dp.location.y);
if (i != max-1) printf(",");
else printf("\n");
}*/
}
TEST(road, get_information) {
MapBuilder builder;
RoadSegmentDefinition def(0);
def.MakeGeometry<GeometryLine>(0, 10, 0, carla::geom::Location());
def.MakeInfo<element::RoadInfoVelocity>(0, 50);
def.MakeInfo<element::RoadInfoVelocity>(2, 90);
def.MakeInfo<element::RoadInfoVelocity>(3, 100);
def.MakeInfo<element::RoadInfoVelocity>(5, 90);
def.MakeInfo<element::RoadInfoLane>();
builder.AddRoadSegmentDefinition(def);
Map m = builder.Build();
const RoadInfoVelocity *r = m.GetData().GetRoad(0)->GetInfo<RoadInfoVelocity>(0.0);
(void)r;
}