Skip to content

Some questions about Rect and BoundBox #14

Description

@colepoirier

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions