mirror of
https://github.com/typst/typst
synced 2025-05-22 04:55:29 +08:00
Give up on not implementing Eq and Ord
This commit is contained in:
parent
fec1f41106
commit
4c37ebb936
@ -2,7 +2,7 @@ use super::*;
|
|||||||
use decorum::N64;
|
use decorum::N64;
|
||||||
|
|
||||||
/// An angle.
|
/// An angle.
|
||||||
#[derive(Default, Copy, Clone, PartialEq, PartialOrd, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub struct Angle {
|
pub struct Angle {
|
||||||
/// The angle in raw units.
|
/// The angle in raw units.
|
||||||
raw: N64,
|
raw: N64,
|
||||||
|
@ -3,7 +3,7 @@ use decorum::N64;
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A fractional length.
|
/// A fractional length.
|
||||||
#[derive(Default, Copy, Clone, PartialEq, PartialOrd, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub struct Fractional(N64);
|
pub struct Fractional(N64);
|
||||||
|
|
||||||
impl Fractional {
|
impl Fractional {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A combined relative and absolute length.
|
/// A combined relative and absolute length.
|
||||||
#[derive(Default, Copy, Clone, PartialEq, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct Linear {
|
pub struct Linear {
|
||||||
/// The relative part.
|
/// The relative part.
|
||||||
pub rel: Relative,
|
pub rel: Relative,
|
||||||
|
@ -3,12 +3,12 @@ use super::*;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A bezier path.
|
/// A bezier path.
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct Path(pub Vec<PathElement>);
|
pub struct Path(pub Vec<PathElement>);
|
||||||
|
|
||||||
/// An element in a bezier path.
|
/// An element in a bezier path.
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum PathElement {
|
pub enum PathElement {
|
||||||
MoveTo(Point),
|
MoveTo(Point),
|
||||||
LineTo(Point),
|
LineTo(Point),
|
||||||
|
@ -3,7 +3,7 @@ use super::*;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A point in 2D.
|
/// A point in 2D.
|
||||||
#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
/// The x coordinate.
|
/// The x coordinate.
|
||||||
pub x: Length,
|
pub x: Length,
|
||||||
|
@ -6,7 +6,7 @@ use super::*;
|
|||||||
///
|
///
|
||||||
/// _Note_: `50%` is represented as `0.5` here, but stored as `50.0` in the
|
/// _Note_: `50%` is represented as `0.5` here, but stored as `50.0` in the
|
||||||
/// corresponding [literal](crate::syntax::Expr::Percent).
|
/// corresponding [literal](crate::syntax::Expr::Percent).
|
||||||
#[derive(Default, Copy, Clone, PartialEq, PartialOrd, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub struct Relative(N64);
|
pub struct Relative(N64);
|
||||||
|
|
||||||
impl Relative {
|
impl Relative {
|
||||||
|
@ -3,7 +3,7 @@ use super::*;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A size in 2D.
|
/// A size in 2D.
|
||||||
#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize, Hash)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
pub struct Size {
|
pub struct Size {
|
||||||
/// The width.
|
/// The width.
|
||||||
pub width: Length,
|
pub width: Length,
|
||||||
|
@ -39,6 +39,7 @@ impl From<StackNode> for AnyNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct StackLayouter<'a> {
|
struct StackLayouter<'a> {
|
||||||
/// The directions of the stack.
|
/// The directions of the stack.
|
||||||
stack: &'a StackNode,
|
stack: &'a StackNode,
|
||||||
|
@ -350,12 +350,7 @@ fn draw(cache: &Cache, frames: &[Frame], dpi: f32) -> Pixmap {
|
|||||||
let pad = Length::pt(5.0);
|
let pad = Length::pt(5.0);
|
||||||
|
|
||||||
let height = pad + frames.iter().map(|l| l.size.height + pad).sum::<Length>();
|
let height = pad + frames.iter().map(|l| l.size.height + pad).sum::<Length>();
|
||||||
let width = 2.0 * pad
|
let width = 2.0 * pad + frames.iter().map(|l| l.size.width).max().unwrap_or_default();
|
||||||
+ frames
|
|
||||||
.iter()
|
|
||||||
.map(|l| l.size.width)
|
|
||||||
.max_by(|a, b| a.partial_cmp(&b).unwrap())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let pixel_width = (dpi * width.to_pt() as f32) as u32;
|
let pixel_width = (dpi * width.to_pt() as f32) as u32;
|
||||||
let pixel_height = (dpi * height.to_pt() as f32) as u32;
|
let pixel_height = (dpi * height.to_pt() as f32) as u32;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user