Skip to content

Conversation

@uckelman
Copy link
Contributor

@uckelman uckelman commented Dec 9, 2025

Make Gizmos::rect_2d draw the joint of the upper left corner of the rectangle

Objective

  • Gizmos::rect_2d does not draw the line joint between the left and top line segments. This looks odd when the line joint is not GizmoLineJoint::None.

Solution

  • Gizmos::rect_2d draws the rectangle using Gizmos::linestrip_2d, which doesn't draw a closed shape.
  • In order to make linestrip_2d to draw a joint at a corner, that corner has to be in the points list with a predecessor and a successor.
  • tl has no predecessor when it's the first element in the list, and no successor when it's the last.
  • Appending tr to the list is enough to put tl between two other points, which causes the joint to be rendered.

Testing

  • I tested my change against a demo where I draw a selection box.

The test code is just this, and observing the result captured in the screenshots below:

    gizmos.rect_2d(selection.rect.center(), selection.rect.size(), Color::srgb_u8(0xFF, 0, 0));

Showcase

Incorrect GizmoLineJoint::Miter joint without this change:

Screenshot from 2025-12-09 22-42-06

Correct GizmoLineJoint::Miter joint with this change:

Screenshot from 2025-12-09 22-43-06

Gizmos::rect_2d to ensure that the line joint on the top left corner is
drawn.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Gizmos Visual editor and debug gizmos X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Dec 9, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that we're double-drawing the one line segment, but this is a very unobtrusive fix. Are other polygons affected?

@uckelman
Copy link
Contributor Author

uckelman commented Dec 9, 2025

I don't love the double drawing either, but I didn't spot any underlying mechanism for drawing closed shapes. Not sure about other polygons---I found this in the context of drawing a selection box. I'll check..

@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Dec 9, 2025
@uckelman
Copy link
Contributor Author

uckelman commented Dec 9, 2025

rounded_rect_2d has a correct upper left corner, but I think doesn't use line joints? This also seems not to be a problem with ellipse_2d. I don't see any general polygon drawing functions in Gizmos.

@uckelman
Copy link
Contributor Author

uckelman commented Dec 9, 2025

Aha, I found primitive_2d for drawing polygons. Hadn't spotted that before. primitive_2d does have the same problem with the joint on the first vertex. E.g.:

Screenshot from 2025-12-09 23-52-23

These all use linestrip_2d in the same way, so should all have the same defect:

GizmoPrimitive2d<Rhombus>
GizmoPrimitive2d<Triangle2d>
GizmoPrimitive2d<Rectangle>
GizmoPrimitive2d<Polygon>
GizmoPrimitive2d<RegularPolygon>

Given that, a better fix would be a lineloop_2d (or some other better name?) they could all call.

@alice-i-cecile
Copy link
Member

Given that, a better fix would be a lineloop_2d (or some other better name?) they could all call.

Agreed, this would be my preference. We could fix #22081 in earnest, and then resolve all of these problems at once.

@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed X-Uncontroversial This work is generally agreed upon S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 10, 2025
@alice-i-cecile alice-i-cecile self-requested a review December 10, 2025 06:36
@uckelman
Copy link
Contributor Author

Closing this in favor of #22085.

@uckelman uckelman closed this Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Gizmos Visual editor and debug gizmos C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants