edge replace

This commit is contained in:
Val Erastov 2017-12-31 19:14:36 -07:00
parent 6fbc1d4c8e
commit a7050e47a2
2 changed files with 36 additions and 2 deletions

View file

@ -66,8 +66,13 @@ function checkShellForErrors(shell, code) {
}
}
export function BooleanAlgorithm( shellA, shellB, type ) {
let EDGE_REPLACE = [];
export function BooleanAlgorithm( shellA, shellB, type ) {
//fixme
EDGE_REPLACE = [];
BREP_DEBUG.startBooleanSession(shellA, shellB, type);
shellA = prepareWorkingCopy(shellA);
@ -93,6 +98,8 @@ export function BooleanAlgorithm( shellA, shellB, type ) {
intersectFaces(shellA, shellB, type);
replaceEdges();
replaceMergedFaces(facesData, mergedFaces);
for (let faceData of facesData) {
faceData.initGraph();
@ -154,6 +161,12 @@ function removeInvalidLoops(facesData) {
}
}
function replaceEdges() {
for (let {from, to} of EDGE_REPLACE) {
from.replace(to);
}
}
function replaceMergedFaces(facesData, mergedFaces) {
filterInPlace(facesData, ({face}) =>
mergedFaces.find(({originFaces}) => originFaces.indexOf(face) > -1) === undefined
@ -332,6 +345,7 @@ function mergeFaces(facesA, facesB, opType) {
}
if (isSameEdge(testee, edge)) {
//annihilation here
markEdgeToReplace(testee, edge.twin());
invalid.add(testee);
invalid.add(edge);
}
@ -459,6 +473,10 @@ function mergeFaces(facesA, facesB, opType) {
};
}
function markEdgeToReplace(from, to) {
EDGE_REPLACE.push({from, to});
}
export function mergeVertices(shell1, shell2) {
const toSwap = new Map();
for (let v1 of shell1.vertices) {
@ -656,7 +674,6 @@ function newEdgeDirectionValidityTest(e, curve) {
}
function intersectFaces(shellA, shellB, operationType) {
const invert = operationType === TYPE.UNION;
for (let i = 0; i < shellA.faces.length; i++) {
const faceA = shellA.faces[i];
if (DEBUG.FACE_FACE_INTERSECTION) {

View file

@ -78,4 +78,21 @@ class HalfEdge extends TopoObject {
}
return res;
}
replace(he) {
if (this.edge.halfEdge1 === this) {
this.edge.halfEdge1 = he;
} else {
this.edge.halfEdge2 = he;
}
he.edge = this.edge;
he.loop = this.loop;
he.prev = this.prev;
he.prev.next = he;
he.next = this.next;
he.next.prev = he;
}
}