mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
organizing math module - extracting out generic equality methods
This commit is contained in:
parent
8748f401b7
commit
210eed5101
20 changed files with 104 additions and 98 deletions
|
|
@ -4,10 +4,8 @@ import * as vec from 'math/vec';
|
|||
import {perp2d} from 'math/vec';
|
||||
import {eqTol} from "../../web/app/brep/geom/tolerance";
|
||||
import {IDENTITY_BASIS3} from "math/basis";
|
||||
import {distance, distanceSquared3, distanceSquaredAB3, distanceSquaredANegB3} from "math/distance";
|
||||
|
||||
export const TOLERANCE = 1E-6;
|
||||
export const TOLERANCE_SQ = TOLERANCE * TOLERANCE;
|
||||
import {distance} from "math/distance";
|
||||
import {TOLERANCE} from "math/equality";
|
||||
|
||||
|
||||
export function circleFromPoints(p1, p2, p3) {
|
||||
|
|
@ -34,38 +32,6 @@ export function norm2(vec) {
|
|||
return Math.sqrt(sq);
|
||||
}
|
||||
|
||||
export function areEqual(v1, v2, tolerance) {
|
||||
return Math.abs(v1 - v2) < tolerance;
|
||||
}
|
||||
|
||||
export function areVectorsEqual(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquaredAB3(v1, v2), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function areNegVectorsEqual(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquaredANegB3(v1, v2), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function areVectorsEqual3(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquared3(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function vectorsEqual(v1, v2) {
|
||||
return areVectorsEqual(v1, v2, TOLERANCE_SQ);
|
||||
}
|
||||
|
||||
export function equal(v1, v2) {
|
||||
return areEqual(v1, v2, TOLERANCE);
|
||||
}
|
||||
|
||||
export function strictEqual(a, b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
}
|
||||
|
||||
export function strictEqual2D(a, b) {
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
||||
export function rotate(px, py, angle) {
|
||||
return rotateInPlace(px, py, angle, new Vector());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
import {distanceSquared3, distanceSquaredAB3, distanceSquaredANegB3} from "math/distance";
|
||||
|
||||
export const TOLERANCE = 1E-6;
|
||||
export const TOLERANCE_SQ = TOLERANCE * TOLERANCE;
|
||||
|
||||
export function areEqual(v1, v2, tolerance) {
|
||||
return Math.abs(v1 - v2) < tolerance;
|
||||
}
|
||||
|
||||
export function areVectorsEqual(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquaredAB3(v1, v2), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function areNegVectorsEqual(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquaredANegB3(v1, v2), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function areVectorsEqual3(v1, v2, toleranceSQ) {
|
||||
return areEqual(distanceSquared3(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]), 0, toleranceSQ);
|
||||
}
|
||||
|
||||
export function vectorsEqual(v1, v2) {
|
||||
return areVectorsEqual(v1, v2, TOLERANCE_SQ);
|
||||
}
|
||||
|
||||
export function equal(v1, v2) {
|
||||
return areEqual(v1, v2, TOLERANCE);
|
||||
}
|
||||
|
||||
export function strictEqual(a, b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
}
|
||||
|
||||
export function strictEqual2D(a, b) {
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import NurbsCurve from "./nurbsCurve";
|
||||
import {Vec3} from 'math/l3space'
|
||||
import {areEqual} from 'math/commons'
|
||||
|
||||
import {eqSqTol, ueq, veq, veq3, veqNeg} from "../tolerance";
|
||||
import curveIntersect from "../impl/curve/curves-isec";
|
||||
|
|
@ -10,6 +9,7 @@ import Vector from 'math/vector';
|
|||
import cache from "../impl/cache";
|
||||
import {Tessellation1D} from "../../../cad/craft/engine/tessellation";
|
||||
import {Matrix3} from "math/matrix";
|
||||
import {areEqual} from "math/equality";
|
||||
|
||||
export default class BrepCurve {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as vec from "math/vec";
|
||||
import {TOLERANCE, TOLERANCE_SQ} from '../../tolerance';
|
||||
import * as math from 'math/commons'
|
||||
import {fmin_bfgs} from 'math/optim/bfgs';
|
||||
import {areEqual} from "../../../../../../modules/math/equality";
|
||||
|
||||
export default function curveIntersect(curve1, curve2, isecRange1, isecRange2, tesselator) {
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ export default function curveIntersect(curve1, curve2, isecRange1, isecRange2, t
|
|||
p0: point1,
|
||||
p1: point2
|
||||
});
|
||||
if (math.areEqual(u1, l1, TOLERANCE )) {
|
||||
if (areEqual(u1, l1, TOLERANCE )) {
|
||||
i ++;
|
||||
}
|
||||
if (math.areEqual(u2, l2, TOLERANCE )) {
|
||||
if (areEqual(u2, l2, TOLERANCE )) {
|
||||
j ++;
|
||||
}
|
||||
}
|
||||
|
|
@ -85,8 +85,8 @@ function intersectSegs(a1, b1, a2, b2) {
|
|||
let point1 = vec.add(a1, vec.mul(v1, u1));
|
||||
let point2 = vec.add(a2, vec.mul(v2, u2));
|
||||
let p2p = vec.lengthSq(vec.sub(point1, point2));
|
||||
let eq = (a, b) => math.areEqual(a, b, TOLERANCE);
|
||||
if (u1 !== Infinity && u2 !== Infinity && math.areEqual(p2p, 0, TOLERANCE_SQ) &&
|
||||
let eq = (a, b) => areEqual(a, b, TOLERANCE);
|
||||
if (u1 !== Infinity && u2 !== Infinity && areEqual(p2p, 0, TOLERANCE_SQ) &&
|
||||
((u1 >0 && u1 < l1) || eq(u1, 0) || eq(u1, l1)) &&
|
||||
((u2 >0 && u2 < l2) || eq(u2, 0) || eq(u2, l2))
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import * as vec from "math/vec";
|
||||
import * as math from 'math/commons'
|
||||
import {eqEps, TOLERANCE, TOLERANCE_01, TOLERANCE_SQ} from '../tolerance';
|
||||
import {Vec3} from "math/l3space";
|
||||
import {fmin_bfgs} from "math/optim/bfgs";
|
||||
import {areEqual} from "math/equality";
|
||||
|
||||
export interface NurbsCurveData {
|
||||
degree: number,
|
||||
|
|
@ -219,10 +219,10 @@ export function curveIntersect(curve1, curve2) {
|
|||
p0: point1,
|
||||
p1: point2
|
||||
});
|
||||
if (math.areEqual(u1, l1, TOLERANCE )) {
|
||||
if (areEqual(u1, l1, TOLERANCE )) {
|
||||
i ++;
|
||||
}
|
||||
if (math.areEqual(u2, l2, TOLERANCE )) {
|
||||
if (areEqual(u2, l2, TOLERANCE )) {
|
||||
j ++;
|
||||
}
|
||||
}
|
||||
|
|
@ -270,8 +270,8 @@ function intersectSegs(a1, b1, a2, b2) {
|
|||
let point1 = vec.add(a1, vec.mul(v1, u1));
|
||||
let point2 = vec.add(a2, vec.mul(v2, u2));
|
||||
let p2p = vec.lengthSq(vec.sub(point1, point2));
|
||||
let eq = (a, b) => math.areEqual(a, b, TOLERANCE);
|
||||
if (u1 !== Infinity && u2 !== Infinity && math.areEqual(p2p, 0, TOLERANCE_SQ) &&
|
||||
let eq = (a, b) => areEqual(a, b, TOLERANCE);
|
||||
if (u1 !== Infinity && u2 !== Infinity && areEqual(p2p, 0, TOLERANCE_SQ) &&
|
||||
((u1 >0 && u1 < l1) || eq(u1, 0) || eq(u1, l1)) &&
|
||||
((u2 >0 && u2 < l2) || eq(u2, 0) || eq(u2, l2))
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {areEqual, areNegVectorsEqual, areVectorsEqual, areVectorsEqual3} from 'math/commons';
|
||||
import {distanceSquared3} from "math/distance";
|
||||
import {areEqual, areNegVectorsEqual, areVectorsEqual, areVectorsEqual3} from "math/equality";
|
||||
|
||||
export const TOLERANCE = 1e-3;
|
||||
export const TOLERANCE_SQ = TOLERANCE * TOLERANCE;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as math from '../../../modules/math/commons'
|
||||
import {Edge} from './topo/edge'
|
||||
import {equal} from "math/equality";
|
||||
|
||||
export default function({curve, start}) {
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ export default function({curve, start}) {
|
|||
const aTip = curve.closestParam(aE.vertexA.point.data());
|
||||
const bTip = curve.closestParam(bE.vertexB.point.data());
|
||||
|
||||
if (math.equal(aTip, bTip)) {
|
||||
if (equal(aTip, bTip)) {
|
||||
//swap vertex everywhere
|
||||
updateVertex(bE, bE, aE.vertexA);
|
||||
} else if (aTip > bTip) {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import {Loop} from '../topo/loop';
|
|||
import {Shell} from '../topo/shell';
|
||||
import {Vertex} from '../topo/vertex';
|
||||
import {evolveFace} from './evolve-face'
|
||||
import * as math from '../../../../modules/math/commons';
|
||||
import {eqTol, TOLERANCE, ueq, veq, veqNeg} from '../geom/tolerance';
|
||||
import CadError from "../../utils/errors";
|
||||
import {createBoundingSurface} from "../brep-builder";
|
||||
import BREP_DEBUG from '../debug/brep-debug';
|
||||
import {Face} from "../topo/face";
|
||||
import {vectorsEqual} from "../../../../modules/math/equality";
|
||||
|
||||
|
||||
const A = 0, B = 1;
|
||||
|
|
@ -650,8 +650,8 @@ function fixCurveDirection(curve, surface1, surface2, operationType) {
|
|||
function newEdgeDirectionValidityTest(e, curve) {
|
||||
let point = e.halfEdge1.vertexA.point;
|
||||
let tangent = curve.tangentAtPoint(point);
|
||||
assert('tangent of originated curve and first halfEdge should be the same', math.vectorsEqual(tangent, e.halfEdge1.tangent(point)));
|
||||
assert('tangent of originated curve and second halfEdge should be the opposite', math.vectorsEqual(tangent._negate(), e.halfEdge2.tangent(point)));
|
||||
assert('tangent of originated curve and first halfEdge should be the same', vectorsEqual(tangent, e.halfEdge1.tangent(point)));
|
||||
assert('tangent of originated curve and second halfEdge should be the opposite', vectorsEqual(tangent._negate(), e.halfEdge2.tangent(point)));
|
||||
}
|
||||
|
||||
function intersectFaces(shellA, shellB, operationType) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import Vector from "math/vector";
|
||||
import {FaceTouchAlignConstraint} from "../constraints/faceTouchAlign";
|
||||
import {AssemblyDOF, ModificationResponse} from "./assemblyDOF";
|
||||
import {areEqual, clamp, DEG_RAD, lineLineIntersection} from "math/commons";
|
||||
import {clamp, DEG_RAD, lineLineIntersection} from "math/commons";
|
||||
import {ConflictDOF} from "./conflictDOF";
|
||||
import {EdgeAlignConstraint} from "../constraints/edgeAlign";
|
||||
import {PPEEDOF} from "./PPEEDOF";
|
||||
import {EEEEDOF} from "./EEEEDOF";
|
||||
import {Matrix3} from "math/matrix";
|
||||
import {areEqual} from "math/equality";
|
||||
|
||||
const ANGULAR_ALLOWANCE = 10 * DEG_RAD;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ import {eqTol} from "../../../brep/geom/tolerance";
|
|||
import {FaceTouchAlignConstraint} from "../constraints/faceTouchAlign";
|
||||
import {Plane} from './../../../brep/geom/impl/plane';
|
||||
import {ANGULAR_ALLOWANCE, AssemblyDOF, ModificationResponse} from "./assemblyDOF";
|
||||
import {areEqual, clamp, DEG_RAD} from "math/commons";
|
||||
import {clamp, DEG_RAD} from "math/commons";
|
||||
import {ConflictDOF} from "./conflictDOF";
|
||||
import {PPPPDOF} from "./PPPPDOF";
|
||||
import {EdgeAlignConstraint} from "../constraints/edgeAlign";
|
||||
import {Matrix3} from "math/matrix";
|
||||
import {areEqual} from "math/equality";
|
||||
|
||||
export class PPDOF implements AssemblyDOF {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import BBox from '../math/bbox'
|
|||
import * as math from '../../../modules/math/commons'
|
||||
import {MeshSceneSolid} from './scene/wrappers/meshSceneObject'
|
||||
import {Matrix3} from 'math/matrix';
|
||||
import {equal} from 'math/equality';
|
||||
|
||||
export const FACE_COLOR = 0xB0C4DE;
|
||||
|
||||
|
|
@ -243,7 +244,7 @@ export function normalOfCCWSeq(ccwSequence) {
|
|||
for (let i = 2; i < ccwSequence.length; ++i) {
|
||||
let c = ccwSequence[i];
|
||||
let normal = b.minus(a).cross(c.minus(a)).normalize();
|
||||
if (!math.equal(normal.length(), 0)) {
|
||||
if (!equal(normal.length(), 0)) {
|
||||
return normal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as math from '../../../../../modules/math/commons'
|
||||
import {enclose} from '../../../brep/brep-enclose'
|
||||
import {BooleanOperation, combineShells} from '../booleanOperation'
|
||||
import {Matrix3} from 'math/matrix';
|
||||
import {equal} from 'math/equality';
|
||||
|
||||
|
||||
export function Extrude(params, ctx) {
|
||||
|
|
@ -85,7 +85,7 @@ export function getEncloseDetails(params, contours, target, csys, sketchSurface,
|
|||
if (invert) contour.reverse();
|
||||
|
||||
const lidPath = [];
|
||||
let applyPrism = !math.equal(params.prism, 1);
|
||||
let applyPrism = !equal(params.prism, 1);
|
||||
let prismTr = null;
|
||||
if (applyPrism) {
|
||||
prismTr = new Matrix3();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import Vector from 'math/vector';
|
||||
import * as math from '../../../../../modules/math/commons'
|
||||
import {createShared} from '../../cad-utils'
|
||||
import {TriangulatePolygons} from '../../tess/triangulation';
|
||||
import {Matrix3} from "../../../../../modules/math/matrix";
|
||||
import {distanceAB3} from "../../../../../modules/math/distance";
|
||||
import {Matrix3} from "math/matrix";
|
||||
import {distanceAB3} from "math/distance";
|
||||
import {equal} from "math/equality";
|
||||
|
||||
function Group(derivedFrom) {
|
||||
this.polygons = [];
|
||||
|
|
@ -17,10 +17,10 @@ export default function revolve(polygons, axisSegment, angle, resolution) {
|
|||
const polygon = [pOrig[p], pOrig[q]];
|
||||
|
||||
//skip point if they are on the axis of revolving
|
||||
if (!math.equal(0, distanceAB3(pOrig[q], pRot[q]))) {
|
||||
if (!equal(0, distanceAB3(pOrig[q], pRot[q]))) {
|
||||
polygon.push(pRot[q]);
|
||||
}
|
||||
if (!math.equal(0, distanceAB3(pOrig[p], pRot[p]))) {
|
||||
if (!equal(0, distanceAB3(pOrig[p], pRot[p]))) {
|
||||
polygon.push(pRot[p]);
|
||||
}
|
||||
if (polygon.length < 3) {
|
||||
|
|
@ -46,7 +46,7 @@ export default function revolve(polygons, axisSegment, angle, resolution) {
|
|||
const face = csgPolygon(polygon, shared);
|
||||
out.push(face);
|
||||
});
|
||||
if (!math.equal(_360, angle)) {
|
||||
if (!equal(_360, angle)) {
|
||||
if (angle < 0) {
|
||||
let t = lids;
|
||||
lids = polygons;
|
||||
|
|
@ -76,10 +76,10 @@ export function revolveToTriangles(polygons, axisSegment, angle, resolution, tri
|
|||
//add initial polygon
|
||||
let lids = revolveIterator(polygons, axisSegment, angle, resolution, (pOrig, pRot, p, q, r, id, i, length) => {
|
||||
//skip point if they are on the axis of revolving
|
||||
if (!math.equal(0, distanceAB3(pOrig[q], pRot[q]))) {
|
||||
if (!equal(0, distanceAB3(pOrig[q], pRot[q]))) {
|
||||
out.push( [pOrig[p], pOrig[q], pRot[q]] );
|
||||
}
|
||||
if (!math.equal(0, distanceAB3(pOrig[p], pRot[p]))) {
|
||||
if (!equal(0, distanceAB3(pOrig[p], pRot[p]))) {
|
||||
out.push( [ pRot[q], pRot[p], pOrig[p]] );
|
||||
}
|
||||
let last = i === length - 1
|
||||
|
|
@ -137,7 +137,7 @@ export function revolveIterator(polygons, axisSegment, angle, resolution, callba
|
|||
|
||||
|
||||
function addIfNonZero(out, seg) {
|
||||
if (!math.equal(0, distanceAB3(seg[0], seg[1]))) {
|
||||
if (!equal(0, distanceAB3(seg[0], seg[1]))) {
|
||||
out.push(seg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {Mesh} from '../mesh'
|
|||
import revolve from './revolve'
|
||||
import {Triangulate} from '../../tess/triangulation'
|
||||
import {distanceAB3} from "../../../../../modules/math/distance";
|
||||
import {areEqual, equal, strictEqual} from "../../../../../modules/math/equality";
|
||||
|
||||
export function sortPolygons(polygons) {
|
||||
function Loop(polygon) {
|
||||
|
|
@ -139,7 +140,7 @@ function _pointOnLine(p, a, b) {
|
|||
var abLength = ab.length();
|
||||
var apLength = ap.length();
|
||||
|
||||
return apLength > 0 && apLength < abLength && math.areEqual(abLength * apLength, dp, 1E-6);
|
||||
return apLength > 0 && apLength < abLength && areEqual(abLength * apLength, dp, 1E-6);
|
||||
}
|
||||
|
||||
export function polygonsToSegments(polygons) {
|
||||
|
|
@ -179,8 +180,8 @@ export function reconstructSketchBounds(csg, face, strict) {
|
|||
var planePolygons = [];
|
||||
for (var pi = 0; pi < polygons.length; pi++) {
|
||||
var poly = polygons[pi];
|
||||
if (math.equal(poly.plane.normal.dot(plane.normal), 1)) {
|
||||
if (math.equal(plane.w, poly.plane.w) && (!strict || !!poly.shared.__tcad && poly.shared.__tcad.faceId === face.id)) {
|
||||
if (equal(poly.plane.normal.dot(plane.normal), 1)) {
|
||||
if (equal(plane.w, poly.plane.w) && (!strict || !!poly.shared.__tcad && poly.shared.__tcad.faceId === face.id)) {
|
||||
planePolygons.push(poly);
|
||||
}
|
||||
continue;
|
||||
|
|
@ -189,9 +190,9 @@ export function reconstructSketchBounds(csg, face, strict) {
|
|||
for(p = n - 1, q = 0; q < n; p = q ++) {
|
||||
var a = poly.vertices[p];
|
||||
var b = poly.vertices[q];
|
||||
var pointAOnPlane = math.equal(plane.signedDistanceToPoint(a.pos), 0);
|
||||
var pointAOnPlane = equal(plane.signedDistanceToPoint(a.pos), 0);
|
||||
if (!pointAOnPlane) continue;
|
||||
var pointBOnPlane = math.equal(plane.signedDistanceToPoint(b.pos), 0);
|
||||
var pointBOnPlane = equal(plane.signedDistanceToPoint(b.pos), 0);
|
||||
if (pointBOnPlane) {
|
||||
outerEdges.push([a.pos, b.pos, poly]);
|
||||
}
|
||||
|
|
@ -206,12 +207,12 @@ export function reconstructSketchBounds(csg, face, strict) {
|
|||
}
|
||||
|
||||
function pickUpCraftInfo(outline, outerEdges) {
|
||||
var eq = math.strictEqual;
|
||||
var eq = strictEqual;
|
||||
for (var psi1 = 0; psi1 < outline.length; psi1++) {
|
||||
var s1 = outline[psi1];
|
||||
for (var psi2 = 0; psi2 < outerEdges.length; psi2++) {
|
||||
var s2 = outerEdges[psi2];
|
||||
if (math.equal(Math.abs(s1[0].minus(s1[1]).unit().dot(s2[0].minus(s2[1]).unit())), 1) &&
|
||||
if (equal(Math.abs(s1[0].minus(s1[1]).unit().dot(s2[0].minus(s2[1]).unit())), 1) &&
|
||||
(eq(s1[0], s2[0]) || eq(s1[1], s2[1]) || eq(s1[0], s2[1]) || eq(s1[1], s2[0]) ||
|
||||
_pointOnLine(s1[0], s2[0], s2[1]) || _pointOnLine(s1[1], s2[0], s2[1]))) {
|
||||
s1[2] = s2[2];
|
||||
|
|
@ -221,13 +222,13 @@ function pickUpCraftInfo(outline, outerEdges) {
|
|||
}
|
||||
|
||||
function getOutlineByCollision(segments, outerEdges) {
|
||||
var eq = math.strictEqual;
|
||||
var eq = strictEqual;
|
||||
var outline = [];
|
||||
for (var psi1 = 0; psi1 < segments.length; psi1++) {
|
||||
var s1 = segments[psi1];
|
||||
for (var psi2 = 0; psi2 < outerEdges.length; psi2++) {
|
||||
var s2 = outerEdges[psi2];
|
||||
if (math.equal(Math.abs(s1[0].minus(s1[1]).unit().dot(s2[0].minus(s2[1]).unit())), 1) &&
|
||||
if (equal(Math.abs(s1[0].minus(s1[1]).unit().dot(s2[0].minus(s2[1]).unit())), 1) &&
|
||||
(eq(s1[0], s2[0]) || eq(s1[1], s2[1]) || eq(s1[0], s2[1]) || eq(s1[1], s2[0]) ||
|
||||
_pointOnLine(s1[0], s2[0], s2[1]) || _pointOnLine(s1[1], s2[0], s2[1]))) {
|
||||
outline.push(s1);
|
||||
|
|
@ -249,7 +250,7 @@ export function findOutline (planePolygons) {
|
|||
|
||||
function removeSharedEdges(segments) {
|
||||
segments = segments.slice();
|
||||
var eq = math.strictEqual;
|
||||
var eq = strictEqual;
|
||||
for (var psi1 = 0; psi1 < segments.length; psi1++) {
|
||||
var s1 = segments[psi1];
|
||||
if (s1 == null) continue;
|
||||
|
|
@ -311,7 +312,7 @@ function removeTJoints(segments) {
|
|||
}
|
||||
|
||||
var points = pointIndex.getKeys();
|
||||
var eq = math.strictEqual;
|
||||
var eq = strictEqual;
|
||||
for (var pi1 = 0; pi1 < points.length; ++pi1) {
|
||||
var point = points[pi1];
|
||||
var best = null, bestFactor;
|
||||
|
|
@ -341,7 +342,7 @@ function deleteRedundantPoints(path) {
|
|||
var a = path[pi];
|
||||
var b = path[bIdx];
|
||||
var c = path[(pi + 2) % pathLength];
|
||||
var eq = math.areEqual;
|
||||
var eq = areEqual;
|
||||
if (!skipMode) cleanedPath.push(a);
|
||||
skipMode = eq(a.minus(b).unit().dot(b.minus(c).unit()), 1, 1E-9);
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ function deleteRedundantPoints(path) {
|
|||
|
||||
export function segmentsToPaths(segments) {
|
||||
|
||||
var veq = math.strictEqual;
|
||||
var veq = strictEqual;
|
||||
var paths = [];
|
||||
var index = HashTable.forVector3d();
|
||||
var csgIndex = HashTable.forEdge();
|
||||
|
|
@ -469,7 +470,7 @@ function splitTwoSegments(a, b) {
|
|||
// lines are not coplanar
|
||||
return null;
|
||||
}
|
||||
var veq = math.strictEqual;
|
||||
var veq = strictEqual;
|
||||
if (veq(a[0], b[0]) || veq(a[0], b[1]) || veq(a[1], b[0]) || veq(a[1], b[1])) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -494,7 +495,7 @@ function splitTwoSegments(a, b) {
|
|||
}
|
||||
|
||||
function attract(vectors, precision) {
|
||||
var eq = math.areEqual();
|
||||
var eq = areEqual();
|
||||
var dist = distanceAB3;
|
||||
vectors = vectors.slice();
|
||||
for (var i = 0; i < vectors.length; i++) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import {areEqual, circleFromPoints, radiusOfCurvature, TOLERANCE} from '../../../../modules/math/commons';
|
||||
import {circleFromPoints, radiusOfCurvature} from '../../../../modules/math/commons';
|
||||
import * as vec from 'math/vec';
|
||||
import {iteratePath} from '../cad-utils';
|
||||
import NurbsCurve from '../../brep/geom/curves/nurbsCurve';
|
||||
import {veqXYZ} from '../../brep/geom/tolerance';
|
||||
import curveTess, {curveTessParams} from '../../brep/geom/impl/curve/curve-tess';
|
||||
import {distanceAB} from "../../../../modules/math/distance";
|
||||
import {distanceAB} from "math/distance";
|
||||
import {areEqual, TOLERANCE} from "math/equality";
|
||||
|
||||
export function getSketchBoundaries(sceneFace) {
|
||||
const boundary = {lines: [], arcs: [], circles: [], nurbses: []};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import * as sm from './sketchModel'
|
||||
import {Graph} from '../../math/graph'
|
||||
import * as math from '../../../../modules/math/commons'
|
||||
import {HashTable} from '../../utils/hashmap'
|
||||
import Joints from '../../../../modules/gems/joints';
|
||||
import sketchObjectGlobalId from './sketchObjectGlobalId';
|
||||
import VectorFactory from '../../../../modules/math/vectorFactory';
|
||||
import {strictEqual2D} from "../../../../modules/math/equality";
|
||||
|
||||
class SketchGeom {
|
||||
|
||||
|
|
@ -145,10 +145,10 @@ function findClosedContoursFromPairedCurves(segments, result) {
|
|||
const s2 = segments[j];
|
||||
if (s1.isCurve || s2.isCurve) {
|
||||
let paired = false;
|
||||
if (math.strictEqual2D(s1.a, s2.a) && math.strictEqual2D(s1.b, s2.b)) {
|
||||
if (strictEqual2D(s1.a, s2.a) && strictEqual2D(s1.b, s2.b)) {
|
||||
paired = true;
|
||||
s2.invert();
|
||||
} else if (math.strictEqual2D(s1.a, s2.b) && math.strictEqual2D(s1.b, s2.a)) {
|
||||
} else if (strictEqual2D(s1.a, s2.b) && strictEqual2D(s1.b, s2.a)) {
|
||||
paired = true;
|
||||
}
|
||||
if (paired) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {areEqual} from "../../../../modules/math/commons";
|
||||
import {areEqual} from "math/equality";
|
||||
|
||||
export default function(outerLoop, innerLoops, tol) {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import * as math from 'math/commons';
|
||||
import {makeAngle0_360} from 'math/commons';
|
||||
import Vector from 'math/vector';
|
||||
import {SketchObject, SketchObjectSerializationData} from './sketch-object';
|
||||
|
|
@ -6,6 +5,7 @@ import {Param} from "./param";
|
|||
import {AlgNumConstraint, ConstraintDefinitions} from "../constr/ANConstraints";
|
||||
import {EndPoint, SketchPointSerializationData} from "./point";
|
||||
import {distance} from "math/distance";
|
||||
import {areEqual, TOLERANCE} from "math/equality";
|
||||
|
||||
export class Arc extends SketchObject {
|
||||
|
||||
|
|
@ -95,8 +95,8 @@ export class Arc extends SketchObject {
|
|||
let r = this.radiusForDrawing();
|
||||
let startAngle = makeAngle0_360(this.getStartAngle());
|
||||
let endAngle;
|
||||
if (math.areEqual(this.a.x, this.b.x, math.TOLERANCE) &&
|
||||
math.areEqual(this.a.y, this.b.y, math.TOLERANCE)) {
|
||||
if (areEqual(this.a.x, this.b.x, TOLERANCE) &&
|
||||
areEqual(this.a.y, this.b.y, TOLERANCE)) {
|
||||
endAngle = startAngle + 2 * Math.PI;
|
||||
} else {
|
||||
endAngle = makeAngle0_360(this.getEndAngle());
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import {Ellipse} from './ellipse'
|
||||
|
||||
import * as math from '../../../../modules/math/commons';
|
||||
import {swap} from '../../utils/utils'
|
||||
import {EndPoint} from "./point";
|
||||
import {AlgNumConstraint, ConstraintDefinitions} from "../constr/ANConstraints";
|
||||
import {distance} from "../../../../modules/math/distance";
|
||||
import {distance} from "math/distance";
|
||||
import {areEqual, TOLERANCE} from "math/equality";
|
||||
|
||||
export class EllipticalArc extends Ellipse {
|
||||
|
||||
|
|
@ -37,8 +36,8 @@ export class EllipticalArc extends Ellipse {
|
|||
const radiusY = Math.max(this.radiusY, 1e-8);
|
||||
let aAngle = this.drawAngle(this.a);
|
||||
let bAngle;
|
||||
if (math.areEqual(this.a.x, this.b.x, math.TOLERANCE) &&
|
||||
math.areEqual(this.a.y, this.b.y, math.TOLERANCE)) {
|
||||
if (areEqual(this.a.x, this.b.x, TOLERANCE) &&
|
||||
areEqual(this.a.y, this.b.y, TOLERANCE)) {
|
||||
bAngle = aAngle + 2 * Math.PI;
|
||||
} else {
|
||||
bAngle = this.drawAngle(this.b)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {SketchObject, SketchObjectSerializationData} from './sketch-object'
|
||||
import Vector from 'math/vector';
|
||||
import * as math from 'math/commons'
|
||||
import {DEG_RAD, makeAngle0_360} from 'math/commons'
|
||||
import {Param} from "./param";
|
||||
import {AlgNumConstraint, ConstraintDefinitions} from "../constr/ANConstraints";
|
||||
import {EndPoint, SketchPointSerializationData} from "./point";
|
||||
import {distanceAB} from "math/distance";
|
||||
import {TOLERANCE} from "math/equality";
|
||||
|
||||
export class Segment extends SketchObject {
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ export class Segment extends SketchObject {
|
|||
}
|
||||
|
||||
recoverIfNecessary() {
|
||||
if (distanceAB(this.a, this.b) > math.TOLERANCE) {
|
||||
if (distanceAB(this.a, this.b) > TOLERANCE) {
|
||||
return false;
|
||||
} else {
|
||||
const recoverLength = 100;
|
||||
|
|
|
|||
Loading…
Reference in a new issue