Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting Protocol definition #58

Open
bshafiee opened this issue Dec 31, 2022 · 1 comment
Open

Limiting Protocol definition #58

bshafiee opened this issue Dec 31, 2022 · 1 comment

Comments

@bshafiee
Copy link

Hi,
Thanks for creating this awesome library. Would it be Possible to extend the protocol to support any KDTreePoint implemented type? What I mean is that, currently the protocol expect the same type for distance comparision:

public protocol KDTreePoint: Equatable {
    ...
    func squaredDistance(to otherPoint: **Self**) -> Double
}

This is okay but very limiting, imagine my nodes have this structure:

class Node {
   point2d: CGPoint
   otherData...
}

if I create my tree with Node, I am forced always to query it with a Node as well, but if you would have relaxed the Protocol to:

public protocol KDTreePoint: Equatable {
    ...
    func squaredDistance(to otherPoint: **KDTreePoint**) -> Double
}

then I could extend both Node and CGPoint and do my queries with a tiny CGPoint (albeit handling the type check in the distance function etc.).
I know this is a convenience but figured mention it. Thank you!

@Bersaelor
Copy link
Owner

hello @bshafiee,

i didn't expect a heterogenous tree structure with different types being compared would be a common use case.
Potentially this could cause a lot of confusion.

Why don't you handle it on the client side?

I.e. you could have

struct MetaNode: KDTreePoint
    point: Either<CGPoint, OtherPoint>
    
    func squaredDistance(to otherPoint: Self) -> Double {
         switch self { 
             ...
    }

Assuming the common definition many people use for Either<A, B>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants