Skip to content

Commit

Permalink
Move Rect to shape module
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNintendoNerd committed Feb 19, 2024
1 parent e2fd0e4 commit e4b8474
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lvd_lib/src/objects/field_smash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use serde::{Deserialize, Serialize};
use crate::{
id::Id,
objects::{base::Base, region::Region},
shape::{LvdPath, LvdShape2, LvdShape3},
shape::{LvdPath, LvdShape2, LvdShape3, Rect},
string::LvdFixedString32,
tag::Tag,
util::{Rect, Vector2},
util::Vector2,
version::{Version, Versioned},
};

Expand Down
2 changes: 1 addition & 1 deletion lvd_lib/src/objects/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::{
objects::base::{Base, MetaInfo},
util::Rect,
shape::Rect,
version::{Version, Versioned},
};

Expand Down
33 changes: 32 additions & 1 deletion lvd_lib/src/shape.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Basic shape types.
//!
//! This module contains the [`LvdShape2`], [`LvdShape2Array`] and [`LvdShape2Element`] types,
//! the [`LvdShape3`] type, and the [`LvdPath`] type.
//! the [`LvdShape3`] type, the [`LvdPath`] type, and the [`Rect`] type.
use binrw::binrw;

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -237,3 +237,34 @@ impl Version for LvdPath {
}
}
}

/// A two-dimensional rectangle type.
#[binrw]
#[br(import(version: u8))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Rect {
/// `Rect` version 1.
#[br(pre_assert(version == 1))]
V1 {
/// Coordinate of the left edge.
left: f32,

/// Coordinate of the right edge.
right: f32,

/// Coordinate of the top edge.
top: f32,

/// Coordinate of the bottom edge.
bottom: f32,
},
}

impl Version for Rect {
fn version(&self) -> u8 {
match self {
Self::V1 { .. } => 1,
}
}
}
33 changes: 1 addition & 32 deletions lvd_lib/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Basic vector types.
//!
//! This module contains the [`Vector2`] and [`Vector3`] types as well as the [`Rect`] type.
//! This module contains the [`Vector2`] and [`Vector3`] types.
use binrw::binrw;

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -60,34 +60,3 @@ impl Version for Vector3 {
}
}
}

/// A two-dimensional rectangle type.
#[binrw]
#[br(import(version: u8))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Rect {
/// `Rect` version 1.
#[br(pre_assert(version == 1))]
V1 {
/// Coordinate of the left edge.
left: f32,

/// Coordinate of the right edge.
right: f32,

/// Coordinate of the top edge.
top: f32,

/// Coordinate of the bottom edge.
bottom: f32,
},
}

impl Version for Rect {
fn version(&self) -> u8 {
match self {
Self::V1 { .. } => 1,
}
}
}

0 comments on commit e4b8474

Please sign in to comment.