I am asking a user for four ranges of floating point numbers. I want to check that there is no overlap between them.
If the ranges were integer ranges it seems that I could either create sets or use Swift Range (or NSRange) and check for intersections.
Is there a way to figure this out if the ranges where then upper and lower bounds are floating point values?
Would I just have to check that each lower and upper bound of each range is not between the lower/upper bound of each of the other ranges? Is there a better way?
Thanks
You can use the Range type to represent a range of floating point values. You can then use the contains method to check if a value is in a range. You can also use the overlaps method to check if two ranges overlap. Here is an example:
You can also use the ~= operator to check if a value is in a range. This is the same operator that is used in switch statements.
You can use the sorted method to sort an array of ranges. Here is an example:
You can then iterate over the sorted ranges and check if the upper bound of the previous range is greater than the lower bound of the current range.
You can also use the contains/overlaps method to check if a range contains another range.