@@ -12,33 +12,42 @@ use crate::{
1212 offset_split_arcs:: offset_split_arcs
1313} ;
1414
15+ /// Configuration options for offsetting operations.
1516pub struct OffsetCfg < ' a > {
16- pub svg : Option < & ' a mut SVG > , // Optional SVG context for rendering
17- pub reconnect : bool , // Flag to indicate if reconnecting arcs is needed
18- pub debug_orig : bool , // Flag to enable debug original polyline
19- pub debug_row : bool , // Flag to enable debug row offsets
20- pub debug_connect : bool , // Flag to enable debug connect offsets
21- pub debug_split : bool , // Flag to enable debug split offsets
22- pub debug_prune : bool , // Flag to enable debug pruned offsets
23- pub debug_final : bool , // Flag to enable debug final offsets
17+ /// Optional SVG context for rendering
18+ pub svg : Option < & ' a mut SVG > ,
19+ /// Flag to indicate if reconnecting arcs is needed
20+ pub reconnect : bool ,
21+ /// Flag to enable writing in svg original polyline
22+ pub svg_orig : bool ,
23+ /// Flag to enable writing in svg raw offsets
24+ pub svg_raw : bool ,
25+ /// Flag to enable writing in svg connect offsets
26+ pub svg_connect : bool ,
27+ /// Flag to enable writing in svg split offsets
28+ pub svg_split : bool ,
29+ /// Flag to enable writing in svg pruned offsets
30+ pub svg_prune : bool ,
31+ /// Flag to enable writing in svg final offsets
32+ pub svg_final : bool ,
2433}
2534
2635impl < ' a > Default for OffsetCfg < ' a > {
2736 fn default ( ) -> Self {
2837 OffsetCfg {
29- svg : None , // SVG context can be set later
30- reconnect : true , // Default to reconnecting arcs
31- debug_orig : false , // Debugging flags are off by default
32- debug_row : false , // Debugging flags are off by default
33- debug_connect : false , // Debugging flags are off by default
34- debug_split : false , // Debugging flags are off by default
35- debug_prune : false , // Debugging flags are off by default
36- debug_final : false , // Debugging reconnect arcs
38+ svg : None ,
39+ reconnect : true ,
40+ svg_orig : false ,
41+ svg_raw : false ,
42+ svg_connect : false ,
43+ svg_split : false ,
44+ svg_prune : false ,
45+ svg_final : false ,
3746 }
3847 }
3948}
4049
41- /// Computes the offset of a polyline and returns result as simplified polylines.
50+ /// Computes the offset of a polyline and returns result as multiple polylines.
4251///
4352/// This is the main entry point for polyline offsetting. It takes an input polyline,
4453/// applies the specified offset distance, and returns a vector of output polylines.
@@ -98,7 +107,7 @@ pub fn offset_polyline_to_polyline(
98107 cfg : & mut OffsetCfg ,
99108) -> Vec < Polyline > {
100109 if let Some ( svg) = cfg. svg . as_deref_mut ( )
101- && cfg. debug_orig
110+ && cfg. svg_orig
102111 {
103112 svg. polyline ( poly, "red" ) ;
104113 }
@@ -117,15 +126,15 @@ pub fn offset_polyline_to_polyline(
117126 let final_poly = arcs_to_polylines ( & reconnect_arcs) ;
118127
119128 if let Some ( svg) = cfg. svg . as_deref_mut ( ) {
120- if cfg. debug_final {
129+ if cfg. svg_final {
121130 svg. polylines ( & final_poly, "violet" ) ;
122131 }
123132 }
124133
125134 final_poly
126135}
127136
128- /// Computes the offset of an Arcline and returns result as Arcline-s.
137+ /// Computes the offset of an Arcline and returns result as multiple Arcline-s.
129138///
130139/// This function is similar to `offset_polyline_to_polyline` but operates on arclines
131140/// (sequences of arcs). This is useful when
@@ -185,7 +194,7 @@ pub fn offset_polyline_to_polyline(
185194///
186195pub fn offset_arcline_to_arcline ( arcs : & Arcline , off : f64 , cfg : & mut OffsetCfg ) -> Vec < Arcline > {
187196 if let Some ( svg) = cfg. svg . as_deref_mut ( )
188- && cfg. debug_orig
197+ && cfg. svg_orig
189198 {
190199 svg. arcline ( arcs, "red" ) ;
191200 }
@@ -212,7 +221,7 @@ pub fn offset_arcline_to_arcline(arcs: &Arcline, off: f64, cfg: &mut OffsetCfg)
212221 }
213222
214223 if let Some ( svg) = cfg. svg . as_deref_mut ( ) {
215- if cfg. debug_final {
224+ if cfg. svg_final {
216225 svg. arclines ( & final_arcs, "violet" ) ;
217226 }
218227 }
@@ -236,6 +245,8 @@ fn offset_arcline_to_arcline_impl(arcs: &Arcline, off: f64, cfg: &mut OffsetCfg)
236245 offset_arcs
237246}
238247
248+ #[ doc( hidden) ]
249+ /// Converts a vector of arcs into a vector of polylines.
239250pub fn arcs_to_polylines ( reconnect_arcs : & Vec < Vec < Arc > > ) -> Vec < Polyline > {
240251 let mut polylines = Vec :: with_capacity ( reconnect_arcs. len ( ) ) ;
241252 for arcs in reconnect_arcs. iter ( ) {
@@ -245,9 +256,10 @@ pub fn arcs_to_polylines(reconnect_arcs: &Vec<Vec<Arc>>) -> Vec<Polyline> {
245256 polylines
246257}
247258
248- // function to convert from Vec<Arc> to Polyline
249- // Note: arcs is a loop of arcs and when converting to PVertex,
250- // some Arc can be either "a" to "b" or "b" to "a" oriented
259+ #[ doc( hidden) ]
260+ /// function to convert from Vec<Arc> to Polyline
261+ /// Note: arcs is a loop of arcs and when converting to PVertex,
262+ /// some Arc can be either "a" to "b" or "b" to "a" oriented
251263pub fn arcs_to_polylines_single ( arcs : & Vec < Arc > ) -> Polyline {
252264 let mut polyline = Vec :: new ( ) ;
253265
@@ -384,6 +396,8 @@ mod test_arcs_to_polylines {
384396 }
385397}
386398
399+
400+ #[ doc( hidden) ]
387401pub fn offset_polyline_multiple (
388402 poly : & Polyline ,
389403 step : f64 ,
@@ -404,21 +418,21 @@ pub fn offset_polyline_multiple(
404418fn offset_single ( poly_raws : & Vec < Vec < OffsetRaw > > , off : f64 , cfg : & mut OffsetCfg ) -> Vec < Arc > {
405419 let offset_raw = offset_polyline_raw:: offset_polyline_raw ( & poly_raws, off) ;
406420 if let Some ( svg) = cfg. svg . as_deref_mut ( )
407- && cfg. debug_row
421+ && cfg. svg_raw
408422 {
409423 svg_offset_raws ( svg, & offset_raw, "blue" ) ;
410424 }
411425
412426 let offset_connect = offset_connect_raw ( & offset_raw, off) ;
413427 if let Some ( svg) = cfg. svg . as_deref_mut ( )
414- && cfg. debug_connect
428+ && cfg. svg_connect
415429 {
416430 svg. arclines ( & offset_connect, "violet" ) ;
417431 }
418432
419433 let mut offset_split = offset_split_arcs ( & offset_raw, & offset_connect) ;
420434 if let Some ( svg) = cfg. svg . as_deref_mut ( )
421- && cfg. debug_split
435+ && cfg. svg_split
422436 {
423437 svg. arcline ( & offset_split, "violet" ) ;
424438 svg. offset_segments_single_points ( & offset_split, "violet" ) ;
@@ -427,14 +441,16 @@ fn offset_single(poly_raws: &Vec<Vec<OffsetRaw>>, off: f64, cfg: &mut OffsetCfg)
427441 let offset_prune = offset_prune_invalid ( & poly_raws, & mut offset_split, off) ;
428442
429443 if let Some ( svg) = cfg. svg . as_deref_mut ( )
430- && cfg. debug_prune
444+ && cfg. svg_prune
431445 {
432446 svg. arcline ( & offset_prune, "violet" ) ;
433447 svg. offset_segments_single_points ( & offset_prune, "violet" ) ;
434448 }
435449 offset_prune
436450}
437451
452+
453+ #[ doc( hidden) ]
438454pub fn svg_offset_raws ( svg : & mut SVG , offset_raws : & Vec < Vec < OffsetRaw > > , color : & str ) {
439455 for raw in offset_raws {
440456 for seg in raw {
@@ -1585,6 +1601,7 @@ pub fn check_if_segments_intersect(off0: OffsetSegment, off1: OffsetSegment) ->
15851601// }
15861602
15871603/// Test polyline for offseting.
1604+ /// Has a mix of positive and negative offsets.
15881605pub fn pline_01 ( ) -> Vec < Polyline > {
15891606 let pline = vec ! [
15901607 pvertex( point( 100.0 , 100.0 ) , 1.5 ) ,
@@ -1617,6 +1634,8 @@ pub fn pline_01() -> Vec<Polyline> {
16171634 return plines;
16181635}
16191636
1637+
1638+ /// Test polyline for offseting.
16201639pub fn pline_02 ( ) -> Polyline {
16211640 let pline = vec ! [
16221641 pvertex( point( 50.0 , 50.0 ) , ZERO ) ,
@@ -2016,6 +2035,7 @@ pub fn pline_04() -> Vec<Polyline> {
20162035
20172036// }
20182037
2038+ #[ doc( hidden) ]
20192039pub fn polyline_to_arcs ( plines : & Vec < Polyline > ) -> Vec < Vec < Arc > > {
20202040 let mut varcs: Vec < Vec < Arc > > = Vec :: new ( ) ;
20212041 for pline in plines {
@@ -2024,6 +2044,7 @@ pub fn polyline_to_arcs(plines: &Vec<Polyline>) -> Vec<Vec<Arc>> {
20242044 varcs
20252045}
20262046
2047+ #[ doc( hidden) ]
20272048fn polyline_to_arcs_single ( pline : & Polyline ) -> Vec < Arc > {
20282049 let mut arcs = Vec :: with_capacity ( pline. len ( ) + 1 ) ;
20292050 let last = pline. len ( ) - 1 ;
0 commit comments