make sure all coincident points from are identical

This commit is contained in:
Val Erastov 2018-09-27 23:16:50 -07:00
parent c7dc3c327d
commit 311511820b
3 changed files with 96 additions and 5 deletions

40
modules/gems/joints.js Normal file
View file

@ -0,0 +1,40 @@
export default class Joints {
constructor() {
this.map = new Map();
}
connect(a, b) {
let tuple = this.map.get(a);
if (!tuple) {
tuple = this.map.get(b);
if (!tuple) {
tuple = {
master: a,
linked: new Set()
};
this.map.set(b, tuple);
}
this.map.set(a, tuple);
}
tuple.linked.add(a);
tuple.linked.add(b);
}
connected(a, b) {
let set = this.map.get(a);
if (!set) {
return false;
}
return set.has(b);
}
master(node) {
let tuple = this.map.get(node);
if (!tuple) {
return node;
}
return tuple.master;
}
}

View file

@ -5,6 +5,7 @@ import {Point} from '../../brep/geom/point'
import {LUT} from '../../math/bezier-cubic'
import {distanceAB, isCCW, makeAngle0_360} from '../../math/math'
import {normalizeCurveEnds} from '../../brep/geom/impl/nurbs-ext';
import Vector from '../../../../modules/math/vector';
const RESOLUTION = 20;
@ -120,7 +121,8 @@ export class Arc extends SketchPrimitive {
const yAxis = pointAtAngle(startAngle + Math.PI * 0.5);
let arc = new verb.geom.Arc(_3dtr(this.c).data(), xAxis.data(), yAxis.data(), distanceAB(this.c, this.a), 0, Math.abs(angle));
return arc;
return adjustEnds(arc, _3dtr(this.a), _3dtr(this.b))
}
}
@ -181,7 +183,18 @@ export class EllipticalArc extends SketchPrimitive {
points.push(bo);
return points;
}
toVerbNurbs(plane, _3dtr) {
const xAxis = this.ep2.minus(this.ep1)._multiply(0.5);
const yAxis = new Vector(xAxis.y, xAxis.x)._normalize()._multiply(this.r) ;
const center = this.ep1.plus(xAxis);
const startAngle = makeAngle0_360(Math.atan2(this.a.y - center.y, this.a.x - center.x));
const endAngle = makeAngle0_360(Math.atan2(this.b.y - center.y, this.b.x - center.x));
let arc = new verb.geom.EllipseArc(_3dtr(center).data(), _3dtr(xAxis).data(), _3dtr(yAxis).data(), startAngle, endAngle);
return adjustEnds(arc, _3dtr(this.a), _3dtr(this.b))
}
}
export class Circle extends SketchPrimitive {
@ -329,3 +342,18 @@ class CompositeCurve {
}
}
function adjustEnds(arc, a, b) {
let data = arc.asNurbs();
function setHomoPoint(homoPoint, vector) {
homoPoint[0] = vector.x * homoPoint[3];
homoPoint[1] = vector.y * homoPoint[3];
homoPoint[2] = vector.z * homoPoint[3];
}
setHomoPoint(data.controlPoints[0], a);
setHomoPoint(data.controlPoints[data.controlPoints.length - 1], b);
return new verb.geom.NurbsCurve(data);
}

View file

@ -4,6 +4,8 @@ import Vector from 'math/vector';
import {Graph} from '../../math/graph'
import * as math from '../../math/math'
import {HashTable} from '../../utils/hashmap'
import {Constraints} from '../../sketcher/parametric';
import Joints from '../../../../modules/gems/joints';
class SketchGeom {
@ -45,6 +47,31 @@ export function ReadSketch(sketch, sketchId, readConstructionSegments) {
return sketchId + "/" + obj.id;
}
const out = new SketchGeom();
let coiJoints = new Joints();
if (sketch.constraints !== undefined) {
for (let i = 0; i < sketch.constraints.length; ++i) {
let c = sketch.constraints[i];
let name = c[0];
let ps = c[1];
if (name === 'coi') {
coiJoints.connect(ps[0], ps[1]);
}
}
}
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);
pointsById.set(pointId, point);
}
return point;
}
if (sketch.layers !== undefined) {
for (let layer of sketch.layers) {
const isConstructionLayer = layer.name === "_construction_";
@ -89,10 +116,6 @@ export function ReadSketch(sketch, sketchId, readConstructionSegments) {
return out;
}
export function ReadSketchPoint(arr) {
return new Vector(readSketchFloat(arr[1][1]), readSketchFloat(arr[2][1]), 0)
}
export function FetchContours(geom) {
const contours = findClosedContours(geom.connections);
for (let loop of geom.loops) {