Skip to content

Commit bb6fe50

Browse files
authored
vello_toy: Color lines according to their winding sign (#846)
#845 removed line-tile intersections from the debug rendering, as these are no longer present in the internal representation. However, that also removed a way to see whether lines are directed upwards or downwards, which is important to understand their effect on winding. This proposes coloring the lines according to their orientation: lines oriented upwards add to winding and are colored green. Lines oriented downwards subtract from winding and are colored red. Horizontal lines don't affect winding, and will with future changes likely not generate any tiles at all. These are colored grey. An example of what that looks like: ```shell cargo run --bin debug -- --path "M 5 5 L 40 23 L 20 43.5 L 1 43.5 Z" --stages ls,ta ``` ![debug](https://github.com/user-attachments/assets/ee4600a8-eb03-4cef-9796-a86cafec9526)
1 parent 4a75ece commit bb6fe50

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

sparse_strips/vello_toy/src/debug.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use clap::Parser;
1212
use std::collections::HashSet;
1313
use std::path;
1414
use svg::node::element::path::Data;
15-
use svg::node::element::{Path, Rectangle};
15+
use svg::node::element::{Line as SvgLine, Path, Rectangle};
1616
use svg::{Document, Node};
1717
use vello_common::coarse::{Cmd, Wide, WideTile};
1818
use vello_common::color::palette::css::BLACK;
@@ -140,31 +140,33 @@ fn draw_grid(document: &mut Document, width: u16, height: u16) {
140140
}
141141

142142
fn draw_line_segments(document: &mut Document, line_buf: &[Line]) {
143-
let mut data = Data::new();
144-
145-
let mut last = None;
143+
let svg_line = SvgLine::new()
144+
.set("stroke-width", 0.1)
145+
.set("fill", "none")
146+
.set("fill-opacity", 0.1);
146147

147148
for line in line_buf {
148-
let first = (line.p0.x, line.p0.y);
149-
let second = (line.p1.x, line.p1.y);
150-
151-
if Some(first) != last {
152-
data = data.move_to(first);
153-
}
154-
155-
data = data.line_to(second);
149+
let dy = line.p1.y - line.p0.y;
150+
let color = if dy < 0. {
151+
// Lines oriented upwards add to winding.
152+
"green"
153+
} else if dy > 0. {
154+
// Lines oriented upwards subtract from winding.
155+
"red"
156+
} else {
157+
// Horizontal lines don't impact winding.
158+
"grey"
159+
};
156160

157-
last = Some(second);
161+
let svg_line = svg_line
162+
.clone()
163+
.set("x1", line.p0.x)
164+
.set("y1", line.p0.y)
165+
.set("x2", line.p1.x)
166+
.set("y2", line.p1.y)
167+
.set("stroke", color);
168+
document.append(svg_line);
158169
}
159-
160-
let border = Path::new()
161-
.set("stroke-width", 0.1)
162-
.set("stroke", "green")
163-
.set("fill", "none")
164-
.set("fill-opacity", 0.1)
165-
.set("d", data);
166-
167-
document.append(border);
168170
}
169171

170172
fn draw_tile_areas(document: &mut Document, tiles: &Tiles) {

0 commit comments

Comments
 (0)