Skip to content

Commit e3ad522

Browse files
committed
clean up From<Primitives> for Mesh
1 parent 11bee30 commit e3ad522

File tree

18 files changed

+70
-242
lines changed

18 files changed

+70
-242
lines changed

crates/bevy_math/src/primitives/dim2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ impl From<ConvexPolygon> for Polygon {
19561956
)]
19571957
pub struct ConvexPolygon {
19581958
/// The vertices of the [`ConvexPolygon`].
1959-
vertices: Vec<Vec2>,
1959+
pub vertices: Vec<Vec2>,
19601960
}
19611961

19621962
#[cfg(feature = "alloc")]

crates/bevy_mesh/src/primitives/dim2.rs

Lines changed: 25 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,14 @@ impl Extrudable for CircleMeshBuilder {
8181
impl Meshable for Circle {
8282
type Output = CircleMeshBuilder;
8383

84-
fn mesh(&self) -> Self::Output {
84+
fn mesh(self) -> Self::Output {
8585
CircleMeshBuilder {
86-
circle: *self,
86+
circle: self,
8787
..Default::default()
8888
}
8989
}
9090
}
9191

92-
impl From<Circle> for Mesh {
93-
fn from(circle: Circle) -> Self {
94-
circle.mesh().build()
95-
}
96-
}
97-
9892
/// Specifies how to generate UV-mappings for the [`CircularSector`] and [`CircularSegment`] shapes.
9993
///
10094
/// Currently the only variant is `Mask`, which is good for showing a portion of a texture that includes
@@ -243,23 +237,14 @@ impl Extrudable for CircularSectorMeshBuilder {
243237
impl Meshable for CircularSector {
244238
type Output = CircularSectorMeshBuilder;
245239

246-
fn mesh(&self) -> Self::Output {
240+
fn mesh(self) -> Self::Output {
247241
CircularSectorMeshBuilder {
248-
sector: *self,
242+
sector: self,
249243
..Default::default()
250244
}
251245
}
252246
}
253247

254-
impl From<CircularSector> for Mesh {
255-
/// Converts this sector into a [`Mesh`] using a default [`CircularSectorMeshBuilder`].
256-
///
257-
/// See the documentation of [`CircularSectorMeshBuilder`] for more details.
258-
fn from(sector: CircularSector) -> Self {
259-
sector.mesh().build()
260-
}
261-
}
262-
263248
/// A builder used for creating a [`Mesh`] with a [`CircularSegment`] shape.
264249
///
265250
/// The resulting mesh will have a UV-map such that the center of the circle is
@@ -390,23 +375,14 @@ impl Extrudable for CircularSegmentMeshBuilder {
390375
impl Meshable for CircularSegment {
391376
type Output = CircularSegmentMeshBuilder;
392377

393-
fn mesh(&self) -> Self::Output {
378+
fn mesh(self) -> Self::Output {
394379
CircularSegmentMeshBuilder {
395-
segment: *self,
380+
segment: self,
396381
..Default::default()
397382
}
398383
}
399384
}
400385

401-
impl From<CircularSegment> for Mesh {
402-
/// Converts this sector into a [`Mesh`] using a default [`CircularSegmentMeshBuilder`].
403-
///
404-
/// See the documentation of [`CircularSegmentMeshBuilder`] for more details.
405-
fn from(segment: CircularSegment) -> Self {
406-
segment.mesh().build()
407-
}
408-
}
409-
410386
/// A builder used for creating a [`Mesh`] with a [`ConvexPolygon`] shape.
411387
///
412388
/// You must verify that the `vertices` are not concave when constructing this type. You can
@@ -420,9 +396,9 @@ pub struct ConvexPolygonMeshBuilder {
420396
impl Meshable for ConvexPolygon {
421397
type Output = ConvexPolygonMeshBuilder;
422398

423-
fn mesh(&self) -> Self::Output {
399+
fn mesh(self) -> Self::Output {
424400
Self::Output {
425-
vertices: self.vertices().to_vec(),
401+
vertices: self.vertices,
426402
}
427403
}
428404
}
@@ -456,12 +432,6 @@ impl Extrudable for ConvexPolygonMeshBuilder {
456432
}
457433
}
458434

459-
impl From<ConvexPolygon> for Mesh {
460-
fn from(polygon: ConvexPolygon) -> Self {
461-
polygon.mesh().build()
462-
}
463-
}
464-
465435
/// A builder used for creating a [`Mesh`] with a [`RegularPolygon`] shape.
466436
#[derive(Clone, Copy, Debug, Reflect)]
467437
#[reflect(Default, Debug, Clone)]
@@ -504,7 +474,7 @@ impl RegularPolygonMeshBuilder {
504474
impl Meshable for RegularPolygon {
505475
type Output = RegularPolygonMeshBuilder;
506476

507-
fn mesh(&self) -> Self::Output {
477+
fn mesh(self) -> Self::Output {
508478
Self::Output {
509479
circumradius: self.circumcircle.radius,
510480
sides: self.sides,
@@ -530,12 +500,6 @@ impl Extrudable for RegularPolygonMeshBuilder {
530500
}
531501
}
532502

533-
impl From<RegularPolygon> for Mesh {
534-
fn from(polygon: RegularPolygon) -> Self {
535-
polygon.mesh().build()
536-
}
537-
}
538-
539503
/// A builder used for creating a [`Mesh`] with an [`Ellipse`] shape.
540504
#[derive(Clone, Copy, Debug, Reflect)]
541505
#[reflect(Default, Debug, Clone)]
@@ -627,20 +591,14 @@ impl Extrudable for EllipseMeshBuilder {
627591
impl Meshable for Ellipse {
628592
type Output = EllipseMeshBuilder;
629593

630-
fn mesh(&self) -> Self::Output {
594+
fn mesh(self) -> Self::Output {
631595
EllipseMeshBuilder {
632-
ellipse: *self,
596+
ellipse: self,
633597
..Default::default()
634598
}
635599
}
636600
}
637601

638-
impl From<Ellipse> for Mesh {
639-
fn from(ellipse: Ellipse) -> Self {
640-
ellipse.mesh().build()
641-
}
642-
}
643-
644602
/// A builder used for creating a [`Mesh`] with a [`Segment2d`].
645603
pub struct Segment2dMeshBuilder {
646604
/// The [`Segment2d`] shape.
@@ -669,15 +627,8 @@ impl MeshBuilder for Segment2dMeshBuilder {
669627
impl Meshable for Segment2d {
670628
type Output = Segment2dMeshBuilder;
671629

672-
fn mesh(&self) -> Self::Output {
673-
Segment2dMeshBuilder::new(*self)
674-
}
675-
}
676-
677-
impl From<Segment2d> for Mesh {
678-
/// Converts this segment into a [`Mesh`] using a default [`Segment2dMeshBuilder`].
679-
fn from(segment: Segment2d) -> Self {
680-
segment.mesh().build()
630+
fn mesh(self) -> Self::Output {
631+
Segment2dMeshBuilder::new(self)
681632
}
682633
}
683634

@@ -712,16 +663,8 @@ impl MeshBuilder for Polyline2dMeshBuilder {
712663
impl Meshable for Polyline2d {
713664
type Output = Polyline2dMeshBuilder;
714665

715-
fn mesh(&self) -> Self::Output {
716-
Polyline2dMeshBuilder {
717-
polyline: self.clone(),
718-
}
719-
}
720-
}
721-
722-
impl From<Polyline2d> for Mesh {
723-
fn from(polyline: Polyline2d) -> Self {
724-
polyline.mesh().build()
666+
fn mesh(self) -> Self::Output {
667+
Polyline2dMeshBuilder { polyline: self }
725668
}
726669
}
727670

@@ -844,20 +787,14 @@ impl Extrudable for AnnulusMeshBuilder {
844787
impl Meshable for Annulus {
845788
type Output = AnnulusMeshBuilder;
846789

847-
fn mesh(&self) -> Self::Output {
790+
fn mesh(self) -> Self::Output {
848791
AnnulusMeshBuilder {
849-
annulus: *self,
792+
annulus: self,
850793
..Default::default()
851794
}
852795
}
853796
}
854797

855-
impl From<Annulus> for Mesh {
856-
fn from(annulus: Annulus) -> Self {
857-
annulus.mesh().build()
858-
}
859-
}
860-
861798
/// A builder for creating a [`Mesh`] with an [`Rhombus`] shape.
862799
#[derive(Clone, Copy, Debug, Reflect)]
863800
#[reflect(Default, Debug, Clone)]
@@ -931,19 +868,13 @@ impl Extrudable for RhombusMeshBuilder {
931868
impl Meshable for Rhombus {
932869
type Output = RhombusMeshBuilder;
933870

934-
fn mesh(&self) -> Self::Output {
871+
fn mesh(self) -> Self::Output {
935872
Self::Output {
936873
half_diagonals: self.half_diagonals,
937874
}
938875
}
939876
}
940877

941-
impl From<Rhombus> for Mesh {
942-
fn from(rhombus: Rhombus) -> Self {
943-
rhombus.mesh().build()
944-
}
945-
}
946-
947878
/// A builder used for creating a [`Mesh`] with a [`Triangle2d`] shape.
948879
#[derive(Clone, Copy, Debug, Default, Reflect)]
949880
#[reflect(Default, Debug, Clone)]
@@ -963,8 +894,8 @@ impl Triangle2dMeshBuilder {
963894
impl Meshable for Triangle2d {
964895
type Output = Triangle2dMeshBuilder;
965896

966-
fn mesh(&self) -> Self::Output {
967-
Self::Output { triangle: *self }
897+
fn mesh(self) -> Self::Output {
898+
Self::Output { triangle: self }
968899
}
969900
}
970901

@@ -1015,12 +946,6 @@ impl Extrudable for Triangle2dMeshBuilder {
1015946
}
1016947
}
1017948

1018-
impl From<Triangle2d> for Mesh {
1019-
fn from(triangle: Triangle2d) -> Self {
1020-
triangle.mesh().build()
1021-
}
1022-
}
1023-
1024949
/// A builder used for creating a [`Mesh`] with a [`Rectangle`] shape.
1025950
#[derive(Clone, Copy, Debug, Reflect)]
1026951
#[reflect(Default, Debug, Clone)]
@@ -1088,19 +1013,13 @@ impl Extrudable for RectangleMeshBuilder {
10881013
impl Meshable for Rectangle {
10891014
type Output = RectangleMeshBuilder;
10901015

1091-
fn mesh(&self) -> Self::Output {
1016+
fn mesh(self) -> Self::Output {
10921017
RectangleMeshBuilder {
10931018
half_size: self.half_size,
10941019
}
10951020
}
10961021
}
10971022

1098-
impl From<Rectangle> for Mesh {
1099-
fn from(rectangle: Rectangle) -> Self {
1100-
rectangle.mesh().build()
1101-
}
1102-
}
1103-
11041023
/// A builder used for creating a [`Mesh`] with a [`Capsule2d`] shape.
11051024
#[derive(Clone, Copy, Debug, Reflect)]
11061025
#[reflect(Default, Debug, Clone)]
@@ -1248,20 +1167,14 @@ impl Extrudable for Capsule2dMeshBuilder {
12481167
impl Meshable for Capsule2d {
12491168
type Output = Capsule2dMeshBuilder;
12501169

1251-
fn mesh(&self) -> Self::Output {
1170+
fn mesh(self) -> Self::Output {
12521171
Capsule2dMeshBuilder {
1253-
capsule: *self,
1172+
capsule: self,
12541173
..Default::default()
12551174
}
12561175
}
12571176
}
12581177

1259-
impl From<Capsule2d> for Mesh {
1260-
fn from(capsule: Capsule2d) -> Self {
1261-
capsule.mesh().build()
1262-
}
1263-
}
1264-
12651178
/// A builder used for creating a [`Mesh`] with a [`Ring`] shape.
12661179
pub struct RingMeshBuilder<P>
12671180
where
@@ -1276,7 +1189,7 @@ where
12761189
P: Primitive2d + Meshable,
12771190
{
12781191
/// Create a new `RingMeshBuilder<P>` from a given `Ring<P>` shape.
1279-
pub fn new(ring: &Ring<P>) -> Self {
1192+
pub fn new(ring: Ring<P>) -> Self {
12801193
Self {
12811194
outer_shape_builder: ring.outer_shape.mesh(),
12821195
inner_shape_builder: ring.inner_shape.mesh(),
@@ -1511,20 +1424,11 @@ where
15111424
{
15121425
type Output = RingMeshBuilder<P>;
15131426

1514-
fn mesh(&self) -> Self::Output {
1427+
fn mesh(self) -> Self::Output {
15151428
RingMeshBuilder::new(self)
15161429
}
15171430
}
15181431

1519-
impl<P> From<Ring<P>> for Mesh
1520-
where
1521-
P: Primitive2d + Meshable,
1522-
{
1523-
fn from(ring: Ring<P>) -> Self {
1524-
ring.mesh().build()
1525-
}
1526-
}
1527-
15281432
#[cfg(test)]
15291433
mod tests {
15301434
use bevy_math::{prelude::Annulus, primitives::RegularPolygon, FloatOrd};

crates/bevy_mesh/src/primitives/dim3/capsule.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,10 @@ impl MeshBuilder for Capsule3dMeshBuilder {
421421
impl Meshable for Capsule3d {
422422
type Output = Capsule3dMeshBuilder;
423423

424-
fn mesh(&self) -> Self::Output {
424+
fn mesh(self) -> Self::Output {
425425
Capsule3dMeshBuilder {
426-
capsule: *self,
426+
capsule: self,
427427
..Default::default()
428428
}
429429
}
430430
}
431-
432-
impl From<Capsule3d> for Mesh {
433-
fn from(capsule: Capsule3d) -> Self {
434-
capsule.mesh().build()
435-
}
436-
}

crates/bevy_mesh/src/primitives/dim3/cone.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,14 @@ impl MeshBuilder for ConeMeshBuilder {
174174
impl Meshable for Cone {
175175
type Output = ConeMeshBuilder;
176176

177-
fn mesh(&self) -> Self::Output {
177+
fn mesh(self) -> Self::Output {
178178
ConeMeshBuilder {
179-
cone: *self,
179+
cone: self,
180180
..Default::default()
181181
}
182182
}
183183
}
184184

185-
impl From<Cone> for Mesh {
186-
fn from(cone: Cone) -> Self {
187-
cone.mesh().build()
188-
}
189-
}
190-
191185
#[cfg(test)]
192186
mod tests {
193187
use crate::{Mesh, MeshBuilder, Meshable, VertexAttributeValues};

crates/bevy_mesh/src/primitives/dim3/conical_frustum.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,10 @@ impl MeshBuilder for ConicalFrustumMeshBuilder {
169169
impl Meshable for ConicalFrustum {
170170
type Output = ConicalFrustumMeshBuilder;
171171

172-
fn mesh(&self) -> Self::Output {
172+
fn mesh(self) -> Self::Output {
173173
ConicalFrustumMeshBuilder {
174-
frustum: *self,
174+
frustum: self,
175175
..Default::default()
176176
}
177177
}
178178
}
179-
180-
impl From<ConicalFrustum> for Mesh {
181-
fn from(frustum: ConicalFrustum) -> Self {
182-
frustum.mesh().build()
183-
}
184-
}

0 commit comments

Comments
 (0)