From be55277a3feb5a23189aa6b9757d56cf88244be1 Mon Sep 17 00:00:00 2001 From: copygirl Date: Wed, 26 Mar 2025 19:09:24 +0100 Subject: [PATCH] Add Region to (min, max) conversion --- src/bloxel/generic_math/region.rs | 8 ++++++++ src/bloxel/math/block_region.rs | 8 ++++++++ src/bloxel/math/chunk_region.rs | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/bloxel/generic_math/region.rs b/src/bloxel/generic_math/region.rs index 13f8225..a02b75b 100644 --- a/src/bloxel/generic_math/region.rs +++ b/src/bloxel/generic_math/region.rs @@ -132,6 +132,14 @@ impl std::hash::Hash for Region { } } +// Conversion + +impl From> for (Pos, Pos) { + fn from(Region { min, max, .. }: Region) -> Self { + (min.into(), max.into()) + } +} + // Offsetting impl Add for Region { diff --git a/src/bloxel/math/block_region.rs b/src/bloxel/math/block_region.rs index 3af9d6e..91eba0d 100644 --- a/src/bloxel/math/block_region.rs +++ b/src/bloxel/math/block_region.rs @@ -85,3 +85,11 @@ overload!((l: ?BlockRegion) + (r: IVec3) -> BlockRegion { BlockRegion::new_unche overload!((l: ?BlockRegion) - (r: IVec3) -> BlockRegion { BlockRegion::new_unchecked(l.min - r, l.max - r) }); overload!((s: &mut BlockRegion) += (v: IVec3) { s.min += v; s.max += v; }); overload!((s: &mut BlockRegion) -= (v: IVec3) { s.min -= v; s.max -= v; }); + +// Conversion + +impl From for (BlockPos, BlockPos) { + fn from(BlockRegion { min, max }: BlockRegion) -> Self { + (min, max) + } +} diff --git a/src/bloxel/math/chunk_region.rs b/src/bloxel/math/chunk_region.rs index ba79b6f..39ae0f2 100644 --- a/src/bloxel/math/chunk_region.rs +++ b/src/bloxel/math/chunk_region.rs @@ -92,3 +92,11 @@ overload!((l: ?ChunkRegion) + (r: IVec3) -> ChunkRegion { ChunkRegion::new_unche overload!((l: ?ChunkRegion) - (r: IVec3) -> ChunkRegion { ChunkRegion::new_unchecked(l.min - r, l.max - r) }); overload!((s: &mut ChunkRegion) += (v: IVec3) { s.min += v; s.max += v; }); overload!((s: &mut ChunkRegion) -= (v: IVec3) { s.min -= v; s.max -= v; }); + +// Conversion + +impl From for (ChunkPos, ChunkPos) { + fn from(ChunkRegion { min, max }: ChunkRegion) -> Self { + (min, max) + } +}