1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::graphics::point::Point;
use crate::graphics::rectangle::Rectangle;
/// A textured quad.
#[derive(Debug, PartialEq, Clone)]
pub struct Quad {
/// The region of the resource that should be shown on the quad, in relative
/// coordinates: [0.0, 1.0].
pub source: Rectangle<f32>,
/// The position where the quad should be drawn.
pub position: Point,
/// The size of the quad.
pub size: (f32, f32),
}
impl Default for Quad {
fn default() -> Self {
Self {
source: Rectangle {
x: 0.0,
y: 0.0,
width: 1.0,
height: 1.0,
},
position: Point::new(0.0, 0.0),
size: (1.0, 1.0),
}
}
}
/// Turn a type into a quad.
///
/// Most methods accept generic types that can be turned into quads. This allows
/// you to use your own quad-based type.
pub trait IntoQuad {
/// Turns the implementor into a quad.
///
/// `x_unit` and `y_unit` are conversion factors for the [`source`] field.
/// Use them to convert absolute resource coordinates into relative
/// coordinates.
///
/// [`source`]: struct.Quad.html#structfield.source
fn into_quad(self, x_unit: f32, y_unit: f32) -> Quad;
}
impl IntoQuad for Quad {
fn into_quad(self, _x_unit: f32, _y_unit: f32) -> Quad {
self
}
}