Skip to content

Commit c964283

Browse files
committed
Added benchmark examples and fixed arcline offset
1 parent 91cc32e commit c964283

13 files changed

+226
-81
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.4.0] - 2025-10-25
4+
- fixed offset for arclines
5+
- added benchmarks
6+
37
## [0.4.0] - 2025-10-25
48
- Fixed negative bulge arc offsetting bugs
59
- Improved bulge sign inference from arc connectivity

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "offroad"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "2D offsetting for arc polylines/polygons."
55
rust-version = "1.88"
66
edition = "2024"
@@ -34,6 +34,18 @@ opt-level = 3
3434
name = "bench_offset_multiple"
3535
harness = false
3636

37+
[[bench]]
38+
name = "bench_offset_multiple200"
39+
harness = false
40+
41+
[[bench]]
42+
name = "bench_offset_multiple500"
43+
harness = false
44+
45+
[[bench]]
46+
name = "bench_offset_multiple1000"
47+
harness = false
48+
3749
[workspace.lints]
3850
rust.unsafe_code = "forbid"
3951

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::time::Instant;
2+
use togo::{poly::arcline1000, prelude::*};
3+
use offroad::prelude::*;
4+
5+
fn main() {
6+
println!("Multi-Offset Benchmark (~1000 arcs in double spiral)");
7+
println!("======================================================");
8+
9+
let mut cfg = OffsetCfg::default();
10+
cfg.svg_orig = false;
11+
let arc_orig = arcline1000();
12+
13+
let start = Instant::now();
14+
15+
// Forward direction
16+
for i in 1..26 {
17+
offset_arcline_to_arcline(&arc_orig, (i as f64)/4.0, &mut cfg);
18+
}
19+
20+
// Reverse direction
21+
let arcs_reversed = arcline_reverse(&arc_orig);
22+
for i in 1..26 {
23+
offset_arcline_to_arcline(&arcs_reversed, (i as f64)/4.0, &mut cfg);
24+
}
25+
26+
let total_time = start.elapsed();
27+
let operations = 25 * 2; // 25 offsets in each direction
28+
let avg_per_operation = total_time / operations;
29+
30+
println!("Total time for {} offset operations: {:?}", operations, total_time);
31+
println!("Average time per operation: {:?}", avg_per_operation);
32+
println!("Operations per second: {:.1}", 1.0 / avg_per_operation.as_secs_f64());
33+
}
34+
35+
/*
36+
> cargo bench --bench bench_offset_multiple1000
37+
38+
Total time for 50 offset operations: 17.233370346s
39+
Average time per operation: 344.667406ms
40+
Operations per second: 2.9
41+
42+
*/
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
use std::time::Instant;
2-
use togo::prelude::*;
2+
use togo::{poly::arcline200, prelude::*};
33
use offroad::prelude::*;
44

