Skip to content

Conversation

@ChristopherBiscardi
Copy link
Contributor

Objective

Most Mesh2d primitives order their vertices in what I'll call "hull order", which is to say, in an sequential outline of the shape.
A Rectangle, for example, is:

let positions = vec![
  [hw, hh, 0.0],
  [-hw, hh, 0.0],
  [-hw, -hh, 0.0],
  [hw, -hh, 0.0],
];

The Rhombus does not follow this pattern, instead using "right, left, top, bottom" order for the vertex buffer.

This isn't a general issue, but there is definitely a pattern to the way the shapes are laid out, and Rhombus doesn't follow it.
This means you can use the vertex buffer alone to define a hull for most 2d shapes (regular polygons, lines, circles, capsules, etc), except the rhombus (also not valid for annulus/ring afaik)

Solution

Re-order the indices and vertices for Rhombus, resulting in the same output, but enabling the vertex buffer to be used to define a "hull" directly, without the index buffer.

Testing

Run the 2d_shapes demo, see wireframe is as expected.

screenshot-2025-10-21-at-09 03 12@2x

Showcase

In a 2d visibility mesh demo I was building, this caused an issue when trying to directly use the vertex buffer to define the outer "hull" shape.

old rhombus on left, new rhombus on right.

screenshot-2025-10-21-at-08 40 14@2x

@ChristopherBiscardi ChristopherBiscardi added A-Rendering Drawing game state to the screen A-Math Fundamental domain-agnostic mathematical operations S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 21, 2025
@kpreid
Copy link
Contributor

kpreid commented Oct 21, 2025

I think that if this property is to be provided for people to use, then it should be documented and tested (the test can be as simple as "are the vertices of the shape sorted by their atan2(vertex - center)?"). If the property is added with no documentation and no tests, then it might be accidentally removed in a future reimplementation or not provided by a new shape.

@ChristopherBiscardi
Copy link
Contributor Author

@kpreid yup, that's totally fair (and I'm open to adding those tests in this PR).

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

Labels

A-Math Fundamental domain-agnostic mathematical operations A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants