# Confusion about periodic BCs in NearestNeighbors.jl

**URL:** https://discourse.julialang.org/t/confusion-about-periodic-bcs-in-nearestneighbors-jl/134706
**Category:** General Usage
**Tags:** question, package
**Created:** [December 23, 2025, 10:19am UTC](https://discourse.julialang.org/t/confusion-about-periodic-bcs-in-nearestneighbors-jl/134706 "2025-12-23T10:19:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Barabule](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Barabule](https://discourse.julialang.org/u/Barabule)
#### Post date: [December 23, 2025, 10:19am UTC](https://discourse.julialang.org/t/confusion-about-periodic-bcs-in-nearestneighbors-jl/134706/1 "2025-12-23T10:19:35Z")

</div>

Hi,

I’m trying to make a periodic tree in NearestNeigbors with a custom Distance metric

```julia-auto
struct SegmentDistance <:Metric; end

function parameters(::SegmentDistance)
    nothing
end

```

The idea is to compute line segment distances inside a periodic cell. The line segments are encoded as SVector{6} with the first 3 elements the center (lies inside the cell) and the next 3 a direction → so the endpoints can be outside the cell.

I’m constructing the tree like this to make the tree periodic only in the first 3 elements:

```julia-auto
    lower = [0.0, 0.0, 0.0, -Inf, -Inf, -Inf]
    upper = [volume..., Inf, Inf, Inf]
    tree = PeriodicTree(BallTree(segments, SegmentDistance()), lower, upper)

```

The problem is I get an error complaining about not finding the parameters function, even though it’s defined in the RVE module:

```julia-auto
MethodError: no method matching parameters(::RVE.SegmentDistance)
The function `parameters` exists, but no method is defined for this combination of argument types.

```

How can I make this work? And why do I need the parameters function anyway?

Thanks.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 23, 2025, 4:17pm UTC](https://discourse.julialang.org/t/confusion-about-periodic-bcs-in-nearestneighbors-jl/134706/2 "2025-12-23T16:17:17Z")

</div>

> [@Barabule](#):
>
> `function parameters(::SegmentDistance)`

[Should be](https://docs.julialang.org/en/v1/manual/modules/#using-and-import-with-specific-identifiers,-and-adding-methods) `function Distances.parameters(::SegmentDistance)` in order to add a new method to the `parameters` function from `Distances.jl`, instead of defining an unrelated function with the same name in your own module.

---

<div class="post-metadata">

### Author: ![Barabule](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Barabule](https://discourse.julialang.org/u/Barabule)
#### Post date: [December 23, 2025, 5:00pm UTC](https://discourse.julialang.org/t/confusion-about-periodic-bcs-in-nearestneighbors-jl/134706/3 "2025-12-23T17:00:17Z")

</div>

That did work.. unfortunately now NN complains about a missing eval\_op method and so on. Looking through the NN code I gather it looks like a periodic BC aware metric per coordinate ?  
So at the end I feel this’ll just lead me into a rabbit hole.  
I have the feeling that what I want is not possible with PeriodicTree (at least not yet).  
At least the NN tree works for 6d “points” to represent line segments and my custom distance metric; I implemented the periodic BC with (not so)ghost points (repeated the inner points for all 26 neighbors) - it works but it’s kinda hacky.  
Oh well.. merry Xmas everybody 🎅
