# Computing distances in Agents.jl

**URL:** <https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375>\
**Category:** General Usage\
**Tags:** agents, agentsjl\
**Created:** [December 5, 2025, 11:32am UTC](https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375 "2025-12-05T11:32:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucia\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucia_lopez/32/217649_2.png) [@Lucia\_Lopez](https://discourse.julialang.org/u/Lucia_Lopez)\
**Post date:** [December 5, 2025, 11:32am UTC](https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375/1 "2025-12-05T11:32:57Z")

</div>

In Agents.jl, is there a built-in method to compute the distance from an agent within a `GridSpace` that automatically uses the appropriate distance metric (consistent with the one specified during the space’s initialization) and correctly handles periodic boundary conditions?

So far, I have only encountered workarounds that either manually select the distance function based on the metric chosen at space creation and then handling periodicity, or just relying on a `Pathfinder` to infer distance from path length. But it feels like I’ve missed something.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 6, 2025, 3:58pm UTC](https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375/2 "2025-12-06T15:58:37Z")

</div>

yes, use the distance functions:

- [API · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/api/#Agents.euclidean_distance)
- [API · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/api/#Agents.manhattan_distance)

depending on your metric

---

<div class="post-metadata">

**Author:** ![Lucia\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucia_lopez/32/217649_2.png) [@Lucia\_Lopez](https://discourse.julialang.org/u/Lucia_Lopez)\
**Post date:** [December 6, 2025, 11:10pm UTC](https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375/3 "2025-12-06T23:10:38Z")

</div>

This works for those two distances, but I could not find the version for the case when `metric = :chebyshev`, so that would have to be handled manually.  
Maybe computing distances is not that usual in many cases, but I found strange that despite having an `ABM` with a space being initialized with a defined metric, there’s no standard, automated way to compute distances without explicitly checking and switching on the value of `abmspace(model).metric`.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 7, 2025, 3:37am UTC](https://discourse.julialang.org/t/computing-distances-in-agents-jl/134375/4 "2025-12-07T03:37:11Z")

</div>

Yeah it is strange that this version is missing, but perhaps you can consider doing a pull request that adds it?
