srs2dge_core/texture/
pos.rs1use crate::prelude::{PositionedRect, Rect};
2use glam::Vec2;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
8pub struct TexturePosition {
9 pub top_left: Vec2,
10 pub bottom_right: Vec2,
11}
12
13impl TexturePosition {
16 pub fn new(area: Rect, pos: PositionedRect) -> Self {
17 let (w, h) = (area.width as f32, area.height as f32);
18 let top_left = Vec2::new(pos.x as f32 / w, pos.y as f32 / h);
19 let bottom_right = Vec2::new(pos.width as f32 / w, pos.height as f32 / h) + top_left;
20
21 Self {
22 top_left,
23 bottom_right,
24 }
25 }
26}
27
28impl Default for TexturePosition {
29 fn default() -> Self {
30 Self {
31 top_left: Vec2::new(0.0, 0.0),
32 bottom_right: Vec2::new(1.0, 1.0),
33 }
34 }
35}