Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions cetz-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ciborium::ser::into_writer;
use serde::Deserialize;
use serde::Serialize;
use wasm_minimal_protocol::*;
use std::cmp;

mod layout;
pub use layout::{InputTree, OutputTree};
Expand Down Expand Up @@ -117,15 +118,12 @@ fn aabb(init: Option<Bounds>, pts: Vec<Point>) -> Result<Bounds, String> {
let mut bounds = match init {
Some(init) => init,
None => Bounds {
low: pts.first().unwrap().clone(),
high: pts.first().unwrap().clone(),
low: pts.first().unwrap().clone().iter().take(3).cloned().collect(),
high: pts.first().unwrap().iter().take(3).cloned().collect(),
},
};
for pt in pts {
if pt.len() != 3 {
return Err("Point must have 3 dimensions".to_string());
}
for dim in 0..pt.len() {
for dim in 0..cmp::min(3, pt.len()) {
if pt[dim] < bounds.low[dim] {
bounds.low[dim] = pt[dim];
}
Expand Down
2 changes: 1 addition & 1 deletion src/canvas.typ
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
place(top + left, float: false, if drawable.type == "path" {
let vertices = ()

let transform-point((x, y, _)) = {
let transform-point((x, y, ..)) = {
(( x - offset-x - segment-x) * length,
(-y - offset-y - segment-y) * length)
}
Expand Down
4 changes: 2 additions & 2 deletions src/mark.typ
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

let t = (
// Translate & rotate to the target coordinate & direction
matrix.transform-translate(..pos),
matrix.transform-translate(..pos.slice(0, 3)),
matrix.transform-rotate-dir(dir, up),
matrix.transform-rotate-z(-90deg),

Expand All @@ -142,7 +142,7 @@
}),

// Translate mark to have its anchor (tip, base, center) at (0,0)
matrix.transform-translate(..vector.scale(origin, if reverse {1} else {-1})),
matrix.transform-translate(..vector.scale(origin.slice(0, 3), if reverse {1} else {-1})),

// Mirror on x and/or y axis
if not flip or reverse {
Expand Down
6 changes: 3 additions & 3 deletions src/matrix.typ
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
/// - up (vector): idk
/// -> matrix
#let transform-rotate-dir(dir, up) = {
dir = vector.norm(dir)
up = vector.norm(up)
dir = vector.norm(dir.slice(0, 3))
up = vector.norm(up.slice(0, 3))

let (dx, dy, dz) = dir
let (ux, uy, uz) = up
Expand Down Expand Up @@ -257,7 +257,7 @@
/// - vec (vector): The vector to multiply
/// - w (float): The default value for the fourth element of the vector if it is three dimensional.
/// -> vector
#let mul4x4-vec3(mat, vec, w: 1) = {
#let mul4x4-vec3(mat, vec, w: 1.0) = {
assert(vec.len() <= 4)

let x = vec.at(0)
Expand Down
Loading