Skip to content

Commit

Permalink
expose more types when 'eval' feature is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrg committed Jun 25, 2021
1 parent 12b9b12 commit a1928c8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zeno"
version = "0.2.1"
version = "0.2.2"
authors = ["Chad Brokaw <[email protected]>"]
edition = "2018"
description = "High performance, low level 2D path rasterization."
Expand Down
63 changes: 63 additions & 0 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,69 @@ impl Transform {
}
}

/// The origin of the coordinate system for rendering.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Origin {
/// Origin (0, 0) at the top left of the image.
TopLeft,
/// Origin (0, 0) at the bottom left of the image.
BottomLeft,
}

impl Default for Origin {
fn default() -> Self {
Self::TopLeft
}
}

/// Describes the offset and dimensions of a rendered mask.
#[derive(Copy, Clone, Debug, Default)]
pub struct Placement {
/// Horizontal offset with respect to the origin specified when computing
/// the placement.
pub left: i32,
/// Vertical offset with respect to the origin specified when computing
/// the placement.
pub top: i32,
/// Width in pixels.
pub width: u32,
/// Height in pixels.
pub height: u32,
}

impl Placement {
/// Given an origin, offset and bounding box, computes the resulting offset
/// and placement for a tightly bounded mask.
pub fn compute(
origin: Origin,
offset: impl Into<Vector>,
bounds: &Bounds,
) -> (Vector, Placement) {
let offset = offset.into();
let mut bounds = *bounds;
bounds.min = (bounds.min + offset).floor();
bounds.max = (bounds.max + offset).ceil();
let offset = Vector::new(-bounds.min.x + 1., -bounds.min.y);
let width = bounds.width() as u32 + 2;
let height = bounds.height() as u32;
let left = -offset.x as i32;
let top = if origin == Origin::BottomLeft {
(-offset.y).floor() + height as f32
} else {
-offset.y
} as i32;
(
offset,
Placement {
left,
top,
width,
height,
},
)
}
}

/// Axis-aligned bounding box.
#[derive(Copy, Clone, Default, Debug)]
pub struct Bounds {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ mod svg_parser;
mod traversal;

pub use command::{Command, Verb};
pub use geometry::{Angle, Bounds, Point, Transform, Vector};
pub use geometry::{Angle, Bounds, Origin, Placement, Point, Transform, Vector};
#[cfg(feature = "eval")]
pub use hit_test::HitTest;
#[cfg(feature = "eval")]
pub use mask::{Format, Mask, Origin, Placement};
pub use mask::{Format, Mask};
pub use path_builder::{ArcSize, ArcSweep, PathBuilder};
pub use path_data::{length, PathData};
#[cfg(feature = "eval")]
Expand Down
67 changes: 2 additions & 65 deletions src/mask.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Mask generator.

use super::geometry::{Bounds, Transform, Vector};
use super::geometry::{Origin, Placement, Transform, Vector};
use super::path_data::{apply, PathData};
use super::scratch::Scratch;
use super::style::{Fill, Style};

use core::cell::RefCell;
use crate::lib::Vec;
use core::cell::RefCell;

/// The desired output image format for rendering.
#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -44,69 +44,6 @@ impl Default for Format {
}
}

/// The origin of the coordinate system for rendering.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Origin {
/// Origin (0, 0) at the top left of the image.
TopLeft,
/// Origin (0, 0) at the bottom left of the image.
BottomLeft,
}

impl Default for Origin {
fn default() -> Self {
Self::TopLeft
}
}

/// Describes the offset and dimensions of a rendered mask.
#[derive(Copy, Clone, Debug, Default)]
pub struct Placement {
/// Horizontal offset with respect to the origin specified when computing
/// the placement.
pub left: i32,
/// Vertical offset with respect to the origin specified when computing
/// the placement.
pub top: i32,
/// Width in pixels.
pub width: u32,
/// Height in pixels.
pub height: u32,
}

impl Placement {
/// Given an origin, offset and bounding box, computes the resulting offset
/// and placement for a tightly bounded mask.
pub fn compute(
origin: Origin,
offset: impl Into<Vector>,
bounds: &Bounds,
) -> (Vector, Placement) {
let offset = offset.into();
let mut bounds = *bounds;
bounds.min = (bounds.min + offset).floor();
bounds.max = (bounds.max + offset).ceil();
let offset = Vector::new(-bounds.min.x + 1., -bounds.min.y);
let width = bounds.width() as u32 + 2;
let height = bounds.height() as u32;
let left = -offset.x as i32;
let top = if origin == Origin::BottomLeft {
(-offset.y).floor() + height as f32
} else {
-offset.y
} as i32;
(
offset,
Placement {
left,
top,
width,
height,
},
)
}
}

/// Builder for configuring and rendering a mask.
pub struct Mask<'a, 's, D> {
data: D,
Expand Down

0 comments on commit a1928c8

Please sign in to comment.