1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Expand plot axes thickness to fit their labels (#3921)

Expand the plot axis thickness as the contained plot axis labels get
wider.

This fixes a problem where the plot labels would otherwise get clipped.


![plot-axis-expansion](https://github.com/emilk/egui/assets/1148717/4500a26e-4a11-401d-9e8e-2d98d02ef3b7)
This commit is contained in:
Emil Ernerfeldt
2024-01-30 12:45:27 +01:00
committed by GitHub
parent 01597fe1a1
commit 527f4bfdf6
5 changed files with 332 additions and 268 deletions

View File

@@ -28,6 +28,7 @@ pub struct Rot2 {
/// Identity rotation
impl Default for Rot2 {
/// Identity rotation
#[inline]
fn default() -> Self {
Self { s: 0.0, c: 1.0 }
}
@@ -39,29 +40,35 @@ impl Rot2 {
/// Angle is clockwise in radians.
/// A 𝞃/4 = 90° rotation means rotating the X axis to the Y axis.
#[inline]
pub fn from_angle(angle: f32) -> Self {
let (s, c) = angle.sin_cos();
Self { s, c }
}
#[inline]
pub fn angle(self) -> f32 {
self.s.atan2(self.c)
}
/// The factor by which vectors will be scaled.
#[inline]
pub fn length(self) -> f32 {
self.c.hypot(self.s)
}
#[inline]
pub fn length_squared(self) -> f32 {
self.c.powi(2) + self.s.powi(2)
}
#[inline]
pub fn is_finite(self) -> bool {
self.c.is_finite() && self.s.is_finite()
}
#[must_use]
#[inline]
pub fn inverse(self) -> Self {
Self {
s: -self.s,
@@ -70,6 +77,7 @@ impl Rot2 {
}
#[must_use]
#[inline]
pub fn normalized(self) -> Self {
let l = self.length();
let ret = Self {
@@ -95,6 +103,7 @@ impl std::fmt::Debug for Rot2 {
impl std::ops::Mul<Self> for Rot2 {
type Output = Self;
#[inline]
fn mul(self, r: Self) -> Self {
/*
|lc -ls| * |rc -rs|
@@ -111,6 +120,7 @@ impl std::ops::Mul<Self> for Rot2 {
impl std::ops::Mul<Vec2> for Rot2 {
type Output = Vec2;
#[inline]
fn mul(self, v: Vec2) -> Vec2 {
Vec2 {
x: self.c * v.x - self.s * v.y,
@@ -123,6 +133,7 @@ impl std::ops::Mul<Vec2> for Rot2 {
impl std::ops::Mul<Rot2> for f32 {
type Output = Rot2;
#[inline]
fn mul(self, r: Rot2) -> Rot2 {
Rot2 {
c: self * r.c,
@@ -135,6 +146,7 @@ impl std::ops::Mul<Rot2> for f32 {
impl std::ops::Mul<f32> for Rot2 {
type Output = Self;
#[inline]
fn mul(self, r: f32) -> Self {
Self {
c: self.c * r,
@@ -147,6 +159,7 @@ impl std::ops::Mul<f32> for Rot2 {
impl std::ops::Div<f32> for Rot2 {
type Output = Self;
#[inline]
fn div(self, r: f32) -> Self {
Self {
c: self.c / r,