cxx_qt_lib/core/
qpointf.rs1use cxx::{type_id, ExternType};
8use std::fmt;
9
10#[cxx::bridge]
11mod ffi {
12 unsafe extern "C++" {
13 include!("cxx-qt-lib/qpoint.h");
14 type QPoint = crate::QPoint;
15 include!("cxx-qt-lib/qpointf.h");
16 type QPointF = super::QPointF;
17 include!("cxx-qt-lib/qstring.h");
18 type QString = crate::QString;
19
20 #[rust_name = "is_null"]
22 fn isNull(self: &QPointF) -> bool;
23
24 #[rust_name = "manhattan_length"]
27 fn manhattanLength(self: &QPointF) -> f64;
28
29 #[rust_name = "set_x"]
31 fn setX(self: &mut QPointF, x: f64);
32
33 #[rust_name = "set_y"]
35 fn setY(self: &mut QPointF, y: f64);
36
37 #[rust_name = "to_point"]
40 fn toPoint(self: &QPointF) -> QPoint;
41
42 fn transposed(self: &QPointF) -> QPointF;
44
45 fn x(self: &QPointF) -> f64;
47
48 fn y(self: &QPointF) -> f64;
50 }
51
52 #[namespace = "rust::cxxqtlib1"]
53 unsafe extern "C++" {
54 #[doc(hidden)]
55 #[rust_name = "qpointf_dot_product"]
56 fn qpointfDotProduct(p1: &QPointF, p2: &QPointF) -> f64;
57 }
58
59 #[namespace = "rust::cxxqtlib1"]
60 unsafe extern "C++" {
61 include!("cxx-qt-lib/common.h");
62
63 #[doc(hidden)]
64 #[rust_name = "qpointf_init_default"]
65 fn construct() -> QPointF;
66 #[doc(hidden)]
67 #[rust_name = "qpointf_init"]
68 fn construct(x: f64, y: f64) -> QPointF;
69 #[doc(hidden)]
70 #[rust_name = "qpointf_from_qpoint"]
71 fn construct(point: &QPoint) -> QPointF;
72 #[doc(hidden)]
73 #[rust_name = "qpointf_to_qstring"]
74 fn toQString(value: &QPointF) -> QString;
75 #[doc(hidden)]
76 #[rust_name = "qpointf_plus"]
77 fn operatorPlus(a: &QPointF, b: &QPointF) -> QPointF;
78 #[doc(hidden)]
79 #[rust_name = "qpointf_minus"]
80 fn operatorMinus(a: &QPointF, b: &QPointF) -> QPointF;
81 #[doc(hidden)]
82 #[rust_name = "qpointf_mul"]
83 fn operatorMul(a: f64, b: &QPointF) -> QPointF;
84 #[doc(hidden)]
85 #[rust_name = "qpointf_div"]
86 fn operatorDiv(a: f64, b: &QPointF) -> QPointF;
87 }
88}
89
90#[derive(Debug, Clone, PartialEq)]
92#[repr(C)]
93pub struct QPointF {
94 x: f64,
95 y: f64,
96}
97
98impl QPointF {
99 pub fn dot_product(p1: &QPointF, p2: &QPointF) -> f64 {
101 ffi::qpointf_dot_product(p1, p2)
102 }
103
104 pub fn new(x: f64, y: f64) -> Self {
106 ffi::qpointf_init(x, y)
107 }
108}
109
110impl Default for QPointF {
111 fn default() -> Self {
113 ffi::qpointf_init_default()
114 }
115}
116
117impl fmt::Display for QPointF {
118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119 write!(f, "{}", ffi::qpointf_to_qstring(self))
120 }
121}
122
123impl From<&ffi::QPoint> for QPointF {
124 fn from(point: &ffi::QPoint) -> Self {
126 ffi::qpointf_from_qpoint(point)
127 }
128}
129
130impl From<QPointF> for ffi::QPoint {
131 fn from(value: QPointF) -> Self {
134 value.to_point()
135 }
136}
137
138impl std::ops::Add for QPointF {
139 type Output = Self;
140 fn add(self, other: Self) -> Self {
141 ffi::qpointf_plus(&self, &other)
142 }
143}
144
145impl std::ops::Sub for QPointF {
146 type Output = Self;
147 fn sub(self, other: Self) -> Self {
148 ffi::qpointf_minus(&self, &other)
149 }
150}
151
152impl std::ops::Mul<f64> for QPointF {
153 type Output = Self;
154 fn mul(self, rhs: f64) -> Self {
155 ffi::qpointf_mul(rhs, &self)
156 }
157}
158
159impl std::ops::Div<f64> for QPointF {
160 type Output = Self;
161 fn div(self, rhs: f64) -> Self {
162 ffi::qpointf_div(rhs, &self)
163 }
164}
165
166unsafe impl ExternType for QPointF {
170 type Id = type_id!("QPointF");
171 type Kind = cxx::kind::Trivial;
172}