Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow independent corner radii for RoundedRect #166

Merged
merged 6 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A circle arc.
//! An ellipse arc.

use crate::{PathEl, Point, Rect, Shape, Vec2};
use std::{
Expand Down Expand Up @@ -30,7 +30,7 @@ impl Arc {
pub fn append_iter(&self, tolerance: f64) -> ArcAppendIter {
let sign = self.sweep_angle.signum();
let scaled_err = self.radii.x.max(self.radii.y) / tolerance;
// Number of subdivisions per circle based on error tolerance.
// Number of subdivisions per ellipse based on error tolerance.
// Note: this may slightly underestimate the error for quadrants.
let n_err = (1.1163 * scaled_err).powf(1.0 / 6.0).max(3.999_999);
let n = (n_err * self.sweep_angle.abs() * (1.0 / (2.0 * PI))).ceil();
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod point;
mod quadbez;
mod rect;
mod rounded_rect;
mod rounded_rect_radii;
mod shape;
mod size;
mod svg;
Expand All @@ -111,6 +112,7 @@ pub use crate::point::*;
pub use crate::quadbez::*;
pub use crate::rect::*;
pub use crate::rounded_rect::*;
pub use crate::rounded_rect_radii::*;
pub use crate::shape::*;
pub use crate::size::*;
pub use crate::svg::*;
Expand Down
6 changes: 3 additions & 3 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt;
use std::ops::{Add, Sub};

use crate::{Ellipse, Insets, PathEl, Point, RoundedRect, Shape, Size, Vec2};
use crate::{Ellipse, Insets, PathEl, Point, RoundedRect, RoundedRectRadii, Shape, Size, Vec2};

/// A rectangle.
#[derive(Clone, Copy, Default, PartialEq)]
Expand Down Expand Up @@ -442,8 +442,8 @@ impl Rect {
/// Creates a new [`RoundedRect`] from this `Rect` and the provided
/// corner radius.
#[inline]
pub fn to_rounded_rect(self, radius: f64) -> RoundedRect {
RoundedRect::from_rect(self, radius)
pub fn to_rounded_rect(self, radii: RoundedRectRadii) -> RoundedRect {
RoundedRect::from_rect(self, radii)
}

/// Returns the [`Ellipse`] that is bounded by this `Rect`.
Expand Down
Loading