Skip to content

Commit 9af546e

Browse files
committed
lib: Improve Homogeneous Coordinate Support
1 parent 92759fe commit 9af546e

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

cetz-core/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use ciborium::ser::into_writer;
33
use serde::Deserialize;
44
use serde::Serialize;
55
use wasm_minimal_protocol::*;
6+
use std::cmp;
67

78
mod layout;
89
pub use layout::{InputTree, OutputTree};
@@ -117,15 +118,12 @@ fn aabb(init: Option<Bounds>, pts: Vec<Point>) -> Result<Bounds, String> {
117118
let mut bounds = match init {
118119
Some(init) => init,
119120
None => Bounds {
120-
low: pts.first().unwrap().clone(),
121-
high: pts.first().unwrap().clone(),
121+
low: pts.first().unwrap().clone().iter().take(3).cloned().collect(),
122+
high: pts.first().unwrap().iter().take(3).cloned().collect(),
122123
},
123124
};
124125
for pt in pts {
125-
if pt.len() != 3 {
126-
return Err("Point must have 3 dimensions".to_string());
127-
}
128-
for dim in 0..pt.len() {
126+
for dim in 0..cmp::min(3, pt.len()) {
129127
if pt[dim] < bounds.low[dim] {
130128
bounds.low[dim] = pt[dim];
131129
}

src/canvas.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
place(top + left, float: false, if drawable.type == "path" {
146146
let vertices = ()
147147

148-
let transform-point((x, y, _)) = {
148+
let transform-point((x, y, ..)) = {
149149
(( x - offset-x - segment-x) * length,
150150
(-y - offset-y - segment-y) * length)
151151
}

src/mark.typ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127

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

@@ -139,7 +139,7 @@
139139
}),
140140

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

144144
// Mirror on x and/or y axis
145145
if not flip or reverse {

src/matrix.typ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
/// - up (vector): idk
124124
/// -> matrix
125125
#let transform-rotate-dir(dir, up) = {
126-
dir = vector.norm(dir)
127-
up = vector.norm(up)
126+
dir = vector.norm(dir.slice(0, 3))
127+
up = vector.norm(up.slice(0, 3))
128128

129129
let (dx, dy, dz) = dir
130130
let (ux, uy, uz) = up

0 commit comments

Comments
 (0)