Skip to content

Commit a0d92c3

Browse files
committed
update example
1 parent 61a5b52 commit a0d92c3

File tree

5 files changed

+191
-221
lines changed

5 files changed

+191
-221
lines changed

examples/html/index.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
</style>
2323
<script type="module">
24-
import init, { Overlay, OverlayGraph, OverlayRule, ShapeType, FillRule} from './ishape/ishape_wasm.js';
24+
import init, { Overlay, OverlayRule, FillRule} from './ishape/ishape_wasm.js';
2525

2626
init();
2727

@@ -34,12 +34,8 @@
3434
const subj = JSON.parse(subjInput);
3535
const clip = JSON.parse(clipInput);
3636

37-
const overlay = new Overlay();
38-
overlay.add_paths(subj, ShapeType.Subject);
39-
overlay.add_paths(clip, ShapeType.Clip);
40-
41-
const graph = overlay.build_graph(FillRule.EvenOdd);
42-
const union = graph.extract_shapes(OverlayRule.Union);
37+
const overlay = Overlay.new_with_subj_and_clip(subj, clip);
38+
const union = overlay.overlay(OverlayRule.Union, FillRule.EvenOdd);
4339

4440
const resultText = JSON.stringify(union, null, 2);
4541
document.getElementById('result').innerText = `Result:\n${resultText}`;

examples/html/ishape/ishape_wasm.d.ts

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,71 +14,48 @@ export enum OverlayRule {
1414
Intersect = 2,
1515
Union = 3,
1616
Difference = 4,
17-
Xor = 5,
17+
InverseDifference = 5,
18+
Xor = 6,
1819
}
1920
/**
2021
*/
2122
export enum FillRule {
2223
EvenOdd = 0,
2324
NonZero = 1,
25+
Positive = 2,
26+
Negative = 3,
2427
}
2528
/**
2629
*/
2730
export class Overlay {
2831
free(): void;
2932
/**
33+
* @param {any} subj_js
34+
* @param {any} clip_js
35+
* @returns {Overlay | undefined}
3036
*/
31-
constructor();
32-
/**
33-
* @param {any} js_path
34-
* @param {ShapeType} shape_type
35-
*/
36-
add_path(js_path: any, shape_type: ShapeType): void;
37-
/**
38-
* @param {any} js_shape
39-
* @param {ShapeType} shape_type
40-
*/
41-
add_paths(js_shape: any, shape_type: ShapeType): void;
42-
/**
43-
* @param {FillRule} fill_rule
44-
* @returns {OverlayGraph}
45-
*/
46-
build_graph(fill_rule: FillRule): OverlayGraph;
47-
}
48-
/**
49-
*/
50-
export class OverlayGraph {
51-
free(): void;
52-
/**
53-
* @param {OverlayRule} overlay_rule
54-
* @returns {any}
55-
*/
56-
extract_shapes(overlay_rule: OverlayRule): any;
37+
static new_with_subj_and_clip(subj_js: any, clip_js: any): Overlay | undefined;
5738
/**
5839
* @param {OverlayRule} overlay_rule
59-
* @param {number} min_area_f64
40+
* @param {FillRule} fill_rule
6041
* @returns {any}
6142
*/
62-
extract_shapes_min_area(overlay_rule: OverlayRule, min_area_f64: number): any;
43+
overlay(overlay_rule: OverlayRule, fill_rule: FillRule): any;
6344
/**
45+
* @param {FillRule} fill_rule
6446
* @returns {any}
6547
*/
66-
links(): any;
48+
separate_vectors(fill_rule: FillRule): any;
6749
}
6850

6951
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7052

7153
export interface InitOutput {
7254
readonly memory: WebAssembly.Memory;
73-
readonly __wbg_overlay_free: (a: number) => void;
74-
readonly overlay_create: () => number;
75-
readonly overlay_add_path: (a: number, b: number, c: number) => void;
76-
readonly overlay_add_paths: (a: number, b: number, c: number) => void;
77-
readonly overlay_build_graph: (a: number, b: number) => number;
78-
readonly __wbg_overlaygraph_free: (a: number) => void;
79-
readonly overlaygraph_extract_shapes: (a: number, b: number) => number;
80-
readonly overlaygraph_extract_shapes_min_area: (a: number, b: number, c: number) => number;
81-
readonly overlaygraph_links: (a: number) => number;
55+
readonly __wbg_overlay_free: (a: number, b: number) => void;
56+
readonly overlay_new_with_subj_and_clip: (a: number, b: number) => number;
57+
readonly overlay_overlay: (a: number, b: number, c: number) => number;
58+
readonly overlay_separate_vectors: (a: number, b: number) => number;
8259
readonly __wbindgen_malloc: (a: number, b: number) => number;
8360
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
8461
readonly __wbindgen_exn_store: (a: number) => void;
@@ -89,18 +66,18 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
8966
* Instantiates the given `module`, which can either be bytes or
9067
* a precompiled `WebAssembly.Module`.
9168
*
92-
* @param {SyncInitInput} module
69+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
9370
*
9471
* @returns {InitOutput}
9572
*/
96-
export function initSync(module: SyncInitInput): InitOutput;
73+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
9774

9875
/**
9976
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
10077
* for everything else, calls `WebAssembly.instantiate` directly.
10178
*
102-
* @param {InitInput | Promise<InitInput>} module_or_path
79+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
10380
*
10481
* @returns {Promise<InitOutput>}
10582
*/
106-
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
83+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;

0 commit comments

Comments
 (0)