This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
/
point.rs
93 lines (79 loc) · 2.59 KB
/
point.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
// 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 Vec2;
use ffi;
use glib::translate::*;
use gobject_ffi;
use std::mem;
glib_wrapper! {
#[derive(Debug, PartialOrd, Ord, Hash)]
pub struct Point(Boxed<ffi::graphene_point_t>);
match fn {
copy => |ptr| gobject_ffi::g_boxed_copy(ffi::graphene_point_get_type(), ptr as *mut _) as *mut ffi::graphene_point_t,
free => |ptr| gobject_ffi::g_boxed_free(ffi::graphene_point_get_type(), ptr as *mut _),
get_type => || ffi::graphene_point_get_type(),
}
}
impl Point {
pub fn distance(&self, b: &Point) -> (f32, f32, f32) {
unsafe {
let mut d_x = mem::uninitialized();
let mut d_y = mem::uninitialized();
let ret = ffi::graphene_point_distance(self.to_glib_none().0, b.to_glib_none().0, &mut d_x, &mut d_y);
(ret, d_x, d_y)
}
}
fn equal(&self, b: &Point) -> bool {
unsafe {
from_glib(ffi::graphene_point_equal(self.to_glib_none().0, b.to_glib_none().0))
}
}
pub fn init(&mut self, x: f32, y: f32) {
unsafe {
ffi::graphene_point_init(self.to_glib_none_mut().0, x, y);
}
}
pub fn init_from_point(&mut self, src: &Point) {
unsafe {
ffi::graphene_point_init_from_point(self.to_glib_none_mut().0, src.to_glib_none().0);
}
}
pub fn init_from_vec2(&mut self, src: &Vec2) {
unsafe {
ffi::graphene_point_init_from_vec2(self.to_glib_none_mut().0, src.to_glib_none().0);
}
}
pub fn interpolate(&self, b: &Point, factor: f64) -> Point {
unsafe {
let mut res = Point::uninitialized();
ffi::graphene_point_interpolate(self.to_glib_none().0, b.to_glib_none().0, factor, res.to_glib_none_mut().0);
res
}
}
pub fn near(&self, b: &Point, epsilon: f32) -> bool {
unsafe {
from_glib(ffi::graphene_point_near(self.to_glib_none().0, b.to_glib_none().0, epsilon))
}
}
pub fn to_vec2(&self) -> Vec2 {
unsafe {
let mut v = Vec2::uninitialized();
ffi::graphene_point_to_vec2(self.to_glib_none().0, v.to_glib_none_mut().0);
v
}
}
pub fn zero() -> Point {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::graphene_point_zero())
}
}
}
impl PartialEq for Point {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.equal(other)
}
}
impl Eq for Point {}