-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathqlinef.rs
187 lines (148 loc) · 6.61 KB
/
qlinef.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
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Laurent Montel <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::QLine;
use crate::QPointF;
use cxx::{type_id, ExternType};
use std::fmt;
#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qlinef.h");
type QLineF = super::QLineF;
include!("cxx-qt-lib/qline.h");
type QLine = crate::QLine;
include!("cxx-qt-lib/qpointf.h");
type QPointF = crate::QPointF;
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;
/// Returns the angle of the line in degrees.
fn angle(self: &QLineF) -> f64;
/// Returns the angle (in degrees) from this line to the given line, taking the direction of the lines into account.
/// If the lines do not intersect within their range, it is the intersection point of the extended lines that serves as origin (see QLineF::UnboundedIntersection).
#[rust_name = "angle_to"]
fn angleTo(self: &QLineF, line: &QLineF) -> f64;
/// Returns the line's start point.
fn p1(self: &QLineF) -> QPointF;
/// Returns the line's end point.
fn p2(self: &QLineF) -> QPointF;
/// Returns the x-coordinate of the line's start point.
fn x1(self: &QLineF) -> f64;
/// Returns the x-coordinate of the line's end point.
fn x2(self: &QLineF) -> f64;
/// Returns the y-coordinate of the line's start point.
fn y1(self: &QLineF) -> f64;
/// Returns the y-coordinate of the line's end point.
fn y2(self: &QLineF) -> f64;
/// Returns the center point of this line. This is equivalent to (p1() + p2()) / 2, except it will never overflow.
fn center(self: &QLineF) -> QPointF;
/// Returns the horizontal component of the line's vector.
fn dx(self: &QLineF) -> f64;
/// Returns the vertical component of the line's vector.
fn dy(self: &QLineF) -> f64;
/// Returns true if the line does not have distinct start and end points; otherwise returns false.
#[rust_name = "is_null"]
fn isNull(self: &QLineF) -> bool;
/// Returns the length of the line.
fn length(self: &QLineF) -> f64;
/// Returns a line that is perpendicular to this line with the same starting point and length.
#[rust_name = "normal_vector"]
fn normalVector(self: &QLineF) -> QLineF;
/// Returns the point at the parameterized position specified by t. The function returns the line's start point if t = 0, and its end point if t = 1.
#[rust_name = "point_at"]
fn pointAt(self: &QLineF, t: f64) -> QPointF;
/// Sets the angle of the line to the given angle (in degrees). This will change the position of the second point of the line such that the line has the given angle.
#[rust_name = "set_angle"]
fn setAngle(self: &mut QLineF, angle: f64);
/// Sets the length of the line to the given length. QLineF will move the end point - p2() - of the line to give the line its new length, unless length() was previously zero, i
/// in which case no scaling is attempted. For lines with very short lengths (represented by denormal floating-point values), results may be imprecise.
#[rust_name = "set_length"]
fn setLength(self: &mut QLineF, length: f64);
/// Sets the starting point of this line to p1.
#[rust_name = "set_p1"]
fn setP1(self: &mut QLineF, p1: &QPointF);
/// Sets the end point of this line to p2.
#[rust_name = "set_p2"]
fn setP2(self: &mut QLineF, p1: &QPointF);
/// Sets this line to the start in x1, y1 and end in x2, y2.
#[rust_name = "set_line"]
fn setLine(self: &mut QLineF, x1: f64, y1: f64, x2: f64, y2: f64);
/// Sets the start point of this line to p1 and the end point of this line to p2.
#[rust_name = "set_points"]
fn setPoints(self: &mut QLineF, p1: &QPointF, p2: &QPointF);
/// Returns an integer based copy of this line.
#[rust_name = "to_line"]
fn toLine(self: &QLineF) -> QLine;
/// Translates this line by the given offset.
fn translate(self: &mut QLineF, offset: &QPointF);
/// Returns this line translated by the given offset.
fn translated(self: &QLineF, offset: &QPointF) -> QLineF;
/// Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0, provided the line is non-null.
#[rust_name = "unit_vector"]
fn unitVector(self: &QLineF) -> QLineF;
}
#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");
#[doc(hidden)]
#[rust_name = "qlinef_default"]
fn construct() -> QLineF;
#[doc(hidden)]
#[rust_name = "qlinef_new"]
fn construct(pt1: QPointF, pt2: QPointF) -> QLineF;
#[doc(hidden)]
#[rust_name = "qlinef_from_qline"]
fn construct(line: &QLine) -> QLineF;
#[doc(hidden)]
#[rust_name = "qlinef_to_debug_qstring"]
fn toDebugQString(value: &QLineF) -> QString;
}
}
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// The QLineF class provides a two-dimensional vector using floating point precision.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct QLineF {
pt1: QPointF,
pt2: QPointF,
}
impl QLineF {
/// Constructs a line object that represents the line between pt1 and pt2.
pub fn new(pt1: QPointF, pt2: QPointF) -> Self {
ffi::qlinef_new(pt1, pt2)
}
}
impl Default for QLineF {
/// Constructs a default qlinef
fn default() -> Self {
ffi::qlinef_default()
}
}
impl From<&ffi::QLine> for QLineF {
/// Construct a QLineF object from the given integer-based line.
fn from(line: &QLine) -> Self {
ffi::qlinef_from_qline(line)
}
}
impl From<QLineF> for ffi::QLine {
/// Returns an integer-based copy of this line.
/// Note that the returned line's start and end points are rounded to the nearest integer.
fn from(value: QLineF) -> Self {
value.to_line()
}
}
impl fmt::Display for QLineF {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ffi::qlinef_to_debug_qstring(self))
}
}
// Safety:
//
// Static checks on the C++ side ensure that QLineF is trivial.
unsafe impl ExternType for QLineF {
type Id = type_id!("QLineF");
type Kind = cxx::kind::Trivial;
}