Skip to content

Commit 2f0b5b9

Browse files
authored
Use impl Into<Color> for gizmos.primitive_3d(...) (#12915)
# Objective - All gizmos APIs besides `gizmos.primitive_3d` use `impl Into<Color>` as their type for `color`. ## Solution - This PR changes `primitive_3d()` to use `impl Into<Color>` aswell.
1 parent ab7cbfa commit 2f0b5b9

File tree

1 file changed

+23
-21
lines changed
  • crates/bevy_gizmos/src/primitives

1 file changed

+23
-21
lines changed

crates/bevy_gizmos/src/primitives/dim3.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait GizmoPrimitive3d<P: Primitive3d> {
2929
primitive: P,
3030
position: Vec3,
3131
rotation: Quat,
32-
color: Color,
32+
color: impl Into<Color>,
3333
) -> Self::Output<'_>;
3434
}
3535

@@ -43,7 +43,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Dir3> for Gizmos<'w, 's, T> {
4343
primitive: Dir3,
4444
position: Vec3,
4545
rotation: Quat,
46-
color: Color,
46+
color: impl Into<Color>,
4747
) -> Self::Output<'_> {
4848
self.arrow(position, position + (rotation * *primitive), color);
4949
}
@@ -85,14 +85,14 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Sphere> for Gizmos<'w, 's, T>
8585
primitive: Sphere,
8686
position: Vec3,
8787
rotation: Quat,
88-
color: Color,
88+
color: impl Into<Color>,
8989
) -> Self::Output<'_> {
9090
SphereBuilder {
9191
gizmos: self,
9292
radius: primitive.radius,
9393
position,
9494
rotation,
95-
color,
95+
color: color.into(),
9696
segments: DEFAULT_NUMBER_SEGMENTS,
9797
}
9898
}
@@ -184,14 +184,14 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Plane3d> for Gizmos<'w, 's, T
184184
primitive: Plane3d,
185185
position: Vec3,
186186
rotation: Quat,
187-
color: Color,
187+
color: impl Into<Color>,
188188
) -> Self::Output<'_> {
189189
Plane3dBuilder {
190190
gizmos: self,
191191
normal: primitive.normal,
192192
rotation,
193193
position,
194-
color,
194+
color: color.into(),
195195
axis_count: 4,
196196
segment_count: 3,
197197
segment_length: 0.25,
@@ -251,12 +251,13 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Line3d> for Gizmos<'w, 's, T>
251251
primitive: Line3d,
252252
position: Vec3,
253253
rotation: Quat,
254-
color: Color,
254+
color: impl Into<Color>,
255255
) -> Self::Output<'_> {
256256
if !self.enabled {
257257
return;
258258
}
259259

260+
let color = color.into();
260261
let direction = rotation * *primitive.direction;
261262
self.arrow(position, position + direction, color);
262263

@@ -278,7 +279,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Segment3d> for Gizmos<'w, 's,
278279
primitive: Segment3d,
279280
position: Vec3,
280281
rotation: Quat,
281-
color: Color,
282+
color: impl Into<Color>,
282283
) -> Self::Output<'_> {
283284
if !self.enabled {
284285
return;
@@ -303,7 +304,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive3d<Polyline3d<N>
303304
primitive: Polyline3d<N>,
304305
position: Vec3,
305306
rotation: Quat,
306-
color: Color,
307+
color: impl Into<Color>,
307308
) -> Self::Output<'_> {
308309
if !self.enabled {
309310
return;
@@ -328,7 +329,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<BoxedPolyline3d> for Gizmos<'
328329
primitive: BoxedPolyline3d,
329330
position: Vec3,
330331
rotation: Quat,
331-
color: Color,
332+
color: impl Into<Color>,
332333
) -> Self::Output<'_> {
333334
if !self.enabled {
334335
return;
@@ -355,7 +356,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cuboid> for Gizmos<'w, 's, T>
355356
primitive: Cuboid,
356357
position: Vec3,
357358
rotation: Quat,
358-
color: Color,
359+
color: impl Into<Color>,
359360
) -> Self::Output<'_> {
360361
if !self.enabled {
361362
return;
@@ -390,6 +391,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cuboid> for Gizmos<'w, 's, T>
390391
// lines connecting upper and lower rectangles of the cuboid
391392
let connections = vertices.into_iter().zip(vertices.into_iter().skip(4));
392393

394+
let color = color.into();
393395
upper
394396
.chain(lower)
395397
.chain(connections)
@@ -439,15 +441,15 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cylinder> for Gizmos<'w, 's,
439441
primitive: Cylinder,
440442
position: Vec3,
441443
rotation: Quat,
442-
color: Color,
444+
color: impl Into<Color>,
443445
) -> Self::Output<'_> {
444446
Cylinder3dBuilder {
445447
gizmos: self,
446448
radius: primitive.radius,
447449
half_height: primitive.half_height,
448450
position,
449451
rotation,
450-
color,
452+
color: color.into(),
451453
segments: DEFAULT_NUMBER_SEGMENTS,
452454
}
453455
}
@@ -536,15 +538,15 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Capsule3d> for Gizmos<'w, 's,
536538
primitive: Capsule3d,
537539
position: Vec3,
538540
rotation: Quat,
539-
color: Color,
541+
color: impl Into<Color>,
540542
) -> Self::Output<'_> {
541543
Capsule3dBuilder {
542544
gizmos: self,
543545
radius: primitive.radius,
544546
half_length: primitive.half_length,
545547
position,
546548
rotation,
547-
color,
549+
color: color.into(),
548550
segments: DEFAULT_NUMBER_SEGMENTS,
549551
}
550552
}
@@ -651,15 +653,15 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cone> for Gizmos<'w, 's, T> {
651653
primitive: Cone,
652654
position: Vec3,
653655
rotation: Quat,
654-
color: Color,
656+
color: impl Into<Color>,
655657
) -> Self::Output<'_> {
656658
Cone3dBuilder {
657659
gizmos: self,
658660
radius: primitive.radius,
659661
height: primitive.height,
660662
position,
661663
rotation,
662-
color,
664+
color: color.into(),
663665
base_segments: DEFAULT_NUMBER_SEGMENTS,
664666
height_segments: DEFAULT_NUMBER_SEGMENTS,
665667
}
@@ -749,7 +751,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<ConicalFrustum> for Gizmos<'w
749751
primitive: ConicalFrustum,
750752
position: Vec3,
751753
rotation: Quat,
752-
color: Color,
754+
color: impl Into<Color>,
753755
) -> Self::Output<'_> {
754756
ConicalFrustum3dBuilder {
755757
gizmos: self,
@@ -758,7 +760,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<ConicalFrustum> for Gizmos<'w
758760
height: primitive.height,
759761
position,
760762
rotation,
761-
color,
763+
color: color.into(),
762764
segments: DEFAULT_NUMBER_SEGMENTS,
763765
}
764766
}
@@ -861,15 +863,15 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Torus> for Gizmos<'w, 's, T>
861863
primitive: Torus,
862864
position: Vec3,
863865
rotation: Quat,
864-
color: Color,
866+
color: impl Into<Color>,
865867
) -> Self::Output<'_> {
866868
Torus3dBuilder {
867869
gizmos: self,
868870
minor_radius: primitive.minor_radius,
869871
major_radius: primitive.major_radius,
870872
position,
871873
rotation,
872-
color,
874+
color: color.into(),
873875
minor_segments: DEFAULT_NUMBER_SEGMENTS,
874876
major_segments: DEFAULT_NUMBER_SEGMENTS,
875877
}

0 commit comments

Comments
 (0)