Skip to content

Math, inclusivity and exclusivity #37

@museun

Description

@museun

Currently, the whole math library is kind of .. confusing.

There should only be 1 representation: exclusive. All rects should inclusively ranged.

The only place where exclusivity matters is on the terminal surface. this can just add Vec2::splat(1) to make it inclusive at the very end of the 'pipeline'.

But, perhaps we should make everything exclusive and the surface subtracts Vec2::splat(1).

For example, currently everything uses the exclusive ranges:

for y in 0..rect.height() {
    for x in 0..rect.width() {
        let pos = pos2(x, y); 
    }
}

But things like Rect::clamp() uses an inclusive range:

    pub fn clamp(&self, pos: Pos2) -> Pos2 {
        pos.clamp(self.min, self.max)
    }

This is a bit annoying, for example:

    fn event(&mut self, event: ViewEvent, ctx: EventCtx) -> Handled {
        if let ViewEvent::MouseDrag {
            current,
            inside: true,
            ..
        } = event
        {
            self.cursor = ctx.rect().clamp(current);
            return Handled::Sink;
        }
        Handled::Bubble
    }

That clamps the cursor to 1,1 past the viewable area of the rectangle.

I think all rectangle math should be exclusive so it aligns with how we can iterate through the coordinates of a rect.

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