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

Feature Request: Support RangeBounds. #2

Open
rljacobson opened this issue Mar 28, 2020 · 1 comment
Open

Feature Request: Support RangeBounds. #2

rljacobson opened this issue Mar 28, 2020 · 1 comment

Comments

@rljacobson
Copy link

rljacobson commented Mar 28, 2020

Every std::ops::Range* struct implements std::ops::RangeBounds, which holds the endpoints of the range. The endpoints are std::ops::Bound<t>s:

pub enum Bound<T> {
    Included(T),
    Excluded(T),
    Unbounded,
}

Every possible kind of interval can be represented with this machinery: open, closed, half-open, unbounded on either or both ends, even degenerate intervals (singletons and null sets).

An argument against supporting anything other than inclusive ranges is, every numeric type is finite (including floats), and thus the topology of the type is discrete. In other words, for, say, floats, the half-open set [a, b) is precisely the same set as [a, b'] where b' is the largest representable float smaller than b.

My counterargument is that we use these sets to approximate continuous intervals and want them to have the semantics of the usual continuous topology on the reals. In other words, we wish to interpret [a, b) to include all of the numbers between b' and b, despite b being potentially approximate.

@spearman
Copy link
Owner

spearman commented Mar 31, 2020

Thanks for the input, I can see how something like that could be useful in a math library, I've used 1D AABBs for something similar in collision libraries.

This library was originally written with discrete ranges in mind, primitive integers or types with Eq constraints, and with the intention of using it to represent "free-lists" of indices in contiguous storage. I'm not sure how much it would change the interface to relax the Eq constraint to a PartialEq to accommodate floats. If the type machinery in the generic version gets more complicated/harder to read, then I'd probably prefer to put it in a separate module.

I don't think I'm using this currently in anything upstream, so it's not going to be changing much in the near future, with that said anyone is welcome to submit pull requests =)

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