Skip to content

Commit 2f5f3af

Browse files
committed
Rename example from offset_simple to offset_polyline and update associated documentation; remove unused files and add new SVG output.
1 parent dc628ad commit 2f5f3af

5 files changed

Lines changed: 21 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ name = "offset_multiple"
2727
harness = false
2828

2929
[[example]]
30-
name = "offset_simple"
30+
name = "offset_polyline"
3131

3232
[[example]]
3333
name = "offset_multiple"

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44

55
```
6-
cargo run --example offset_simple
6+
cargo run --example offset_polyline
77
```
88

9-
![](https://raw.githubusercontent.com/radevgit/offroad/refs/heads/main/examples/img/offset_simple.svg "offset_simple")
9+
![](https://raw.githubusercontent.com/radevgit/offroad/refs/heads/main/examples/img/offset_polyline.svg "offset_polyline")
1010

1111
```
1212
cargo run --example offset_multiple
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ use geom::prelude::*;
22
use offroad::prelude::{OffsetCfg, offset_polyline_to_polyline};
33

44
fn main() {
5+
// Configuration for offsetting
56
let mut cfg = OffsetCfg::default();
67
let mut svg = SVG::new(300.0, 300.0, "/tmp/out2.svg");
78
cfg.svg = Some(&mut svg);
9+
// Show original polyline in SVG output
810
cfg.debug_orig = true;
9-
cfg.debug_reconnect = true;
11+
// Show final offset polylines in SVG output
12+
cfg.debug_final = true;
1013

1114
let poly_orig = vec![
1215
pvertex(point(0.0, 0.0), 0.0),

src/offset.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct OffsetCfg<'a> {
1515
pub debug_connect: bool, // Flag to enable debug connect offsets
1616
pub debug_split: bool, // Flag to enable debug split offsets
1717
pub debug_prune: bool, // Flag to enable debug pruned offsets
18-
pub debug_reconnect: bool, // Flag to enable debug reconnect arcs
18+
pub debug_final: bool, // Flag to enable debug final offsets
1919
}
2020

2121
impl<'a> Default for OffsetCfg<'a> {
@@ -28,7 +28,7 @@ impl<'a> Default for OffsetCfg<'a> {
2828
debug_connect: false, // Debugging flags are off by default
2929
debug_split: false, // Debugging flags are off by default
3030
debug_prune: false, // Debugging flags are off by default
31-
debug_reconnect: false, // Debugging reconnect arcs
31+
debug_final: false, // Debugging reconnect arcs
3232
}
3333
}
3434
}
@@ -109,15 +109,15 @@ pub fn offset_polyline_to_polyline(
109109
println!(" Component {}: {} arcs", i, component.len());
110110
}
111111

112-
let result = arcs_to_polylines(&reconnect_arcs);
112+
let final_poly = arcs_to_polylines(&reconnect_arcs);
113113

114114
if let Some(svg) = cfg.svg.as_deref_mut() {
115-
if cfg.debug_reconnect {
116-
svg.polylines(&result, "violet");
115+
if cfg.debug_final {
116+
svg.polylines(&final_poly, "violet");
117117
}
118118
}
119119

120-
result
120+
final_poly
121121
}
122122

123123
/// Computes the offset of an Arcline and returns result as Arcline-s.
@@ -192,27 +192,27 @@ pub fn offset_arcline_to_arcline(arcs: &Arcline, off: f64, cfg: &mut OffsetCfg)
192192
// remove bridges
193193
remove_bridge_arcs(&mut mod_arcs);
194194

195-
let mut result = Vec::new();
195+
let mut final_arcs = Vec::new();
196196
if cfg.reconnect {
197-
result = offset_reconnect_arcs(&mut mod_arcs);
197+
final_arcs = offset_reconnect_arcs(&mut mod_arcs);
198198
println!(
199199
"offset_reconnect_arcs returned {} components",
200-
result.len()
200+
final_arcs.len()
201201
);
202-
for (i, component) in result.iter().enumerate() {
202+
for (i, component) in final_arcs.iter().enumerate() {
203203
println!(" Component {}: {} arcs", i, component.len());
204204
}
205205
} else {
206-
result.push(mod_arcs);
206+
final_arcs.push(mod_arcs);
207207
}
208208

209209
if let Some(svg) = cfg.svg.as_deref_mut() {
210-
if cfg.debug_reconnect {
211-
svg.arclines(&result, "violet");
210+
if cfg.debug_final {
211+
svg.arclines(&final_arcs, "violet");
212212
}
213213
}
214214

215-
result
215+
final_arcs
216216
}
217217

218218
fn offset_polyline_to_polyline_impl(poly: &Polyline, off: f64, cfg: &mut OffsetCfg) -> Vec<Arc> {

0 commit comments

Comments
 (0)