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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::Point;
use crate::Quad;
use crate::Rect;
use glib::translate::*;
use std::fmt;

impl Quad {
    #[doc(alias = "graphene_quad_init")]
    pub fn new(p1: &Point, p2: &Point, p3: &Point, p4: &Point) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            let mut quad = Self::uninitialized();
            ffi::graphene_quad_init(
                quad.to_glib_none_mut().0,
                p1.to_glib_none().0,
                p2.to_glib_none().0,
                p3.to_glib_none().0,
                p4.to_glib_none().0,
            );
            quad
        }
    }

    #[doc(alias = "graphene_quad_init_from_rect")]
    #[doc(alias = "init_from_rect")]
    pub fn from_rect(r: &Rect) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            let mut quad = Self::uninitialized();
            ffi::graphene_quad_init_from_rect(quad.to_glib_none_mut().0, r.to_glib_none().0);
            quad
        }
    }

    #[doc(alias = "graphene_quad_init_from_points")]
    #[doc(alias = "init_from_points")]
    pub fn from_points(points: &[Point; 4]) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            let points = [
                *points[0].to_glib_none().0,
                *points[1].to_glib_none().0,
                *points[2].to_glib_none().0,
                *points[3].to_glib_none().0,
            ];
            let mut quad = Self::uninitialized();
            ffi::graphene_quad_init_from_points(
                quad.to_glib_none_mut().0,
                points.as_ptr() as *const _,
            );
            quad
        }
    }

    #[doc(alias = "graphene_quad_get_point")]
    #[doc(alias = "get_point")]
    pub fn point(&self, index_: u32) -> Point {
        assert!(index_ < 4);
        unsafe { from_glib_none(ffi::graphene_quad_get_point(self.to_glib_none().0, index_)) }
    }

    pub fn points(&self) -> &[Point; 4] {
        unsafe { &*(&self.inner.points as *const [ffi::graphene_point_t; 4] as *const [Point; 4]) }
    }
}

impl fmt::Debug for Quad {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Quad")
            .field("points", &self.points())
            .finish()
    }
}