jipolanco / BSplineKit.jl

A collection of B-spline tools in Julia
https://jipolanco.github.io/BSplineKit.jl/dev/
MIT License
50 stars 9 forks source link

Extend equality to `SplineInterpolation` #74

Closed tlow22 closed 1 year ago

tlow22 commented 1 year ago

Hello, thanks for the helpful package! Was doing some unit testing today when I found that the cause of failure was that the equality operation == on SplineInterpolation doesn't work as I expected it to.

Example:

using BSplineKit

a = [0.0, 1.0, 2.0, 3.0, 4.0, 6.0]
b = [0.0, 1.0, 3.0, 12.0, 30.0, 100.0]

fit1 = interpolate(a, b, BSplineOrder(3))
fit2 = interpolate(a, b, BSplineOrder(3))

fit1 == fit2 # yields false

I can make a small PR that basically extends the == operator:

Base.:(==)(o1::SplineInterpolation, o2::SplineInterpolation) =
    all([getproperty(o1, p) == getproperty(o2, p) for p in propertynames(o1)])
jipolanco commented 1 year ago

Hi, thanks for catching that and for your kind words!

Feel free to make a small PR (or I can do it myself if you prefer). I think the best solution would be to actually reuse the == operator already defined for Splines.

Noting that SplineInterpolation is a subtype of SplineWrapper, the following definition should do the job and be quite generic:

# In src/Splines/wrapper.jl
Base.:(==)(o1::SplineWrapper, o2::SplineWrapper) = spline(o1) == spline(o2)
tlow22 commented 1 year ago

Ah a much better solution, I'll get on it then.

jipolanco commented 1 year ago

Closed by #75