Error with Swift Apprentice v2.0 overlaps solution Ch.11: Structures

Hi guys, am I missing something here? To me it seems like the solution for the overlaps(with:) solution has a small error. This is what it currently is:

func overlaps(with area: DeliveryArea) -> Bool {
    distance(from: center, to: area.center)
    return distance(from: center, to: area.center) >= (range + area.range)
}

It seems like it should be comparing with “<=” instead of “>=” right? Given the following areas:

let area1 = DeliveryArea(range: 2.5, center: Location(x: 2, y: 4))
let area2 = DeliveryArea(range: 2.5, center: Location(x: 2, y: 100))

The areas shouldn’t overlap, however, the current solution says it does.

Sorry if this has been brought up before and/or I’m using an older version of the solutions!

@bbpiepho Thanks very much for your question! I believe <= is correct, and the reason why is that it is trying to identify whether a particular section falls within a particular region or not. If the region is <=, it means that section touches the other region at some point, and thus, would return true. If you used your approach, the method would still work, but a return value of false would mean that the region overlaps (which would be a bit more confusing) :slight_smile:

I hope this makes sense!

All the best!

@syedfa ahh, I just realized I copy pasted the overlap function once I had already modified it! But it seems that your reply validates what I was trying to depict, so thank you!

No problem! I’m glad I could help :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.