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

Some questions about Rect and BoundBox #14

Open
colepoirier opened this issue Mar 20, 2022 · 1 comment
Open

Some questions about Rect and BoundBox #14

colepoirier opened this issue Mar 20, 2022 · 1 comment

Comments

@colepoirier
Copy link
Contributor

Rect and BoundBox

I'm curious if Rect should be constrained to have the same guarantees as BoundBox where p0 is the (x, y) values closest to negative infinity, and p1 is the (x ,y) values closest to positive infinity, then obviating the need for the BoundBox type which is essentially just a Rect which results in code duplication.

In that scenario would it then also make sense to define Rect as follows?

pub struct Rect {
    x_min: Int,
    y_min: Int,
    x_max: Int,
    y_max: Int,
}

Perceived BoundBox footgun

Something that I found to be a bit of a footgun with BoundBox is that 'empty, otherwise invalid [BoundBox]' is defined to have the value Int::MAX for p0, and Int::MIN for p1. Would it be better to define BoundBox as an enum sum type (like std::Option) as follows:

pub enum BoundBox {
    Valid(Rect),
    Invalid
}

Would this add too much overhead to what the BoundBox type is intended for? Does the user need to check the validity of the BoundBox regardless?

@dan-fritchman
Copy link
Owner

Totally agree the the BoundBox change is much better than what's in there now.

I'm less opinionated on the Rect representation. For some other shapes, e.g. a many-sided polygon, it's often actually nicer to store an offset "externally". The most common cell-instance transformation - translations - becomes a single-point move. In such a setup Rect would just become something like width, height or dx, dy.

You want to roll in at least the anti-foot-gunning?

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