Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
NailxSharipov committed Nov 11, 2024
1 parent 61a5b52 commit a0d92c3
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 221 deletions.
10 changes: 3 additions & 7 deletions examples/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
</style>
<script type="module">
import init, { Overlay, OverlayGraph, OverlayRule, ShapeType, FillRule} from './ishape/ishape_wasm.js';
import init, { Overlay, OverlayRule, FillRule} from './ishape/ishape_wasm.js';

init();

Expand All @@ -34,12 +34,8 @@
const subj = JSON.parse(subjInput);
const clip = JSON.parse(clipInput);

const overlay = new Overlay();
overlay.add_paths(subj, ShapeType.Subject);
overlay.add_paths(clip, ShapeType.Clip);

const graph = overlay.build_graph(FillRule.EvenOdd);
const union = graph.extract_shapes(OverlayRule.Union);
const overlay = Overlay.new_with_subj_and_clip(subj, clip);
const union = overlay.overlay(OverlayRule.Union, FillRule.EvenOdd);

const resultText = JSON.stringify(union, null, 2);
document.getElementById('result').innerText = `Result:\n${resultText}`;
Expand Down
63 changes: 20 additions & 43 deletions examples/html/ishape/ishape_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,48 @@ export enum OverlayRule {
Intersect = 2,
Union = 3,
Difference = 4,
Xor = 5,
InverseDifference = 5,
Xor = 6,
}
/**
*/
export enum FillRule {
EvenOdd = 0,
NonZero = 1,
Positive = 2,
Negative = 3,
}
/**
*/
export class Overlay {
free(): void;
/**
* @param {any} subj_js
* @param {any} clip_js
* @returns {Overlay | undefined}
*/
constructor();
/**
* @param {any} js_path
* @param {ShapeType} shape_type
*/
add_path(js_path: any, shape_type: ShapeType): void;
/**
* @param {any} js_shape
* @param {ShapeType} shape_type
*/
add_paths(js_shape: any, shape_type: ShapeType): void;
/**
* @param {FillRule} fill_rule
* @returns {OverlayGraph}
*/
build_graph(fill_rule: FillRule): OverlayGraph;
}
/**
*/
export class OverlayGraph {
free(): void;
/**
* @param {OverlayRule} overlay_rule
* @returns {any}
*/
extract_shapes(overlay_rule: OverlayRule): any;
static new_with_subj_and_clip(subj_js: any, clip_js: any): Overlay | undefined;
/**
* @param {OverlayRule} overlay_rule
* @param {number} min_area_f64
* @param {FillRule} fill_rule
* @returns {any}
*/
extract_shapes_min_area(overlay_rule: OverlayRule, min_area_f64: number): any;
overlay(overlay_rule: OverlayRule, fill_rule: FillRule): any;
/**
* @param {FillRule} fill_rule
* @returns {any}
*/
links(): any;
separate_vectors(fill_rule: FillRule): any;
}

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

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_overlay_free: (a: number) => void;
readonly overlay_create: () => number;
readonly overlay_add_path: (a: number, b: number, c: number) => void;
readonly overlay_add_paths: (a: number, b: number, c: number) => void;
readonly overlay_build_graph: (a: number, b: number) => number;
readonly __wbg_overlaygraph_free: (a: number) => void;
readonly overlaygraph_extract_shapes: (a: number, b: number) => number;
readonly overlaygraph_extract_shapes_min_area: (a: number, b: number, c: number) => number;
readonly overlaygraph_links: (a: number) => number;
readonly __wbg_overlay_free: (a: number, b: number) => void;
readonly overlay_new_with_subj_and_clip: (a: number, b: number) => number;
readonly overlay_overlay: (a: number, b: number, c: number) => number;
readonly overlay_separate_vectors: (a: number, b: number) => number;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_exn_store: (a: number) => void;
Expand All @@ -89,18 +66,18 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {SyncInitInput} module
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
*
* @returns {InitOutput}
*/
export function initSync(module: SyncInitInput): InitOutput;
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
Loading

0 comments on commit a0d92c3

Please sign in to comment.