Use homogeneous coordinates to reduce floating point error when computing the intersection of self-intersecting line segments.

Partially addresses #57.
This commit is contained in:
Patrick Walton 2017-12-20 13:42:20 -08:00
parent f58d3a8512
commit 4c2d0cb5ab
1 changed files with 6 additions and 4 deletions

View File

@ -342,9 +342,10 @@ impl<'a> Partitioner<'a> {
self.emit_b_quads_around_active_edge(upper_active_edge_index, crossing_point.x);
self.emit_b_quads_around_active_edge(lower_active_edge_index, crossing_point.x);
} else {
debug!("warning: swapped active edges {} & {} without finding intersection",
upper_active_edge_index,
lower_active_edge_index);
warn!("swapped active edges {} & {} without finding intersection; rendering \
will probably be incorrect",
upper_active_edge_index,
lower_active_edge_index);
}
self.active_edges.swap(upper_active_edge_index as usize,
@ -1009,7 +1010,8 @@ impl<'a> Partitioner<'a> {
let (lower_line, _) =
Line::new(lower_left_vertex_position,
lower_right_endpoint_position).subdivide_at_x(max_x);
upper_line.intersect_with_line(&lower_line)
// Use `intersect_at_infinity()` to reduce floating point error.
upper_line.intersect_at_infinity(&lower_line)
}
(upper_control_point_vertex_index, u32::MAX) => {