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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Box;
use crate::Point3D;
use glib::translate::*;

glib::wrapper! {
    /// A sphere, represented by its center and radius.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Sphere(Boxed<ffi::graphene_sphere_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_sphere_get_type(), ptr as *mut _) as *mut ffi::graphene_sphere_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_sphere_get_type(), ptr as *mut _),
        init => |_ptr| (),
        clear => |_ptr| (),
        type_ => || ffi::graphene_sphere_get_type(),
    }
}

impl Sphere {
    /// Checks whether the given `point` is contained in the volume
    /// of a [`Sphere`][crate::Sphere].
    /// ## `point`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// `true` if the sphere contains the point
    #[doc(alias = "graphene_sphere_contains_point")]
    pub fn contains_point(&self, point: &Point3D) -> bool {
        unsafe {
            from_glib(ffi::graphene_sphere_contains_point(
                self.to_glib_none().0,
                point.to_glib_none().0,
            ))
        }
    }

    /// Computes the distance of the given `point` from the surface of
    /// a [`Sphere`][crate::Sphere].
    /// ## `point`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the distance of the point
    #[doc(alias = "graphene_sphere_distance")]
    pub fn distance(&self, point: &Point3D) -> f32 {
        unsafe { ffi::graphene_sphere_distance(self.to_glib_none().0, point.to_glib_none().0) }
    }

    /// Checks whether two [`Sphere`][crate::Sphere] are equal.
    /// ## `b`
    /// a [`Sphere`][crate::Sphere]
    ///
    /// # Returns
    ///
    /// `true` if the spheres are equal
    #[doc(alias = "graphene_sphere_equal")]
    fn equal(&self, b: &Sphere) -> bool {
        unsafe {
            from_glib(ffi::graphene_sphere_equal(
                self.to_glib_none().0,
                b.to_glib_none().0,
            ))
        }
    }

    /// Computes the bounding box capable of containing the
    /// given [`Sphere`][crate::Sphere].
    ///
    /// # Returns
    ///
    ///
    /// ## `box_`
    /// return location for the bounding box
    #[doc(alias = "graphene_sphere_get_bounding_box")]
    #[doc(alias = "get_bounding_box")]
    pub fn bounding_box(&self) -> Box {
        unsafe {
            let mut box_ = Box::uninitialized();
            ffi::graphene_sphere_get_bounding_box(self.to_glib_none().0, box_.to_glib_none_mut().0);
            box_
        }
    }

    /// Retrieves the coordinates of the center of a [`Sphere`][crate::Sphere].
    ///
    /// # Returns
    ///
    ///
    /// ## `center`
    /// return location for the coordinates of
    ///  the center
    #[doc(alias = "graphene_sphere_get_center")]
    #[doc(alias = "get_center")]
    pub fn center(&self) -> Point3D {
        unsafe {
            let mut center = Point3D::uninitialized();
            ffi::graphene_sphere_get_center(self.to_glib_none().0, center.to_glib_none_mut().0);
            center
        }
    }

    /// Retrieves the radius of a [`Sphere`][crate::Sphere].
    #[doc(alias = "graphene_sphere_get_radius")]
    #[doc(alias = "get_radius")]
    pub fn radius(&self) -> f32 {
        unsafe { ffi::graphene_sphere_get_radius(self.to_glib_none().0) }
    }

    /// Initializes the given [`Sphere`][crate::Sphere] with the given `center` and `radius`.
    /// ## `center`
    /// the coordinates of the center of the sphere, or [`None`]
    ///  for a center in (0, 0, 0)
    /// ## `radius`
    /// the radius of the sphere
    ///
    /// # Returns
    ///
    /// the initialized [`Sphere`][crate::Sphere]
    #[doc(alias = "graphene_sphere_init")]
    pub fn init(&mut self, center: Option<&Point3D>, radius: f32) {
        unsafe {
            ffi::graphene_sphere_init(self.to_glib_none_mut().0, center.to_glib_none().0, radius);
        }
    }

    /// Checks whether the sphere has a zero radius.
    ///
    /// # Returns
    ///
    /// `true` if the sphere is empty
    #[doc(alias = "graphene_sphere_is_empty")]
    pub fn is_empty(&self) -> bool {
        unsafe { from_glib(ffi::graphene_sphere_is_empty(self.to_glib_none().0)) }
    }

    /// Translates the center of the given [`Sphere`][crate::Sphere] using the `point`
    /// coordinates as the delta of the translation.
    /// ## `point`
    /// the coordinates of the translation
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the translated sphere
    #[doc(alias = "graphene_sphere_translate")]
    pub fn translate(&self, point: &Point3D) -> Sphere {
        unsafe {
            let mut res = Sphere::uninitialized();
            ffi::graphene_sphere_translate(
                self.to_glib_none().0,
                point.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }
}

impl PartialEq for Sphere {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Sphere {}