pub struct Position {
pub x: i32,
pub y: i32,
pub z: i32,
}Fields§
§x: i32§y: i32§z: i32Implementations§
Source§impl Position
impl Position
pub const ZERO: Self
pub const ONE: Self
pub const CHUNK_SIZE: Self
pub const CHUNK_HALF: Self
pub const X: Self
pub const Y: Self
pub const Z: Self
pub const NORTH: Self
pub const SOUTH: Self
pub const EAST: Self
pub const WEST: Self
pub const UP: Self
pub const DOWN: Self
Sourcepub const fn new(x: i32, y: i32, z: i32) -> Self
pub const fn new(x: i32, y: i32, z: i32) -> Self
Examples found in repository?
examples/world_move_bricks.rs (line 26)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let path = PathBuf::from("world.brdb");
7 let dst = PathBuf::from("world_patched.brdb");
8
9 println!("Warning - This code will break if the brick chunk struct changes!!");
10
11 let db = Brdb::open(path)?.into_reader();
12
13 let data = db.global_data()?;
14 let mut grid = UnsavedGrid::default();
15
16 let mut total_bricks = 0;
17 for chunk in db.brick_chunk_index(1)? {
18 for brick in db
19 .brick_chunk_soa(1, chunk.index)?
20 .iter_bricks(chunk.index, data.clone())
21 {
22 // If we wanted wires/components, we'd need to track the bricks here by their chunk index and brick index
23 total_bricks += 1;
24
25 let mut brick = brick?;
26 brick.position += Position::new(3000, 0, 0);
27 grid.add_brick(data.as_ref(), &brick);
28 }
29
30 if chunk.num_components > 0 {
31 println!("sorry, this example doesn't handle components");
32 }
33 if chunk.num_wires > 0 {
34 println!("sorry, this example doesn't handle wires");
35 }
36 }
37 println!("{total_bricks} bricks");
38
39 let mut pending = db.to_pending()?;
40
41 // Replace the main grid (1) with the grid we created
42 *pending.cd_mut("World/0/Bricks/Grids/1")? = grid.to_pending(
43 data.proc_brick_starting_index(),
44 db.components_schema()?.as_ref(),
45 )?;
46
47 if dst.exists() {
48 std::fs::remove_file(&dst)?;
49 }
50 Brdb::new(&dst)?.write_pending("Move the bricks", pending)?;
51
52 // Verify bricks can be read
53 let db = Brdb::open(dst)?.into_reader();
54 for chunk in db.brick_chunk_index(1)? {
55 let _ = db.brick_chunk_soa(1, chunk.index)?;
56 }
57
58 Ok(())
59}pub fn to_relative(self) -> (ChunkIndex, RelativePosition)
pub fn from_relative(chunk: ChunkIndex, pos: RelativePosition) -> Self
Trait Implementations§
Source§impl AddAssign for Position
impl AddAssign for Position
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl DivAssign<i32> for Position
impl DivAssign<i32> for Position
Source§fn div_assign(&mut self, scalar: i32)
fn div_assign(&mut self, scalar: i32)
Performs the
/= operation. Read moreSource§impl MulAssign<i32> for Position
impl MulAssign<i32> for Position
Source§fn mul_assign(&mut self, scalar: i32)
fn mul_assign(&mut self, scalar: i32)
Performs the
*= operation. Read moreSource§impl Ord for Position
impl Ord for Position
Source§impl PartialOrd for Position
impl PartialOrd for Position
Source§impl SubAssign for Position
impl SubAssign for Position
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-= operation. Read moreimpl Copy for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more