@eturnity/eturnity_maths
Advanced tools
Comparing version 7.42.1-qa-elisee-7.45.1 to 7.42.1-qa-elisee-7.45.2
{ | ||
"name": "@eturnity/eturnity_maths", | ||
"version": "7.42.1-qa-elisee-7.45.1", | ||
"version": "7.42.1-qa-elisee-7.45.2", | ||
"author": "Eturnity Team", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,2 +5,3 @@ import { | ||
isSamePoint2D, | ||
calcPolygonArea, | ||
} from './geometry' | ||
@@ -12,2 +13,4 @@ import { | ||
getOutlineList, | ||
getEdgeIntersections, | ||
getEdgeListV2, | ||
} from './splitMergePolygons' | ||
@@ -90,3 +93,16 @@ | ||
} | ||
function generateEdges2DFromOutlines(outlines) { | ||
return outlines | ||
.map((outline, outlineIndex) => | ||
outline.map((currentPoint, index) => { | ||
const nextIndex = (index + 1) % outline.length | ||
const nextPoint = outline[nextIndex] | ||
return { | ||
belongsTo: [{ polygonId: outlineIndex }], | ||
outline: [currentPoint, nextPoint], | ||
} | ||
}) | ||
) | ||
.flat() | ||
} | ||
export function logicOperationOnPolygons( | ||
@@ -97,38 +113,9 @@ outline1, | ||
) { | ||
const fig1 = outline1.map((p) => { | ||
return { x: p.x, y: p.y, z: p.z } | ||
}) | ||
fig1.push(fig1[0]) | ||
const fig2 = outline2.map((p) => { | ||
return { x: p.x, y: p.y, z: p.z } | ||
}) | ||
//nodeList: | ||
let dirtyNodeList = [] | ||
fig1.forEach((p) => { | ||
dirtyNodeList.push(p) | ||
}) | ||
fig2.forEach((p) => { | ||
dirtyNodeList.push(p) | ||
}) | ||
//edgeList (just in term of indexes) | ||
const edges = fig2.map((p, index) => { | ||
return { outline: [p, fig2[(index + 1) % fig2.length]] } | ||
}) | ||
let intersections = getIntersections({ outline: fig1 }, edges) | ||
//2. gather all nodes+intersection in a list[[x,y],[x,y]] | ||
const nodeList = getNodeList(intersections, edges, { outline: fig1 }) | ||
//3. generate all edges not cut, those cut and those from construction polyline | ||
const edgeList = getEdgeList( | ||
nodeList, | ||
intersections, | ||
edges, | ||
{ outline: fig1 }, | ||
1 | ||
) | ||
//4. run planar-face-discovery to get all cycles and rebuild our polygons | ||
const edges = generateEdges2DFromOutlines([outline1, outline2]) | ||
const intersections = getEdgeIntersections(edges) | ||
const nodeList = getNodeList(intersections, edges) | ||
const edgeList = getEdgeListV2(nodeList, intersections, edges) | ||
try { | ||
const outlineList = getOutlineList(nodeList, edgeList) | ||
return filterPolygons(outlineList, fig1, fig2, mode) | ||
return filterPolygons(outlineList, outline1, outline2, mode) | ||
} catch (err) { | ||
@@ -145,3 +132,3 @@ console.error('error with getOutlineList', nodeList, edgeList, err) | ||
let point | ||
const bigPolygons = removeSmallPolygons(polygons, 0.0001) | ||
const bigPolygons = removeSmallPolygons(polygons, 0.001) | ||
for (var i = 0; i < bigPolygons.length; i++) { | ||
@@ -567,3 +554,9 @@ point = getPointInsideOutline( | ||
for (var i = 0; i < polygons.length; i++) { | ||
if (polygonArea(polygons[i]) >= minSize) { | ||
if ( | ||
calcPolygonArea( | ||
polygons[i].map((p) => { | ||
return { ...p, z: 0 } | ||
}) | ||
) >= minSize | ||
) { | ||
big.push(polygons[i]) | ||
@@ -570,0 +563,0 @@ } |
@@ -10,3 +10,3 @@ import { PlanarFaceTree } from 'planar-face-discovery' | ||
import { | ||
isAlmostSamePoint2D, | ||
isSamePoint2D, | ||
getPointOnLine, | ||
@@ -24,3 +24,3 @@ getDistanceBetweenPoints, | ||
import { Polygon } from './objects/Polygon' | ||
import { defaultBaseHeight, mmTolerance } from './config' | ||
import { defaultBaseHeight } from './config' | ||
import { generateEdges2D } from './objects/derivedState/nodesEdgesCreation' | ||
@@ -48,3 +48,3 @@ import { Point, updateComputedGeometryPolygon } from './objects' | ||
const nodeFound = nodeList.find((n) => { | ||
return n && isAlmostSamePoint2D(n, node, mmTolerance) | ||
return n && isSamePoint2D(n, node) | ||
}) | ||
@@ -123,3 +123,3 @@ if (!nodeFound) { | ||
const result = intersections.filter((n) => | ||
isAlmostSamePoint2D(point, n.point, mmTolerance) | ||
isSamePoint2D(point, n.point) | ||
) | ||
@@ -197,3 +197,3 @@ if (result.length) { | ||
) | ||
if (Math.abs(edge.outline[0].z - edge.outline[1].z) < mmTolerance) { | ||
if (Math.abs(edge.outline[0].z - edge.outline[1].z) < 1e-6) { | ||
// edge is flat horizontally, create a flat polygon to project to | ||
@@ -442,3 +442,3 @@ const flatOutline = parentPolygons[0].outline.map((point) => { | ||
const node = nodeList.find((n) => { | ||
return isAlmostSamePoint2D(p, n, mmTolerance) | ||
return isSamePoint2D(p, n) | ||
}) | ||
@@ -451,14 +451,6 @@ if (!node) { | ||
const polylineStart = nodeList.find((p) => { | ||
return isAlmostSamePoint2D( | ||
p, | ||
constructionPolyline.outline[0], | ||
mmTolerance | ||
) | ||
return isSamePoint2D(p, constructionPolyline.outline[0]) | ||
}) | ||
const polylineEnd = nodeList.find((p) => | ||
isAlmostSamePoint2D( | ||
p, | ||
constructionPolyline.outline[polylineLength - 1], | ||
mmTolerance | ||
) | ||
isSamePoint2D(p, constructionPolyline.outline[polylineLength - 1]) | ||
) | ||
@@ -476,7 +468,7 @@ constructionPolyline.outline.forEach((p, index) => { | ||
intersections.forEach((inter) => { | ||
const edge = edges[inter.edgeIndex] | ||
const edge = edges[inter.edge_index_1] | ||
if (edge) { | ||
inter.point.z = | ||
edge.outline[0].z + | ||
inter.edgeParam * (edge.outline[1].z - edge.outline[0].z) | ||
inter.edge_param_1 * (edge.outline[1].z - edge.outline[0].z) | ||
} | ||
@@ -490,3 +482,3 @@ nodeList.push(inter.point) | ||
const newNode = nodeListClean.find((n) => { | ||
return n && isAlmostSamePoint2D(n, node, mmTolerance) | ||
return n && isSamePoint2D(n, node) | ||
}) | ||
@@ -505,6 +497,6 @@ if (!newNode) { | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[0], n, mmTolerance) | ||
isSamePoint2D(edges[index].outline[0], n) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[1], n, mmTolerance) | ||
isSamePoint2D(edges[index].outline[1], n) | ||
) | ||
@@ -575,6 +567,6 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[0], n, mmTolerance) | ||
isSamePoint2D(edges[index].outline[0], n) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[1], n, mmTolerance) | ||
isSamePoint2D(edges[index].outline[1], n) | ||
) | ||
@@ -587,10 +579,6 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(constructionPolyline.outline[index], n, mmTolerance) | ||
isSamePoint2D(constructionPolyline.outline[index], n) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
constructionPolyline.outline[(index + 1) % length], | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(constructionPolyline.outline[(index + 1) % length], n) | ||
) | ||
@@ -603,10 +591,6 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
edges[intersectionOnEdge[0].edgeIndex].outline[0], | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(edges[intersectionOnEdge[0].edgeIndex].outline[0], n) | ||
) | ||
const node_1_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[0].point, n, mmTolerance) | ||
isSamePoint2D(intersectionOnEdge[0].point, n) | ||
) | ||
@@ -617,10 +601,6 @@ edgeList.push([node_0_index_start, node_1_index_start]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[k].point, n, mmTolerance) | ||
isSamePoint2D(intersectionOnEdge[k].point, n) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
intersectionOnEdge[(k + 1) % length].point, | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(intersectionOnEdge[(k + 1) % length].point, n) | ||
) | ||
@@ -631,10 +611,6 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index_end = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[length - 1].point, n, mmTolerance) | ||
isSamePoint2D(intersectionOnEdge[length - 1].point, n) | ||
) | ||
const node_1_index_end = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
edges[intersectionOnEdge[0].edgeIndex].outline[1], | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(edges[intersectionOnEdge[0].edgeIndex].outline[1], n) | ||
) | ||
@@ -648,10 +624,9 @@ edgeList.push([node_0_index_end, node_1_index_end]) | ||
const node_0_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
isSamePoint2D( | ||
constructionPolyline.outline[intersectionOnPolyline[0].polylineIndex], | ||
n, | ||
mmTolerance | ||
n | ||
) | ||
) | ||
const node_1_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnPolyline[0].point, n, mmTolerance) | ||
isSamePoint2D(intersectionOnPolyline[0].point, n) | ||
) | ||
@@ -662,10 +637,6 @@ edgeList.push([node_0_index_start, node_1_index_start]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnPolyline[k].point, n, mmTolerance) | ||
isSamePoint2D(intersectionOnPolyline[k].point, n) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
intersectionOnPolyline[(k + 1) % length].point, | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(intersectionOnPolyline[(k + 1) % length].point, n) | ||
) | ||
@@ -676,15 +647,10 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index_end = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
intersectionOnPolyline[length - 1].point, | ||
n, | ||
mmTolerance | ||
) | ||
isSamePoint2D(intersectionOnPolyline[length - 1].point, n) | ||
) | ||
const node_1_index_end = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D( | ||
isSamePoint2D( | ||
constructionPolyline.outline[ | ||
(intersectionOnPolyline[0].polylineIndex + 1) % lengthPolyline | ||
], | ||
n, | ||
mmTolerance | ||
n | ||
) | ||
@@ -715,3 +681,3 @@ ) | ||
*/ | ||
function getEdgeListV2(nodes, intersections, edges) { | ||
export function getEdgeListV2(nodes, intersections, edges) { | ||
const edgeList = [] | ||
@@ -745,8 +711,4 @@ const groupedIntersections = {} | ||
edgeList.push([ | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(edge.outline[0], n, mmTolerance) | ||
), | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(edge.outline[1], n, mmTolerance) | ||
), | ||
nodes.findIndex((n) => isSamePoint2D(edge.outline[0], n)), | ||
nodes.findIndex((n) => isSamePoint2D(edge.outline[1], n)), | ||
]) | ||
@@ -763,8 +725,4 @@ } else { | ||
edgeList.push([ | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(tempNodes[i], n, mmTolerance) | ||
), | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(tempNodes[i + 1], n, mmTolerance) | ||
), | ||
nodes.findIndex((n) => isSamePoint2D(tempNodes[i], n)), | ||
nodes.findIndex((n) => isSamePoint2D(tempNodes[i + 1], n)), | ||
]) | ||
@@ -829,2 +787,3 @@ } | ||
} | ||
let outlines = cycles | ||
@@ -874,4 +833,4 @@ .map(({ cycle, children }) => { | ||
const CD = vectorLength(v) | ||
if (AB < mmTolerance && CD < mmTolerance) { | ||
if (getDistanceBetweenPoints(A, C) < mmTolerance * 2) { | ||
if (AB < 1e-6 && CD < 1e-6) { | ||
if (getDistanceBetweenPoints(A, C) < 1e-6 * 2) { | ||
return [ | ||
@@ -888,3 +847,3 @@ { | ||
P = getPointOnLine(A, C, D) | ||
if (getDistanceBetweenPoints(P, A) < mmTolerance) { | ||
if (getDistanceBetweenPoints(P, A) < 1e-6) { | ||
j = vectorLength(substractVector(C, A)) / CD | ||
@@ -902,3 +861,3 @@ return [ | ||
M = getPointOnLine(C, A, B) | ||
if (getDistanceBetweenPoints(M, C) < mmTolerance) { | ||
if (getDistanceBetweenPoints(M, C) < 1e-6) { | ||
h = vectorLength(substractVector(C, A)) / AB | ||
@@ -914,3 +873,3 @@ return [ | ||
} | ||
if (Math.abs(denom_u) / (AB * CD) < 0.01) { | ||
if (Math.abs(denom_u) / (AB * CD) < 1e-6) { | ||
//u,v parallel | ||
@@ -922,4 +881,4 @@ //let's check if they are close | ||
if ( | ||
getDistanceBetweenPoints(A, P) < mmTolerance || | ||
getDistanceBetweenPoints(B, M) < mmTolerance | ||
getDistanceBetweenPoints(A, P) < 1e-6 || | ||
getDistanceBetweenPoints(B, M) < 1e-6 | ||
) { | ||
@@ -926,0 +885,0 @@ // AB and CD are colinear |
198022
6659