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

RegularPolygon should allow circumradius to be 0.0 #13332

Closed
mamekoro opened this issue May 11, 2024 · 1 comment · Fixed by #13365
Closed

RegularPolygon should allow circumradius to be 0.0 #13332

mamekoro opened this issue May 11, 2024 · 1 comment · Fixed by #13365
Labels
A-Math Fundamental domain-agnostic mathematical operations C-Usability A simple quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! X-Uncontroversial This work is generally agreed upon

Comments

@mamekoro
Copy link
Contributor

What problem does this solve or what need does it fill?

It currently panics when circumradius is zero.

assert!(circumradius > 0.0, "polygon has a non-positive radius");

Is there any advantage to rejecting 0.0?

Since the value 0.0 is frequently used as a default or minimum value, not allowing it would increase the chances of the game panicking.

Consider, for example, an animation that smoothly resizes a circle. When the circle appears, the radius increases from zero, and when the circle disappears, the radius decreases toward zero. Implementing this animation in v0.12 is simple, but v0.13 requires additional code to make the radius greater than zero to prevent panic.

What solution would you like?

That assertion should be circumradius >= 0.0 to allow zero.

Additional context

Bevy v0.12 can handle a circle of radius 0.0, but v0.13 panics.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, startup)
        .run();
}

fn startup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((
        // v0.12 (no panic)
        // ColorMesh2dBundle {
        //     mesh: meshes.add(shape::Circle::new(0.0).into()).into(),
        //     material: materials.add(Color::WHITE.into()),
        //     ..default()
        // },

        // v0.13 (panics)
        ColorMesh2dBundle {
            mesh: meshes.add(Circle::new(0.0)).into(),
            material: materials.add(Color::WHITE),
            ..default()
        },
    ));
}
@mamekoro mamekoro added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels May 11, 2024
@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy C-Usability A simple quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! X-Uncontroversial This work is generally agreed upon and removed C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels May 13, 2024
@alice-i-cecile
Copy link
Member

Agreed, I'm fully on board with this change. We should ensure that all of our shapes can scale down to (but not past) 0 in the same PR.

KaylaJoyGray added a commit to KaylaJoyGray/bevy that referenced this issue May 14, 2024
- Ensure that shapes can scale down to, but not past, 0.0

- modified the constructor of RegularPolygon and added asserts for other 2d primitives where applicable

- The example program from the issue now runs without panicking
github-merge-queue bot pushed a commit that referenced this issue May 16, 2024
# Objective

Fixes #13332.

## Solution

The assertion `circumradius >= 0.0` to allow zero.

Are there any other shapes that need to be allowed to be constructed
with zero?

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
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 C-Usability A simple quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants