Skip to content

Commit acb4339

Browse files
authored
Add missing QLineF methods (#757)
* Add missing QLineF methods * Add impl From<QLineF> for ffi::QLine
1 parent 9144632 commit acb4339

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

crates/cxx-qt-lib/src/core/qlinef.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ mod ffi {
1717
include!("cxx-qt-lib/qpointf.h");
1818
type QPointF = crate::QPointF;
1919

20+
/// Returns the angle of the line in degrees.
21+
fn angle(self: &QLineF) -> f64;
22+
23+
/// Returns the angle (in degrees) from this line to the given line, taking the direction of the lines into account.
24+
/// 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).
25+
#[rust_name = "angle_to"]
26+
fn angleTo(self: &QLineF, line: &QLineF) -> f64;
27+
2028
/// Returns the line's start point.
2129
fn p1(self: &QLineF) -> QPointF;
2230

@@ -48,6 +56,26 @@ mod ffi {
4856
#[rust_name = "is_null"]
4957
fn isNull(self: &QLineF) -> bool;
5058

59+
/// Returns the length of the line.
60+
fn length(self: &QLineF) -> f64;
61+
62+
/// Returns a line that is perpendicular to this line with the same starting point and length.
63+
#[rust_name = "normal_vector"]
64+
fn normalVector(self: &QLineF) -> QLineF;
65+
66+
/// 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.
67+
#[rust_name = "point_at"]
68+
fn pointAt(self: &QLineF, t: f64) -> QPointF;
69+
70+
/// 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.
71+
#[rust_name = "set_angle"]
72+
fn setAngle(self: &mut QLineF, angle: f64);
73+
74+
/// 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
75+
/// in which case no scaling is attempted. For lines with very short lengths (represented by denormal floating-point values), results may be imprecise.
76+
#[rust_name = "set_length"]
77+
fn setLength(self: &mut QLineF, length: f64);
78+
5179
/// Sets the starting point of this line to p1.
5280
#[rust_name = "set_p1"]
5381
fn setP1(self: &mut QLineF, p1: &QPointF);
@@ -64,11 +92,19 @@ mod ffi {
6492
#[rust_name = "set_points"]
6593
fn setPoints(self: &mut QLineF, p1: &QPointF, p2: &QPointF);
6694

95+
/// Returns an integer based copy of this line.
96+
#[rust_name = "to_line"]
97+
fn toLine(self: &QLineF) -> QLine;
98+
6799
/// Translates this line by the given offset.
68100
fn translate(self: &mut QLineF, offset: &QPointF);
69101

70102
/// Returns this line translated by the given offset.
71103
fn translated(self: &QLineF, offset: &QPointF) -> QLineF;
104+
105+
/// 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.
106+
#[rust_name = "unit_vector"]
107+
fn unitVector(self: &QLineF) -> QLineF;
72108
}
73109

74110
#[namespace = "rust::cxxqtlib1"]
@@ -117,6 +153,14 @@ impl From<&ffi::QLine> for QLineF {
117153
}
118154
}
119155

156+
impl From<QLineF> for ffi::QLine {
157+
/// Returns an integer-based copy of this line.
158+
/// Note that the returned line's start and end points are rounded to the nearest integer.
159+
fn from(value: QLineF) -> Self {
160+
value.to_line()
161+
}
162+
}
163+
120164
// Safety:
121165
//
122166
// Static checks on the C++ side ensure that QLineF is trivial.

0 commit comments

Comments
 (0)