2023-11-20 09:47:50 +00:00
|
|
|
//! Additional [`Gizmos`] Functions -- Circles
|
|
|
|
//!
|
|
|
|
//! Includes the implementation of [`Gizmos::circle`] and [`Gizmos::circle_2d`],
|
|
|
|
//! and assorted support items.
|
|
|
|
|
2024-01-18 15:52:50 +00:00
|
|
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
2024-02-02 21:13:03 +00:00
|
|
|
use bevy_math::Mat2;
|
Rename `Direction2d/3d` to `Dir2/3` (#12189)
# Objective
Split up from #12017, rename Bevy's direction types.
Currently, Bevy has the `Direction2d`, `Direction3d`, and `Direction3dA`
types, which provide a type-level guarantee that their contained vectors
remain normalized. They can be very useful for a lot of APIs for safety,
explicitness, and in some cases performance, as they can sometimes avoid
unnecessary normalizations.
However, many consider them to be inconvenient to use, and opt for
standard vector types like `Vec3` because of this. One reason is that
the direction type names are a bit long and can be annoying to write (of
course you can use autocomplete, but just typing `Vec3` is still nicer),
and in some intances, the extra characters can make formatting worse.
The naming is also inconsistent with Glam's shorter type names, and
results in names like `Direction3dA`, which (in my opinion) are
difficult to read and even a bit ugly.
This PR proposes renaming the types to `Dir2`, `Dir3`, and `Dir3A`.
These names are nice and easy to write, consistent with Glam, and work
well for variants like the SIMD aligned `Dir3A`. As a bonus, it can also
result in nicer formatting in a lot of cases, which can be seen from the
diff of this PR.
Some examples of what it looks like: (copied from #12017)
```rust
// Before
let ray_cast = RayCast2d::new(Vec2::ZERO, Direction2d::X, 5.0);
// After
let ray_cast = RayCast2d::new(Vec2::ZERO, Dir2::X, 5.0);
```
```rust
// Before (an example using Bevy XPBD)
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Direction3d::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
// After
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Dir3::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
```
```rust
// Before
self.circle(
Vec3::new(0.0, -2.0, 0.0),
Direction3d::Y,
5.0,
Color::TURQUOISE,
);
// After (formatting is collapsed in this case)
self.circle(Vec3::new(0.0, -2.0, 0.0), Dir3::Y, 5.0, Color::TURQUOISE);
```
## Solution
Rename `Direction2d`, `Direction3d`, and `Direction3dA` to `Dir2`,
`Dir3`, and `Dir3A`.
---
## Migration Guide
The `Direction2d` and `Direction3d` types have been renamed to `Dir2`
and `Dir3`.
## Additional Context
This has been brought up on the Discord a few times, and we had a small
[poll](https://discord.com/channels/691052431525675048/1203087353850364004/1212465038711984158)
on this. `Dir2`/`Dir3`/`Dir3A` was quite unanimously chosen as the best
option, but of course it was a very small poll and inconclusive, so
other opinions are certainly welcome too.
---------
Co-authored-by: IceSentry <c.giguere42@gmail.com>
2024-02-28 22:48:43 +00:00
|
|
|
use bevy_math::{Dir3, Quat, Vec2, Vec3};
|
2024-02-24 21:35:32 +00:00
|
|
|
use bevy_render::color::LegacyColor;
|
2023-11-20 09:47:50 +00:00
|
|
|
use std::f32::consts::TAU;
|
|
|
|
|
|
|
|
pub(crate) const DEFAULT_CIRCLE_SEGMENTS: usize = 32;
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
fn ellipse_inner(half_size: Vec2, segments: usize) -> impl Iterator<Item = Vec2> {
|
2023-11-20 09:47:50 +00:00
|
|
|
(0..segments + 1).map(move |i| {
|
|
|
|
let angle = i as f32 * TAU / segments as f32;
|
2024-02-02 21:13:03 +00:00
|
|
|
let (x, y) = angle.sin_cos();
|
|
|
|
Vec2::new(x, y) * half_size
|
2023-11-20 09:47:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-01-18 15:52:50 +00:00
|
|
|
impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
2024-02-02 21:13:03 +00:00
|
|
|
/// Draw an ellipse in 3D at `position` with the flat side facing `normal`.
|
|
|
|
///
|
|
|
|
/// This should be called for each frame the ellipse needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_render::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
2024-02-24 21:35:32 +00:00
|
|
|
/// gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), LegacyColor::GREEN);
|
2024-02-02 21:13:03 +00:00
|
|
|
///
|
|
|
|
/// // Ellipses have 32 line-segments by default.
|
|
|
|
/// // You may want to increase this for larger ellipses.
|
|
|
|
/// gizmos
|
2024-02-24 21:35:32 +00:00
|
|
|
/// .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), LegacyColor::RED)
|
2024-02-02 21:13:03 +00:00
|
|
|
/// .segments(64);
|
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn ellipse(
|
|
|
|
&mut self,
|
|
|
|
position: Vec3,
|
|
|
|
rotation: Quat,
|
|
|
|
half_size: Vec2,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2024-02-02 21:13:03 +00:00
|
|
|
) -> EllipseBuilder<'_, 'w, 's, T> {
|
|
|
|
EllipseBuilder {
|
|
|
|
gizmos: self,
|
|
|
|
position,
|
|
|
|
rotation,
|
|
|
|
half_size,
|
|
|
|
color,
|
|
|
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Draw an ellipse in 2D.
|
|
|
|
///
|
|
|
|
/// This should be called for each frame the ellipse needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_render::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
2024-02-24 21:35:32 +00:00
|
|
|
/// gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), LegacyColor::GREEN);
|
2024-02-02 21:13:03 +00:00
|
|
|
///
|
|
|
|
/// // Ellipses have 32 line-segments by default.
|
|
|
|
/// // You may want to increase this for larger ellipses.
|
|
|
|
/// gizmos
|
2024-02-24 21:35:32 +00:00
|
|
|
/// .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), LegacyColor::RED)
|
2024-02-02 21:13:03 +00:00
|
|
|
/// .segments(64);
|
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn ellipse_2d(
|
|
|
|
&mut self,
|
|
|
|
position: Vec2,
|
|
|
|
angle: f32,
|
|
|
|
half_size: Vec2,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2024-02-02 21:13:03 +00:00
|
|
|
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
|
|
|
Ellipse2dBuilder {
|
|
|
|
gizmos: self,
|
|
|
|
position,
|
|
|
|
rotation: Mat2::from_angle(angle),
|
|
|
|
half_size,
|
|
|
|
color,
|
|
|
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 09:47:50 +00:00
|
|
|
/// Draw a circle in 3D at `position` with the flat side facing `normal`.
|
|
|
|
///
|
|
|
|
/// This should be called for each frame the circle needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_render::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
Rename `Direction2d/3d` to `Dir2/3` (#12189)
# Objective
Split up from #12017, rename Bevy's direction types.
Currently, Bevy has the `Direction2d`, `Direction3d`, and `Direction3dA`
types, which provide a type-level guarantee that their contained vectors
remain normalized. They can be very useful for a lot of APIs for safety,
explicitness, and in some cases performance, as they can sometimes avoid
unnecessary normalizations.
However, many consider them to be inconvenient to use, and opt for
standard vector types like `Vec3` because of this. One reason is that
the direction type names are a bit long and can be annoying to write (of
course you can use autocomplete, but just typing `Vec3` is still nicer),
and in some intances, the extra characters can make formatting worse.
The naming is also inconsistent with Glam's shorter type names, and
results in names like `Direction3dA`, which (in my opinion) are
difficult to read and even a bit ugly.
This PR proposes renaming the types to `Dir2`, `Dir3`, and `Dir3A`.
These names are nice and easy to write, consistent with Glam, and work
well for variants like the SIMD aligned `Dir3A`. As a bonus, it can also
result in nicer formatting in a lot of cases, which can be seen from the
diff of this PR.
Some examples of what it looks like: (copied from #12017)
```rust
// Before
let ray_cast = RayCast2d::new(Vec2::ZERO, Direction2d::X, 5.0);
// After
let ray_cast = RayCast2d::new(Vec2::ZERO, Dir2::X, 5.0);
```
```rust
// Before (an example using Bevy XPBD)
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Direction3d::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
// After
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Dir3::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
```
```rust
// Before
self.circle(
Vec3::new(0.0, -2.0, 0.0),
Direction3d::Y,
5.0,
Color::TURQUOISE,
);
// After (formatting is collapsed in this case)
self.circle(Vec3::new(0.0, -2.0, 0.0), Dir3::Y, 5.0, Color::TURQUOISE);
```
## Solution
Rename `Direction2d`, `Direction3d`, and `Direction3dA` to `Dir2`,
`Dir3`, and `Dir3A`.
---
## Migration Guide
The `Direction2d` and `Direction3d` types have been renamed to `Dir2`
and `Dir3`.
## Additional Context
This has been brought up on the Discord a few times, and we had a small
[poll](https://discord.com/channels/691052431525675048/1203087353850364004/1212465038711984158)
on this. `Dir2`/`Dir3`/`Dir3A` was quite unanimously chosen as the best
option, but of course it was a very small poll and inconclusive, so
other opinions are certainly welcome too.
---------
Co-authored-by: IceSentry <c.giguere42@gmail.com>
2024-02-28 22:48:43 +00:00
|
|
|
/// gizmos.circle(Vec3::ZERO, Dir3::Z, 1., LegacyColor::GREEN);
|
2023-11-20 09:47:50 +00:00
|
|
|
///
|
|
|
|
/// // Circles have 32 line-segments by default.
|
|
|
|
/// // You may want to increase this for larger circles.
|
|
|
|
/// gizmos
|
Rename `Direction2d/3d` to `Dir2/3` (#12189)
# Objective
Split up from #12017, rename Bevy's direction types.
Currently, Bevy has the `Direction2d`, `Direction3d`, and `Direction3dA`
types, which provide a type-level guarantee that their contained vectors
remain normalized. They can be very useful for a lot of APIs for safety,
explicitness, and in some cases performance, as they can sometimes avoid
unnecessary normalizations.
However, many consider them to be inconvenient to use, and opt for
standard vector types like `Vec3` because of this. One reason is that
the direction type names are a bit long and can be annoying to write (of
course you can use autocomplete, but just typing `Vec3` is still nicer),
and in some intances, the extra characters can make formatting worse.
The naming is also inconsistent with Glam's shorter type names, and
results in names like `Direction3dA`, which (in my opinion) are
difficult to read and even a bit ugly.
This PR proposes renaming the types to `Dir2`, `Dir3`, and `Dir3A`.
These names are nice and easy to write, consistent with Glam, and work
well for variants like the SIMD aligned `Dir3A`. As a bonus, it can also
result in nicer formatting in a lot of cases, which can be seen from the
diff of this PR.
Some examples of what it looks like: (copied from #12017)
```rust
// Before
let ray_cast = RayCast2d::new(Vec2::ZERO, Direction2d::X, 5.0);
// After
let ray_cast = RayCast2d::new(Vec2::ZERO, Dir2::X, 5.0);
```
```rust
// Before (an example using Bevy XPBD)
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Direction3d::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
// After
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Dir3::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
```
```rust
// Before
self.circle(
Vec3::new(0.0, -2.0, 0.0),
Direction3d::Y,
5.0,
Color::TURQUOISE,
);
// After (formatting is collapsed in this case)
self.circle(Vec3::new(0.0, -2.0, 0.0), Dir3::Y, 5.0, Color::TURQUOISE);
```
## Solution
Rename `Direction2d`, `Direction3d`, and `Direction3dA` to `Dir2`,
`Dir3`, and `Dir3A`.
---
## Migration Guide
The `Direction2d` and `Direction3d` types have been renamed to `Dir2`
and `Dir3`.
## Additional Context
This has been brought up on the Discord a few times, and we had a small
[poll](https://discord.com/channels/691052431525675048/1203087353850364004/1212465038711984158)
on this. `Dir2`/`Dir3`/`Dir3A` was quite unanimously chosen as the best
option, but of course it was a very small poll and inconclusive, so
other opinions are certainly welcome too.
---------
Co-authored-by: IceSentry <c.giguere42@gmail.com>
2024-02-28 22:48:43 +00:00
|
|
|
/// .circle(Vec3::ZERO, Dir3::Z, 5., LegacyColor::RED)
|
2023-11-20 09:47:50 +00:00
|
|
|
/// .segments(64);
|
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn circle(
|
|
|
|
&mut self,
|
|
|
|
position: Vec3,
|
Rename `Direction2d/3d` to `Dir2/3` (#12189)
# Objective
Split up from #12017, rename Bevy's direction types.
Currently, Bevy has the `Direction2d`, `Direction3d`, and `Direction3dA`
types, which provide a type-level guarantee that their contained vectors
remain normalized. They can be very useful for a lot of APIs for safety,
explicitness, and in some cases performance, as they can sometimes avoid
unnecessary normalizations.
However, many consider them to be inconvenient to use, and opt for
standard vector types like `Vec3` because of this. One reason is that
the direction type names are a bit long and can be annoying to write (of
course you can use autocomplete, but just typing `Vec3` is still nicer),
and in some intances, the extra characters can make formatting worse.
The naming is also inconsistent with Glam's shorter type names, and
results in names like `Direction3dA`, which (in my opinion) are
difficult to read and even a bit ugly.
This PR proposes renaming the types to `Dir2`, `Dir3`, and `Dir3A`.
These names are nice and easy to write, consistent with Glam, and work
well for variants like the SIMD aligned `Dir3A`. As a bonus, it can also
result in nicer formatting in a lot of cases, which can be seen from the
diff of this PR.
Some examples of what it looks like: (copied from #12017)
```rust
// Before
let ray_cast = RayCast2d::new(Vec2::ZERO, Direction2d::X, 5.0);
// After
let ray_cast = RayCast2d::new(Vec2::ZERO, Dir2::X, 5.0);
```
```rust
// Before (an example using Bevy XPBD)
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Direction3d::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
// After
let hit = spatial_query.cast_ray(
Vec3::ZERO,
Dir3::X,
f32::MAX,
true,
SpatialQueryFilter::default(),
);
```
```rust
// Before
self.circle(
Vec3::new(0.0, -2.0, 0.0),
Direction3d::Y,
5.0,
Color::TURQUOISE,
);
// After (formatting is collapsed in this case)
self.circle(Vec3::new(0.0, -2.0, 0.0), Dir3::Y, 5.0, Color::TURQUOISE);
```
## Solution
Rename `Direction2d`, `Direction3d`, and `Direction3dA` to `Dir2`,
`Dir3`, and `Dir3A`.
---
## Migration Guide
The `Direction2d` and `Direction3d` types have been renamed to `Dir2`
and `Dir3`.
## Additional Context
This has been brought up on the Discord a few times, and we had a small
[poll](https://discord.com/channels/691052431525675048/1203087353850364004/1212465038711984158)
on this. `Dir2`/`Dir3`/`Dir3A` was quite unanimously chosen as the best
option, but of course it was a very small poll and inconclusive, so
other opinions are certainly welcome too.
---------
Co-authored-by: IceSentry <c.giguere42@gmail.com>
2024-02-28 22:48:43 +00:00
|
|
|
normal: Dir3,
|
2023-11-20 09:47:50 +00:00
|
|
|
radius: f32,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2024-02-02 21:13:03 +00:00
|
|
|
) -> EllipseBuilder<'_, 'w, 's, T> {
|
|
|
|
EllipseBuilder {
|
2023-11-20 09:47:50 +00:00
|
|
|
gizmos: self,
|
|
|
|
position,
|
2024-02-02 21:13:03 +00:00
|
|
|
rotation: Quat::from_rotation_arc(Vec3::Z, *normal),
|
|
|
|
half_size: Vec2::splat(radius),
|
2023-11-20 09:47:50 +00:00
|
|
|
color,
|
|
|
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Draw a circle in 2D.
|
|
|
|
///
|
|
|
|
/// This should be called for each frame the circle needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_render::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
2024-02-24 21:35:32 +00:00
|
|
|
/// gizmos.circle_2d(Vec2::ZERO, 1., LegacyColor::GREEN);
|
2023-11-20 09:47:50 +00:00
|
|
|
///
|
|
|
|
/// // Circles have 32 line-segments by default.
|
|
|
|
/// // You may want to increase this for larger circles.
|
|
|
|
/// gizmos
|
2024-02-24 21:35:32 +00:00
|
|
|
/// .circle_2d(Vec2::ZERO, 5., LegacyColor::RED)
|
2023-11-20 09:47:50 +00:00
|
|
|
/// .segments(64);
|
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn circle_2d(
|
|
|
|
&mut self,
|
|
|
|
position: Vec2,
|
|
|
|
radius: f32,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2024-02-02 21:13:03 +00:00
|
|
|
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
|
|
|
Ellipse2dBuilder {
|
2023-11-20 09:47:50 +00:00
|
|
|
gizmos: self,
|
|
|
|
position,
|
2024-02-02 21:13:03 +00:00
|
|
|
rotation: Mat2::IDENTITY,
|
|
|
|
half_size: Vec2::splat(radius),
|
2023-11-20 09:47:50 +00:00
|
|
|
color,
|
|
|
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
/// A builder returned by [`Gizmos::ellipse`].
|
|
|
|
pub struct EllipseBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
2024-01-18 15:52:50 +00:00
|
|
|
gizmos: &'a mut Gizmos<'w, 's, T>,
|
2023-11-20 09:47:50 +00:00
|
|
|
position: Vec3,
|
2024-02-02 21:13:03 +00:00
|
|
|
rotation: Quat,
|
|
|
|
half_size: Vec2,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2023-11-20 09:47:50 +00:00
|
|
|
segments: usize,
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
impl<T: GizmoConfigGroup> EllipseBuilder<'_, '_, '_, T> {
|
|
|
|
/// Set the number of line-segments for this ellipse.
|
2023-11-20 09:47:50 +00:00
|
|
|
pub fn segments(mut self, segments: usize) -> Self {
|
|
|
|
self.segments = segments;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
impl<T: GizmoConfigGroup> Drop for EllipseBuilder<'_, '_, '_, T> {
|
2023-11-20 09:47:50 +00:00
|
|
|
fn drop(&mut self) {
|
2024-01-18 15:52:50 +00:00
|
|
|
if !self.gizmos.enabled {
|
|
|
|
return;
|
|
|
|
}
|
2024-02-02 21:13:03 +00:00
|
|
|
|
|
|
|
let positions = ellipse_inner(self.half_size, self.segments)
|
|
|
|
.map(|vec2| self.rotation * vec2.extend(0.))
|
|
|
|
.map(|vec3| vec3 + self.position);
|
2023-11-20 09:47:50 +00:00
|
|
|
self.gizmos.linestrip(positions, self.color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
/// A builder returned by [`Gizmos::ellipse_2d`].
|
|
|
|
pub struct Ellipse2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
2024-01-18 15:52:50 +00:00
|
|
|
gizmos: &'a mut Gizmos<'w, 's, T>,
|
2023-11-20 09:47:50 +00:00
|
|
|
position: Vec2,
|
2024-02-02 21:13:03 +00:00
|
|
|
rotation: Mat2,
|
|
|
|
half_size: Vec2,
|
2024-02-24 21:35:32 +00:00
|
|
|
color: LegacyColor,
|
2023-11-20 09:47:50 +00:00
|
|
|
segments: usize,
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
impl<T: GizmoConfigGroup> Ellipse2dBuilder<'_, '_, '_, T> {
|
|
|
|
/// Set the number of line-segments for this ellipse.
|
2023-11-20 09:47:50 +00:00
|
|
|
pub fn segments(mut self, segments: usize) -> Self {
|
|
|
|
self.segments = segments;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 21:13:03 +00:00
|
|
|
impl<T: GizmoConfigGroup> Drop for Ellipse2dBuilder<'_, '_, '_, T> {
|
2023-11-20 09:47:50 +00:00
|
|
|
fn drop(&mut self) {
|
2024-01-18 15:52:50 +00:00
|
|
|
if !self.gizmos.enabled {
|
|
|
|
return;
|
2024-02-02 21:13:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let positions = ellipse_inner(self.half_size, self.segments)
|
|
|
|
.map(|vec2| self.rotation * vec2)
|
|
|
|
.map(|vec2| vec2 + self.position);
|
2023-11-20 09:47:50 +00:00
|
|
|
self.gizmos.linestrip_2d(positions, self.color);
|
|
|
|
}
|
|
|
|
}
|