From e34097ba859010803156cdab692b6e9f6102bd99 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 11 Sep 2024 22:46:50 +0700 Subject: [PATCH] `Line::from` for `(Point, Point)`, `(Point, Vec2)` (#376) --- CHANGELOG.md | 2 ++ src/line.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 900a16d3..576d8af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This release has an [MSRV][] of 1.65. - Add `CircleSegment::inner_arc` and `CircleSegment::outer_arc` ([#368] by [@waywardmonkeys]) - Add `Rect::is_zero_area` and `Size::is_zero_area` and deprecate their `is_empty` methods. ([#370] by [@waywardmonkeys]) - Add `Line::reversed` and `Line::midpoint`. ([#375] by [@waywardmonkeys]) +- Allow construction of `Line` from `(Point, Point)` and `(Point, Vec2)`. ([#376] by [@waywardmonkeys]) ### Changed @@ -69,6 +70,7 @@ Note: A changelog was not kept for or before this release [#368]: https://github.com/linebender/kurbo/pull/368 [#370]: https://github.com/linebender/kurbo/pull/370 [#375]: https://github.com/linebender/kurbo/pull/375 +[#376]: https://github.com/linebender/kurbo/pull/376 [Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.0...HEAD [0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0 diff --git a/src/line.rs b/src/line.rs index b7a8c586..fcde1c99 100644 --- a/src/line.rs +++ b/src/line.rs @@ -90,6 +90,18 @@ impl Line { } } +impl From<(Point, Point)> for Line { + fn from((from, to): (Point, Point)) -> Self { + Line::new(from, to) + } +} + +impl From<(Point, Vec2)> for Line { + fn from((origin, displacement): (Point, Vec2)) -> Self { + Line::new(origin, origin + displacement) + } +} + impl ParamCurve for Line { #[inline] fn eval(&self, t: f64) -> Point {