work on dcel

This commit is contained in:
Skyler Lehmkuhl
2026-03-01 00:35:02 -05:00
parent 14a2b0a4c2
commit 9edfc2086a
4 changed files with 108 additions and 4 deletions
@@ -4,7 +4,7 @@
//! `Dcel::insert_stroke()`. Undo is handled by snapshotting the DCEL.
use crate::action::Action;
use crate::dcel::{bezpath_to_cubic_segments, Dcel, DEFAULT_SNAP_EPSILON};
use crate::dcel::{bezpath_to_cubic_segments, Dcel, FaceId, DEFAULT_SNAP_EPSILON};
use crate::document::Document;
use crate::layer::AnyLayer;
use crate::shape::{ShapeColor, StrokeStyle};
@@ -87,8 +87,24 @@ impl Action for AddShapeAction {
// Apply fill to new faces if this is a closed shape with fill
if self.is_closed {
if let Some(ref fill) = self.fill_color {
for face_id in &result.new_faces {
dcel.face_mut(*face_id).fill_color = Some(fill.clone());
if !result.new_faces.is_empty() {
for face_id in &result.new_faces {
dcel.face_mut(*face_id).fill_color = Some(fill.clone());
}
} else if let Some(&first_edge) = result.new_edges.first() {
// Closed shape in F0 — no face was auto-created.
// One half-edge of the first new edge is on the interior cycle.
// Pick the side with positive signed area (CCW winding).
let [he_a, he_b] = dcel.edge(first_edge).half_edges;
let interior_he = if dcel.cycle_signed_area(he_a) > 0.0 {
he_a
} else {
he_b
};
if dcel.half_edge(interior_he).face == FaceId(0) {
let face_id = dcel.create_face_at_cycle(interior_he);
dcel.face_mut(face_id).fill_color = Some(fill.clone());
}
}
}
}