mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-29 03:44:51 +01:00
merge close vectors when reading sketch
This commit is contained in:
parent
9d58d6cceb
commit
73782cc7bf
3 changed files with 39 additions and 3 deletions
35
modules/math/vectorFactory.js
Normal file
35
modules/math/vectorFactory.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import {veqXYZ} from '../../web/app/brep/geom/tolerance';
|
||||
import Vector from './vector';
|
||||
|
||||
export default class VectorFactory {
|
||||
|
||||
constructor(tolerance) {
|
||||
this.vectors = [];
|
||||
}
|
||||
|
||||
addVertices(vertices) {
|
||||
for (let v of vertices) {
|
||||
this.vectors.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
find(x, y, z) {
|
||||
for (let v of this.vectors) {
|
||||
if (veqXYZ(v.x, v.y, v.z, x, y, z)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
create(x, y, z, onExistent) {
|
||||
let vector = this.find(x, y, z);
|
||||
if (vector === null) {
|
||||
vector = new Vector(x, y, z);
|
||||
this.vectors.push(vector);
|
||||
} else if (onExistent !== undefined) {
|
||||
return onExistent(vector);
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import {HashTable} from '../../utils/hashmap'
|
|||
import {Constraints} from '../../sketcher/parametric';
|
||||
import Joints from '../../../../modules/gems/joints';
|
||||
import sketchObjectGlobalId from './sketchObjectGlobalId';
|
||||
import VectorFactory from '../../../../modules/math/vectorFactory';
|
||||
|
||||
class SketchGeom {
|
||||
|
||||
|
|
@ -59,14 +60,14 @@ export function ReadSketch(sketch, sketchId, readConstructionSegments) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let vectorFactory = new VectorFactory();
|
||||
let pointsById = new Map();
|
||||
function ReadSketchPoint(arr) {
|
||||
let pointId = arr[0];
|
||||
pointId = coiJoints.master(pointId);
|
||||
let point = pointsById.get(pointId);
|
||||
if (!point) {
|
||||
point = new Vector(readSketchFloat(arr[1][1]), readSketchFloat(arr[2][1]), 0);
|
||||
point = vectorFactory.create(readSketchFloat(arr[1][1]), readSketchFloat(arr[2][1]), 0);
|
||||
pointsById.set(pointId, point);
|
||||
}
|
||||
return point;
|
||||
|
|
@ -81,7 +82,7 @@ export function ReadSketch(sketch, sketchId, readConstructionSegments) {
|
|||
// if (isConstructionObject && obj._class !== 'TCAD.TWO.Segment') continue;
|
||||
|
||||
if (obj.edge !== undefined) continue;
|
||||
if (!!obj.aux) continue;
|
||||
if (!!obj.aux && obj.role !== 'virtual') continue;
|
||||
if (obj._class === 'TCAD.TWO.Segment') {
|
||||
const segA = ReadSketchPoint(obj.points[0]);
|
||||
const segB = ReadSketchPoint(obj.points[1]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue