Skip to content

Commit

Permalink
feat: windows support and example
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst authored Mar 21, 2024
1 parent fa66f9c commit 468e9aa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn main() {
.file("clipper2/clipper.offset.cpp")
.file("clipper2/clipper.rectclip.cpp")
.file("clipper2/wrapper.cpp")
.flag_if_supported("-std:c++17") // MSVC
.flag_if_supported("-std=c++17")
.compile("clipper2");

Expand Down
1 change: 1 addition & 0 deletions clipper2/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C"
{
#endif

#include <stdint.h>
#include <stdlib.h>

typedef enum ClipTypeC
Expand Down
43 changes: 43 additions & 0 deletions examples/union.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use clipper2::{Path, PathType, Polygon, Polygons, Vertex};

fn main() {
let path1 = Path::new(
vec![
Vertex::new(0.1, 0.0),
Vertex::new(10.0, 0.0),
Vertex::new(10.0, 10.0),
Vertex::new(0.0, 10.0),
],
true,
);
let path2 = Path::new(
vec![
Vertex::new(5.0, 5.0),
Vertex::new(15.0, 5.0),
Vertex::new(15.0, 15.0),
Vertex::new(5.0, 15.0),
],
true,
);
let polygons = Polygons::new(vec![Polygon::new(
vec![path1.clone(), path2.clone()],
PathType::Subject,
)]);

let output = clipper2::union(polygons);
println!(
"Vertices: {}",
output
.polygons()
.first()
.unwrap()
.paths()
.first()
.unwrap()
.vertices()
.iter()
.map(|v| format!("({:.1}, {:.1})", v.x(), v.y()))
.collect::<Vec<_>>()
.join(", ")
);
}

0 comments on commit 468e9aa

Please sign in to comment.