graphene/
point.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Point, Vec2};
8
9impl Point {
10    #[doc(alias = "graphene_point_init")]
11    pub fn new(x: f32, y: f32) -> Self {
12        assert_initialized_main_thread!();
13        unsafe {
14            let mut p = Self::uninitialized();
15            ffi::graphene_point_init(p.to_glib_none_mut().0, x, y);
16            p
17        }
18    }
19
20    #[doc(alias = "graphene_point_init_from_vec2")]
21    #[doc(alias = "init_from_vec2")]
22    pub fn from_vec2(src: &Vec2) -> Point {
23        assert_initialized_main_thread!();
24        unsafe {
25            let mut p = Self::uninitialized();
26            ffi::graphene_point_init_from_vec2(p.to_glib_none_mut().0, src.to_glib_none().0);
27            p
28        }
29    }
30
31    #[inline]
32    pub fn x(&self) -> f32 {
33        self.inner.x
34    }
35
36    #[inline]
37    pub fn set_x(&mut self, x: f32) {
38        self.inner.x = x;
39    }
40
41    #[inline]
42    pub fn y(&self) -> f32 {
43        self.inner.y
44    }
45
46    #[inline]
47    pub fn set_y(&mut self, y: f32) {
48        self.inner.y = y;
49    }
50}
51
52impl fmt::Debug for Point {
53    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54        f.debug_struct("Point")
55            .field("x", &self.x())
56            .field("y", &self.y())
57            .finish()
58    }
59}
60
61impl Default for Point {
62    fn default() -> Self {
63        Self::zero()
64    }
65}