Skip to content

Commit

Permalink
Add Arc::cast and QuadraticBezierSegment::cast
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 authored and nical committed Jul 15, 2024
1 parent 8d6bb2d commit 3ac2829
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/geom/src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use core::mem::swap;
use core::ops::Range;

use num_traits::NumCast;

use crate::scalar::{cast, Float, Scalar};
use crate::segment::{BoundingBox, Segment};
use crate::{point, vector, Angle, Box2D, Point, Rotation, Transform, Vector};
Expand Down Expand Up @@ -31,6 +33,16 @@ pub struct SvgArc<S> {
}

impl<S: Scalar> Arc<S> {
pub fn cast<NewS: NumCast>(self) -> Arc<NewS> {
Arc {
center: self.center.cast(),
radii: self.radii.cast(),
start_angle: self.start_angle.cast(),
sweep_angle: self.sweep_angle.cast(),
x_rotation: self.x_rotation.cast(),
}
}

/// Create simple circle.
pub fn circle(center: Point<S>, radius: S) -> Self {
Arc {
Expand Down
9 changes: 9 additions & 0 deletions crates/geom/src/quadratic_bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::traits::Transformation;
use crate::{point, Box2D, Point, Vector};
use crate::{CubicBezierSegment, Line, LineEquation, LineSegment, Triangle};
use arrayvec::ArrayVec;
use num_traits::NumCast;

use core::mem;
use core::ops::Range;
Expand All @@ -22,6 +23,14 @@ pub struct QuadraticBezierSegment<S> {
}

impl<S: Scalar> QuadraticBezierSegment<S> {
pub fn cast<NewS: NumCast>(self) -> QuadraticBezierSegment<NewS> {
QuadraticBezierSegment {
from: self.from.cast(),
ctrl: self.ctrl.cast(),
to: self.to.cast(),
}
}

/// Sample the curve at t (expecting t between 0 and 1).
pub fn sample(&self, t: S) -> Point<S> {
let t2 = t * t;
Expand Down

0 comments on commit 3ac2829

Please sign in to comment.