55
fn main() {
6-
println!("Multi-Offset Benchmark (based on offset_multi example)");
6+
println!("Multi-Offset Benchmark (~200 arcs in double spiral)");
77
println!("======================================================");
88

99
let mut cfg = OffsetCfg::default();
1010
cfg.svg_orig = false;
11-
let poly_orig = pline_01()[0].clone();
12-
let poly = polyline_translate(&poly_orig, point(250.0, 100.0));
11+
let arc_orig = arcline200();
1312

1413
let start = Instant::now();
1514

1615
// Forward direction
17-
for i in 1..500 {
18-
offset_polyline_to_polyline(&poly, (i as f64)/5.0, &mut cfg);
16+
for i in 1..100 {
17+
offset_arcline_to_arcline(&arc_orig, (i as f64)/4.0, &mut cfg);
1918
}
2019

2120
// Reverse direction
22-
let poly = polyline_reverse(&poly);
23-
for i in 1..500 {
24-
offset_polyline_to_polyline(&poly, (i as f64)/5.0, &mut cfg);
21+
let arcs_reversed = arcline_reverse(&arc_orig);
22+
for i in 1..100 {
23+
offset_arcline_to_arcline(&arcs_reversed, (i as f64)/4.0, &mut cfg);
2524
}
2625

2726
let total_time = start.elapsed();
28-
let operations = 149 * 2; // 149 offsets in each direction
27+
let operations = 99 * 2; // 99 offsets in each direction
2928
let avg_per_operation = total_time / operations;
3029

3130
println!("Total time for {} offset operations: {:?}", operations, total_time);
@@ -34,10 +33,11 @@ fn main() {
3433
}
3534

3635
/*
37-
> cargo bench
36+
> cargo bench --bench bench_offset_multiple200
37+
38+
Total time for 198 offset operations: 3.386764598s
39+
Average time per operation: 17.104871ms
40+
Operations per second: 58.5
3841
39-
Total time for 298 offset operations: 196.589137ms
40-
Average time per operation: 659.695µs
41-
Operations per second: 1515.9
4242
4343
*/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::time::Instant;
2+
use togo::{poly::arcline500, prelude::*};
3+
use offroad::prelude::*;
4+
5+
fn main() {
6+
println!("Multi-Offset Benchmark (~500 arcs in double spiral)");
7+
println!("======================================================");
8+
9+
let mut cfg = OffsetCfg::default();
10+
cfg.svg_orig = false;
11+
let arc_orig = arcline500();
12+
13+
let start = Instant::now();
14+
15+
// Forward direction
16+
for i in 1..100 {
17+
offset_arcline_to_arcline(&arc_orig, (i as f64)/4.0, &mut cfg);
18+
}
19+
20+
// Reverse direction
21+
let arcs_reversed = arcline_reverse(&arc_orig);
22+
for i in 1..100 {
23+
offset_arcline_to_arcline(&arcs_reversed, (i as f64)/4.0, &mut cfg);
24+
}
25+
26+
let total_time = start.elapsed();
27+
let operations = 99 * 2; // 99 offsets in each direction
28+
let avg_per_operation = total_time / operations;
29+
30+
println!("Total time for {} offset operations: {:?}", operations, total_time);
31+
println!("Average time per operation: {:?}", avg_per_operation);
32+
println!("Operations per second: {:.1}", 1.0 / avg_per_operation.as_secs_f64());
33+
}
34+
35+
/*
36+
> cargo bench --bench bench_offset_multiple500
37+
38+
Total time for 198 offset operations: 14.064167675s
39+
Average time per operation: 71.031149ms
40+
Operations per second: 14.1
41+
42+
43+
*/

examples/offset_arcline1000.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
let mut svg = SVG::new(800.0, 800.0, Some("/tmp/arcline1000.svg"));
77
cfg.svg = Some(&mut svg);
88
cfg.svg_orig = true;
9-
cfg.svg_raw = true;
9+
cfg.svg_final = true;
1010

1111
let poly = arcline1000();
1212
let _offset_polylines = offset_arcline_to_arcline(&poly, 2.0, &mut cfg);

examples/offset_arcline200.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ fn main() {
66
let mut svg = SVG::new(800.0, 800.0, Some("/tmp/arcline200.svg"));
77
cfg.svg = Some(&mut svg);
88
cfg.svg_orig = true;
9-
cfg.svg_raw = true;
9+
cfg.svg_connect = true;
1010

1111
let poly = arcline200();
12-
let _offset_polylines = offset_arcline_to_arcline(&poly, 4.0, &mut cfg);
12+
let _offset_polylines = offset_arcline_to_arcline(&poly, 5.0, &mut cfg);
1313

1414
if let Some(svg) = cfg.svg.as_mut(){
1515
// Write svg to file

examples/offset_arcline500.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ fn main() {
66
let mut svg = SVG::new(800.0, 800.0, Some("/tmp/arcline500.svg"));
77
cfg.svg = Some(&mut svg);
88
cfg.svg_orig = true;
9-
cfg.svg_raw = true;
9+
cfg.svg_final = true;
1010

1111
let poly = arcline500();
12-
let _offset_polylines = offset_arcline_to_arcline(&poly, 2.0, &mut cfg);
12+
let _offset_polylines = offset_arcline_to_arcline(&poly, 13.0, &mut cfg);
1313

1414
if let Some(svg) = cfg.svg.as_mut(){
1515
// Write svg to file

examples/offset_multi200.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ fn main() {
77
let mut svg = SVG::new(800.0, 800.0, Some("/tmp/multi200.svg"));
88
cfg.svg = Some(&mut svg);
99
cfg.svg_orig = true;
10-
cfg.svg_raw = true;
10+
cfg.svg_final = true;
1111

12-
let poly_orig = arcline200();
12+
let arcs_orig = arcline200();
1313
// Translate to fit in the SVG viewport
1414
//let poly = polyline_translate(&poly_orig, point(250.0, 100.0));
1515

1616
let mut offset_external = vec![];
17-
for i in 1..5 {
18-
let offset = offset_arcline_to_arcline(&poly_orig, (i as f64), &mut cfg);
17+
for i in 1..10 {
18+
let offset = offset_arcline_to_arcline(&arcs_orig, (i as f64), &mut cfg);
1919
offset_external.extend(offset);
2020
}
2121

22+
let arcs_reverse = arcline_reverse(&arcs_orig);
23+
24+
let mut offset_internal = vec![];
25+
for i in 1..10 {
26+
let offset = offset_arcline_to_arcline(&arcs_reverse, (i as f64), &mut cfg);
27+
offset_internal.extend(offset);
28+
}
29+
2230
if let Some(svg) = cfg.svg.as_mut(){
2331
// Write svg to file
2432
svg.write_stroke_width(0.1);

0 commit comments

Comments
 (0)