-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement constant time lookup for wall segemtns
Walls are now stored in grid cells where all segmetns are part of that are in approximate distance to this cell. This gives a constant time / no allocation lookup for relevant line segments.
- Loading branch information
1 parent
bbe13ce
commit e933783
Showing
13 changed files
with
8,176 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2012-2023 Forschungszentrum Jülich GmbH | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include "CollisionGeometry.hpp" | ||
#include "GeometryBuilder.hpp" | ||
#include "LineSegment.hpp" | ||
#include "buildGeometries.hpp" | ||
|
||
template <class... Args> | ||
void bmLineSegmentsInDistanceTo(benchmark::State& state, Args&&... args) | ||
{ | ||
auto args_tuple = std::make_tuple(std::move(args)...); | ||
auto geometry = std::move(std::get<Geometry>(args_tuple)); | ||
|
||
for(auto _ : state) { | ||
benchmark::DoNotOptimize(geometry.collisionGeometry->LineSegmentsInDistanceTo(5., {0, 0})); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
|
||
template <class... Args> | ||
void bmLineSegmentsInApproxDistanceTo(benchmark::State& state, Args&&... args) | ||
{ | ||
auto args_tuple = std::make_tuple(std::move(args)...); | ||
auto geometry = std::move(std::get<Geometry>(args_tuple)); | ||
|
||
for(auto _ : state) { | ||
benchmark::DoNotOptimize( | ||
geometry.collisionGeometry->LineSegmentsInApproxDistanceTo({0, 0})); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
|
||
BENCHMARK_CAPTURE(bmLineSegmentsInDistanceTo, large_street_network, buildLargeStreetNetwork()); | ||
|
||
BENCHMARK_CAPTURE(bmLineSegmentsInDistanceTo, grosser_stern, buildGrosserStern()); | ||
|
||
BENCHMARK_CAPTURE( | ||
bmLineSegmentsInApproxDistanceTo, | ||
large_street_network, | ||
buildLargeStreetNetwork()); | ||
|
||
BENCHMARK_CAPTURE(bmLineSegmentsInApproxDistanceTo, grosser_stern, buildGrosserStern()); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
/// Copyright © 2012-2022 Forschungszentrum Jülich GmbH | ||
/// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#include "AABB.hpp" | ||
|
||
static bool intersectsLine(const AABB& boundingBox, const LineSegment& lineSegment) | ||
{ | ||
const Point base = lineSegment.p1; | ||
const Point dir = lineSegment.p2 - lineSegment.p1; | ||
const Point n = Point{dir.y, -dir.x}; | ||
|
||
const Point c1 = boundingBox.BottomLeft() - base; | ||
const Point c2 = boundingBox.TopRight() - base; | ||
const Point c3 = boundingBox.BottomRight() - base; | ||
const Point c4 = boundingBox.TopLeft() - base; | ||
|
||
const double dp1 = n.ScalarProduct(c1); | ||
const double dp2 = n.ScalarProduct(c2); | ||
const double dp3 = n.ScalarProduct(c3); | ||
const double dp4 = n.ScalarProduct(c4); | ||
|
||
return (dp1 * dp2 <= 0.) || (dp2 * dp3 <= 0.) || (dp3 * dp4 <= 0.); | ||
} | ||
|
||
bool AABB::Intersects(const LineSegment& lineSegment) const | ||
{ | ||
if(!intersectsLine(*this, lineSegment)) { | ||
return false; | ||
} | ||
|
||
const AABB bbLineSegment({lineSegment.p1, lineSegment.p2}); | ||
|
||
return this->Overlap(bbLineSegment); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.