Commit 479d9390 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

WorldBase/Infinite/Toric: Fixed a crash when trying to find neighbors without a KD tree.

parent 42a62237
......@@ -81,9 +81,6 @@ private:
/// <summary>A list of agents (sorted by time) that will be added to the simulation in the future.</summary>
AgentQueue agentsToAdd;
/// <summary>A kd-tree of agent positions, used for nearest-neighbor queries.</summary>
AgentKDTree* agentKDTree;
/// <summary>A mapping from agent IDs to positions in the agents_ list.</summary>
/// <remarks>Because agents can be removed during the simulation, the ID of an agent is not necessarily the same
/// as its position in the list. This is why we need this extra administration.
......@@ -103,6 +100,9 @@ protected:
/// <summary>A list containing all agents that are currently in the crowd.</summary>
std::vector<Agent*> agents_;
/// <summary>A kd-tree of agent positions, used for nearest-neighbor queries.</summary>
AgentKDTree* agentKDTree;
/// <summary>The length (in seconds) of a simulation step.</summary>
float delta_time_;
......
......@@ -30,10 +30,14 @@ WorldInfinite::WorldInfinite() : WorldBase(INFINITE_WORLD)
NeighborList WorldInfinite::ComputeNeighbors(const Vector2D& position, float search_radius, const Agent* queryingAgent) const
{
const auto& agents = computeNeighboringAgents_Flat(position, search_radius, queryingAgent);
vector<PhantomAgent> phantoms;
for (const Agent* agent : agents)
phantoms.push_back(PhantomAgent(agent->getPosition(), agent->getVelocity(), agent));
vector<PhantomAgent> phantoms;
if (agentKDTree != nullptr)
{
const auto& agents = computeNeighboringAgents_Flat(position, search_radius, queryingAgent);
for (const Agent* agent : agents)
phantoms.push_back(PhantomAgent(agent->getPosition(), agent->getVelocity(), agent));
}
return { phantoms, computeNeighboringObstacles_Flat(position, search_radius) };
}
......
......@@ -32,10 +32,13 @@ WorldToric::WorldToric(float width, float height)
void WorldToric::computeNeighbors_Displaced(const Vector2D& position, const Vector2D& displacement, float search_radius, const Agent* queryingAgent,
NeighborList& result) const
{
// agents
const auto& agents = computeNeighboringAgents_Flat(position + displacement, search_radius, queryingAgent);
for (const Agent* agent : agents)
result.first.push_back(PhantomAgent(agent->getPosition() - displacement, agent->getVelocity(), agent));
if (agentKDTree != nullptr)
{
// agents
const auto& agents = computeNeighboringAgents_Flat(position + displacement, search_radius, queryingAgent);
for (const Agent* agent : agents)
result.first.push_back(PhantomAgent(agent->getPosition() - displacement, agent->getVelocity(), agent));
}
// obstacles
const auto& obstacles = computeNeighboringObstacles_Flat(position + displacement, search_radius);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment