Skip to content

Commit 6cdb171

Browse files
committed
[path] use arrow like sub-path representation
1 parent afc63dc commit 6cdb171

File tree

4 files changed

+208
-107
lines changed

4 files changed

+208
-107
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rasterize"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
authors = ["Pavel Aslanov <asl.pavel@gmail.com>"]
55
description = "Simple and small 2D rendering library"
66
edition = "2021"
@@ -29,7 +29,7 @@ tracing = "^0.1"
2929
serde = { version = "1.0", features = ["rc", "derive"], optional = true }
3030
serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
3131
png = { version = "^0.17", optional = true }
32-
bytemuck = { version = "1.13", features = ["derive"] }
32+
bytemuck = { version = "1.21", features = ["derive"] }
3333

3434
[dev-dependencies]
3535
criterion = { version = "^0.5", features = ["html_reports"] }

examples/hatchet.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ fn hatch(path: &Path, normal: Line, ratio: Scalar) -> Path {
149149
// all segments grouped by subpath with included closing lines
150150
let segments: Vec<_> = path
151151
.subpaths()
152-
.iter()
153152
.map(|subpath| {
154153
let last = subpath
155154
.end()
@@ -164,7 +163,7 @@ fn hatch(path: &Path, normal: Line, ratio: Scalar) -> Path {
164163
})
165164
.collect();
166165

167-
let mut subpaths_out = Vec::new();
166+
let mut path = Path::empty();
168167
let mut offset_y = 0.0;
169168
while offset_y < bbox_tr.height() + period {
170169
let ints_low = intersect(
@@ -282,17 +281,15 @@ fn hatch(path: &Path, normal: Line, ratio: Scalar) -> Path {
282281
break;
283282
}
284283
}
285-
if let Some(subpath) = SubPath::new(subpath_out, true) {
286-
subpaths_out.push(subpath);
287-
}
284+
path.push(&subpath_out, true);
288285
}
289286

290287
// TODO:
291288
// - include subpath, when bounding box fits between low and high lines
292289
offset_y += period;
293290
}
294291

295-
Path::new(subpaths_out)
292+
path
296293
}
297294

298295
fn generate_bar(
@@ -313,18 +310,18 @@ fn generate_bar(
313310
let by = bbox.y() + border;
314311
let bh = (bbox.height() - 2.0 * border) * (1.0 - frac);
315312
let bw = bbox.width() - 2.0 * border;
316-
let border = Path::builder()
313+
let mut border = Path::builder()
317314
.move_to((bx, by))
318315
.rbox((bw, bh), radii)
319-
.build()
320-
.reverse();
321-
path.extend(border);
316+
.build();
317+
border.reverse();
318+
path.extend(&border);
322319
let ib = hatch_normal.length() * hatch_ratio;
323320
let hatch_path = Path::builder()
324321
.move_to((bx + ib, by + ib))
325322
.rbox((bw - 2.0 * ib, bh - 2.0 * ib), radii)
326323
.build();
327-
path.extend(hatch(&hatch_path, hatch_normal, hatch_ratio));
324+
path.extend(&hatch(&hatch_path, hatch_normal, hatch_ratio));
328325
}
329326
path
330327
}
@@ -419,7 +416,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
419416
Line::new((0.0, 0.0), (70.0, 70.0)),
420417
0.3,
421418
);
422-
path.extend(charging.clone());
419+
path.extend(&charging);
423420
path.transform(tr);
424421
glyphs.push(Glyph {
425422
path,

examples/rasterize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn outline(path: &Path, tr: Transform) -> Scene {
176176
};
177177
let control_radius = 3.0;
178178
let mut output = path.stroke(stroke_style);
179-
for subpath in path.subpaths().iter() {
179+
for subpath in path.subpaths() {
180180
for segment in subpath.segments() {
181181
let mut control = Path::builder();
182182
match segment {
@@ -201,16 +201,16 @@ fn outline(path: &Path, tr: Transform) -> Scene {
201201
}
202202
};
203203
output.extend(
204-
Path::builder()
204+
&Path::builder()
205205
.move_to(segment.start())
206206
.circle(control_radius)
207207
.build(),
208208
);
209-
output.extend(control.build().stroke(control_style));
209+
output.extend(&control.build().stroke(control_style));
210210
}
211211
if (subpath.start() - subpath.end()).length() > control_radius {
212212
output.extend(
213-
Path::builder()
213+
&Path::builder()
214214
.move_to(subpath.end())
215215
.circle(control_radius)
216216
.build(),

0 commit comments

Comments
 (0)