Confusion about periodic BCs in NearestNeighbors.jl

Hi,

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

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:

    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:

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.

Should be 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.

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 :santa_claus: