graphene/auto/triangle.rs
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
// 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::{ffi, Box, Plane, Point3D, Vec2, Vec3};
use glib::translate::*;
glib::wrapper! {
/// A triangle.
pub struct Triangle(BoxedInline<ffi::graphene_triangle_t>);
match fn {
copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_triangle_get_type(), ptr as *mut _) as *mut ffi::graphene_triangle_t,
free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_triangle_get_type(), ptr as *mut _),
type_ => || ffi::graphene_triangle_get_type(),
}
}
impl Triangle {
/// Checks whether the given triangle `self` contains the point `p`.
/// ## `p`
/// a [`Point3D`][crate::Point3D]
///
/// # Returns
///
/// `true` if the point is inside the triangle
#[doc(alias = "graphene_triangle_contains_point")]
pub fn contains_point(&self, p: &Point3D) -> bool {
unsafe { ffi::graphene_triangle_contains_point(self.to_glib_none().0, p.to_glib_none().0) }
}
#[doc(alias = "graphene_triangle_equal")]
fn equal(&self, b: &Triangle) -> bool {
unsafe { ffi::graphene_triangle_equal(self.to_glib_none().0, b.to_glib_none().0) }
}
/// Computes the area of the given [`Triangle`][crate::Triangle].
///
/// # Returns
///
/// the area of the triangle
#[doc(alias = "graphene_triangle_get_area")]
#[doc(alias = "get_area")]
pub fn area(&self) -> f32 {
unsafe { ffi::graphene_triangle_get_area(self.to_glib_none().0) }
}
/// Computes the [barycentric coordinates](http://en.wikipedia.org/wiki/Barycentric_coordinate_system)
/// of the given point `p`.
///
/// The point `p` must lie on the same plane as the triangle `self`; if the
/// point is not coplanar, the result of this function is undefined.
///
/// If we place the origin in the coordinates of the triangle's A point,
/// the barycentric coordinates are `u`, which is on the AC vector; and `v`
/// which is on the AB vector:
///
/// ![](triangle-barycentric.png)
///
/// The returned [`Vec2`][crate::Vec2] contains the following values, in order:
///
/// - `res.x = u`
/// - `res.y = v`
/// ## `p`
/// a [`Point3D`][crate::Point3D]
///
/// # Returns
///
/// `true` if the barycentric coordinates are valid
///
/// ## `res`
/// return location for the vector
/// with the barycentric coordinates
#[doc(alias = "graphene_triangle_get_barycoords")]
#[doc(alias = "get_barycoords")]
pub fn barycoords(&self, p: Option<&Point3D>) -> Option<Vec2> {
unsafe {
let mut res = Vec2::uninitialized();
let ret = ffi::graphene_triangle_get_barycoords(
self.to_glib_none().0,
p.to_glib_none().0,
res.to_glib_none_mut().0,
);
if ret {
Some(res)
} else {
None
}
}
}
/// Computes the bounding box of the given [`Triangle`][crate::Triangle].
///
/// # Returns
///
///
/// ## `res`
/// return location for the box
#[doc(alias = "graphene_triangle_get_bounding_box")]
#[doc(alias = "get_bounding_box")]
pub fn bounding_box(&self) -> Box {
unsafe {
let mut res = Box::uninitialized();
ffi::graphene_triangle_get_bounding_box(
self.to_glib_none().0,
res.to_glib_none_mut().0,
);
res
}
}
/// Computes the coordinates of the midpoint of the given [`Triangle`][crate::Triangle].
///
/// The midpoint G is the [centroid](https://en.wikipedia.org/wiki/Centroid`Triangle_centroid`)
/// of the triangle, i.e. the intersection of its medians.
///
/// # Returns
///
///
/// ## `res`
/// return location for the coordinates of
/// the midpoint
#[doc(alias = "graphene_triangle_get_midpoint")]
#[doc(alias = "get_midpoint")]
pub fn midpoint(&self) -> Point3D {
unsafe {
let mut res = Point3D::uninitialized();
ffi::graphene_triangle_get_midpoint(self.to_glib_none().0, res.to_glib_none_mut().0);
res
}
}
/// Computes the normal vector of the given [`Triangle`][crate::Triangle].
///
/// # Returns
///
///
/// ## `res`
/// return location for the normal vector
#[doc(alias = "graphene_triangle_get_normal")]
#[doc(alias = "get_normal")]
pub fn normal(&self) -> Vec3 {
unsafe {
let mut res = Vec3::uninitialized();
ffi::graphene_triangle_get_normal(self.to_glib_none().0, res.to_glib_none_mut().0);
res
}
}
/// Computes the plane based on the vertices of the given [`Triangle`][crate::Triangle].
///
/// # Returns
///
///
/// ## `res`
/// return location for the plane
#[doc(alias = "graphene_triangle_get_plane")]
#[doc(alias = "get_plane")]
pub fn plane(&self) -> Plane {
unsafe {
let mut res = Plane::uninitialized();
ffi::graphene_triangle_get_plane(self.to_glib_none().0, res.to_glib_none_mut().0);
res
}
}
/// Retrieves the three vertices of the given [`Triangle`][crate::Triangle] and returns
/// their coordinates as [`Point3D`][crate::Point3D].
///
/// # Returns
///
///
/// ## `a`
/// return location for the coordinates
/// of the first vertex
///
/// ## `b`
/// return location for the coordinates
/// of the second vertex
///
/// ## `c`
/// return location for the coordinates
/// of the third vertex
#[doc(alias = "graphene_triangle_get_points")]
#[doc(alias = "get_points")]
pub fn points(&self) -> (Point3D, Point3D, Point3D) {
unsafe {
let mut a = Point3D::uninitialized();
let mut b = Point3D::uninitialized();
let mut c = Point3D::uninitialized();
ffi::graphene_triangle_get_points(
self.to_glib_none().0,
a.to_glib_none_mut().0,
b.to_glib_none_mut().0,
c.to_glib_none_mut().0,
);
(a, b, c)
}
}
/// Computes the UV coordinates of the given point `p`.
///
/// The point `p` must lie on the same plane as the triangle `self`; if the point
/// is not coplanar, the result of this function is undefined. If `p` is [`None`],
/// the point will be set in (0, 0, 0).
///
/// The UV coordinates will be placed in the `res` vector:
///
/// - `res.x = u`
/// - `res.y = v`
///
/// See also: [`barycoords()`][Self::barycoords()]
/// ## `p`
/// a [`Point3D`][crate::Point3D]
/// ## `uv_a`
/// the UV coordinates of the first point
/// ## `uv_b`
/// the UV coordinates of the second point
/// ## `uv_c`
/// the UV coordinates of the third point
///
/// # Returns
///
/// `true` if the coordinates are valid
///
/// ## `res`
/// a vector containing the UV coordinates
/// of the given point `p`
#[doc(alias = "graphene_triangle_get_uv")]
#[doc(alias = "get_uv")]
pub fn uv(&self, p: Option<&Point3D>, uv_a: &Vec2, uv_b: &Vec2, uv_c: &Vec2) -> Option<Vec2> {
unsafe {
let mut res = Vec2::uninitialized();
let ret = ffi::graphene_triangle_get_uv(
self.to_glib_none().0,
p.to_glib_none().0,
uv_a.to_glib_none().0,
uv_b.to_glib_none().0,
uv_c.to_glib_none().0,
res.to_glib_none_mut().0,
);
if ret {
Some(res)
} else {
None
}
}
}
/// Retrieves the three vertices of the given [`Triangle`][crate::Triangle].
///
/// # Returns
///
///
/// ## `a`
/// return location for the first vertex
///
/// ## `b`
/// return location for the second vertex
///
/// ## `c`
/// return location for the third vertex
#[doc(alias = "graphene_triangle_get_vertices")]
#[doc(alias = "get_vertices")]
pub fn vertices(&self) -> (Vec3, Vec3, Vec3) {
unsafe {
let mut a = Vec3::uninitialized();
let mut b = Vec3::uninitialized();
let mut c = Vec3::uninitialized();
ffi::graphene_triangle_get_vertices(
self.to_glib_none().0,
a.to_glib_none_mut().0,
b.to_glib_none_mut().0,
c.to_glib_none_mut().0,
);
(a, b, c)
}
}
}
impl PartialEq for Triangle {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.equal(other)
}
}
impl Eq for Triangle {}