mirror of
https://github.com/xibyte/jsketcher
synced 2026-01-16 13:12:01 +01:00
organizing brep package - add some typesafety
This commit is contained in:
parent
590cd37878
commit
63bbdf564b
5 changed files with 46 additions and 23 deletions
|
|
@ -1,7 +1,18 @@
|
|||
import {Loop} from "brep/topo/loop";
|
||||
import {Shell} from "brep/topo/shell";
|
||||
import {Vec3} from "math/vec";
|
||||
import {Vertex} from "brep/topo/vertex";
|
||||
|
||||
export function toLoops(shell, presicion) {
|
||||
export interface BREPLoopsFormat {
|
||||
format: 'LOOPS';
|
||||
vertices: Vec3[];
|
||||
faces: number[][];
|
||||
|
||||
const fl = presicion || (v => v);
|
||||
}
|
||||
|
||||
export function toLoops(shell: Shell, precisionFn: (number) => number): BREPLoopsFormat {
|
||||
|
||||
const fl = precisionFn || (v => v);
|
||||
|
||||
const vertices = [];
|
||||
for (let v of shell.vertices) {
|
||||
|
|
@ -29,7 +40,7 @@ export function toLoops(shell, presicion) {
|
|||
};
|
||||
}
|
||||
|
||||
function sortByXYZ(vertices) {
|
||||
function sortByXYZ(vertices: Vertex[]) {
|
||||
vertices.sort((v1, v2) => {
|
||||
let c = v1.point.x - v2.point.x;
|
||||
if (c === 0) {
|
||||
|
|
@ -4,8 +4,9 @@ import PIP from '../../../web/app/cad/tess/pip';
|
|||
import {veq} from "geom/tolerance";
|
||||
import {isOnPositiveHalfPlaneFromVec} from "../operations/boolean";
|
||||
import {BrepSurface} from "geom/surfaces/brepSurface";
|
||||
import {Shell} from "./shell";
|
||||
import {edgesGenerator, Shell} from "./shell";
|
||||
import {ProductionInfo} from "../../../web/app/cad/craft/engine/productionInfo";
|
||||
import {HalfEdge} from "brep/topo/edge";
|
||||
|
||||
declare module './face' {
|
||||
|
||||
|
|
@ -35,14 +36,20 @@ export class Face extends TopoObject {
|
|||
innerLoops: Loop[];
|
||||
private __2d: any;
|
||||
|
||||
loops = {
|
||||
[Symbol.iterator]: () => loopsGenerator(this)
|
||||
};
|
||||
edges = {
|
||||
[Symbol.iterator]: () => halfEdgesGenerator(this)
|
||||
};
|
||||
|
||||
|
||||
constructor(surface: BrepSurface) {
|
||||
super();
|
||||
this.surface = surface;
|
||||
this.shell = null;
|
||||
this.outerLoop = new Loop(this);
|
||||
this.innerLoops = [];
|
||||
this.defineIterable('loops', () => loopsGenerator(this));
|
||||
this.defineIterable('edges', () => halfEdgesGenerator(this));
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
|
|
@ -153,7 +160,7 @@ export class Face extends TopoObject {
|
|||
}
|
||||
}
|
||||
|
||||
export function* loopsGenerator(face) {
|
||||
export function* loopsGenerator(face): Generator<Loop> {
|
||||
if (face.outerLoop !== null) {
|
||||
yield face.outerLoop;
|
||||
}
|
||||
|
|
@ -162,7 +169,7 @@ export function* loopsGenerator(face) {
|
|||
}
|
||||
}
|
||||
|
||||
export function* halfEdgesGenerator(face) {
|
||||
export function* halfEdgesGenerator(face): Generator<HalfEdge> {
|
||||
for (let loop of face.loops) {
|
||||
for (let halfEdge of loop.halfEdges) {
|
||||
yield halfEdge;
|
||||
|
|
|
|||
|
|
@ -3,19 +3,21 @@ import {Face} from "./face";
|
|||
import {BrepSurface} from "geom/surfaces/brepSurface";
|
||||
import {HalfEdge} from "./edge";
|
||||
import {findLowestLeftPoint} from "geom/euclidean";
|
||||
import {Vertex} from "brep/topo/vertex";
|
||||
|
||||
export class Loop extends TopoObject {
|
||||
|
||||
face: Face;
|
||||
halfEdges: HalfEdge[];
|
||||
encloses: any;
|
||||
|
||||
encloses = {
|
||||
[Symbol.iterator]: () => enclosesGenerator(this.halfEdges)
|
||||
};
|
||||
|
||||
constructor(face: Face) {
|
||||
super();
|
||||
this.face = face;
|
||||
this.halfEdges = [];
|
||||
this.encloses = undefined;
|
||||
this.defineIterable('encloses', () => enclosesGenerator(this.halfEdges));
|
||||
}
|
||||
|
||||
isCCW(surface: BrepSurface) {
|
||||
|
|
@ -68,7 +70,7 @@ export class Loop extends TopoObject {
|
|||
};
|
||||
}
|
||||
|
||||
export function* enclosesGenerator(halfEdges) {
|
||||
export function* enclosesGenerator(halfEdges): Generator<[HalfEdge, HalfEdge, Vertex]> {
|
||||
let length = halfEdges.length;
|
||||
for (let i = 0; i < halfEdges.length; i++) {
|
||||
let j = (i + 1) % length;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,27 @@
|
|||
import {TopoObject} from './topo-object'
|
||||
import {Face} from "./face";
|
||||
import {Loop} from "./loop";
|
||||
import {Edge} from "./edge";
|
||||
import {Vertex} from "brep/topo/vertex";
|
||||
import {Edge} from "brep/topo/edge";
|
||||
|
||||
|
||||
export class Shell extends TopoObject {
|
||||
|
||||
faces: Face[];
|
||||
edges: Edge[];
|
||||
|
||||
vertices = {
|
||||
[Symbol.iterator]: () => verticesGenerator(this)
|
||||
};
|
||||
|
||||
edges = {
|
||||
[Symbol.iterator]: () => edgesGenerator(this.faces)
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.faces = [];
|
||||
this.defineIterable('vertices', () => verticesGenerator(this));
|
||||
this.defineIterable('edges', () => edgesGenerator(this.faces))
|
||||
}
|
||||
|
||||
|
||||
clone(): Shell {
|
||||
let edgeClones = new Map();
|
||||
for (let e of this.edges) {
|
||||
|
|
@ -48,7 +55,7 @@ export class Shell extends TopoObject {
|
|||
}
|
||||
}
|
||||
|
||||
export function* verticesGenerator(shell: Shell) {
|
||||
export function* verticesGenerator(shell: Shell): Generator<Vertex> {
|
||||
const seen = new Set();
|
||||
for (let face of shell.faces) {
|
||||
for (let edge of face.edges) {
|
||||
|
|
@ -60,7 +67,7 @@ export function* verticesGenerator(shell: Shell) {
|
|||
}
|
||||
}
|
||||
|
||||
export function* edgesGenerator(faces: Face[]) {
|
||||
export function* edgesGenerator(faces: Face[]): Generator<Edge> {
|
||||
const visited = new Set();
|
||||
for (let face of faces) {
|
||||
for (let halfEdge of face.edges) {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ export class TopoObject {
|
|||
});
|
||||
}
|
||||
|
||||
defineIterable(name, iteratorFactory) {
|
||||
this[name] = {};
|
||||
this[name][Symbol.iterator] = iteratorFactory;
|
||||
}
|
||||
}
|
||||
|
||||
export type OperationTemporaryData = any;
|
||||
|
|
|
|||
Loading…
Reference in a new issue