From 4c2d0cb5ab9141fe6fdaab4e22485154763d59a0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Dec 2017 13:42:20 -0800 Subject: [PATCH] Use homogeneous coordinates to reduce floating point error when computing the intersection of self-intersecting line segments. Partially addresses #57. --- partitioner/src/partitioner.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/partitioner/src/partitioner.rs b/partitioner/src/partitioner.rs index d79f84b8..32eec49b 100644 --- a/partitioner/src/partitioner.rs +++ b/partitioner/src/partitioner.rs @@ -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) => {