@eturnity/eturnity_maths
Advanced tools
Comparing version 7.42.2-qa-25.0 to 7.42.2-qa-elisee-7.48.0
{ | ||
"name": "@eturnity/eturnity_maths", | ||
"version": "7.42.2-qa-25.0", | ||
"version": "7.42.2-qa-elisee-7.48.0", | ||
"author": "Eturnity Team", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -44,3 +44,7 @@ import { earthRadius } from './config' | ||
const deltaLng = tileLatLng.lng - lng | ||
let { x: x_mm, y: y_mm } = deltaLatLngToDistance(deltaLat, deltaLng, lat) | ||
let { x: x_mm, y: y_mm } = deltaLatLngToDistance( | ||
deltaLat, | ||
deltaLng, | ||
lat + deltaLat / 2 | ||
) | ||
let size = | ||
@@ -47,0 +51,0 @@ ((earthRadius * 2000 * Math.PI) / Math.pow(2.0, zoom)) * |
@@ -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 @@ } |
@@ -173,10 +173,11 @@ import { translate2D, getDegree } from '../geometry' | ||
}) | ||
if (this.layer == 'moduleField') { | ||
this.trimedOutline = this.trimedOutline.map((point) => { | ||
return addVector(point, vectorInMm) | ||
if (this.layer == 'moduleField' && this.data && this.data.modules) { | ||
this.data.modules.forEach((module) => { | ||
module.outline.forEach((p) => { | ||
p[0] += vectorInMm.x | ||
p[1] += vectorInMm.y | ||
}) | ||
}) | ||
} else { | ||
updateComputedGeometryPolygon(this) | ||
} | ||
updateComputedGeometryPolygon(this) | ||
} | ||
@@ -187,5 +188,2 @@ translateOffset(newPositionOffset, center = { x: 0, y: 0 }) { | ||
} | ||
resetOffset() { | ||
this.positionOffset = { x: 0, y: 0, z: 0 } | ||
} | ||
serialize() { | ||
@@ -192,0 +190,0 @@ const baseSerialization = { |
@@ -20,9 +20,10 @@ import { PlanarFaceTree } from 'planar-face-discovery' | ||
} from './geometry' | ||
import { intersectOutlines } from './intersectionPolygon' | ||
import { groupBy } from 'lodash' | ||
import { Polygon } from './objects/Polygon' | ||
import { defaultBaseHeight, mmTolerance } from './config' | ||
import { defaultBaseHeight } from './config' | ||
import { generateEdges2D } from './objects/derivedState/nodesEdgesCreation' | ||
import { Point, updateComputedGeometryPolygon } from './objects' | ||
const FLOAT_PRECISION = 1e-6 | ||
export function mergePolygons(polygonIdsToMerge, edges, layer, polygons) { | ||
@@ -47,3 +48,3 @@ const outsideEdge = edges.filter((e) => e.belongsTo.length == 1) | ||
const nodeFound = nodeList.find((n) => { | ||
return n && isAlmostSamePoint2D(n, node, mmTolerance) | ||
return n && isAlmostSamePoint2D(n, node, FLOAT_PRECISION) | ||
}) | ||
@@ -122,3 +123,3 @@ if (!nodeFound) { | ||
const result = intersections.filter((n) => | ||
isAlmostSamePoint2D(point, n.point, mmTolerance) | ||
isAlmostSamePoint2D(point, n.point, FLOAT_PRECISION) | ||
) | ||
@@ -196,3 +197,5 @@ 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) < FLOAT_PRECISION | ||
) { | ||
// edge is flat horizontally, create a flat polygon to project to | ||
@@ -441,3 +444,3 @@ const flatOutline = parentPolygons[0].outline.map((point) => { | ||
const node = nodeList.find((n) => { | ||
return isAlmostSamePoint2D(p, n, mmTolerance) | ||
return isAlmostSamePoint2D(p, n, FLOAT_PRECISION) | ||
}) | ||
@@ -453,3 +456,3 @@ if (!node) { | ||
constructionPolyline.outline[0], | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -461,3 +464,3 @@ }) | ||
constructionPolyline.outline[polylineLength - 1], | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -476,7 +479,7 @@ ) | ||
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 +493,3 @@ nodeList.push(inter.point) | ||
const newNode = nodeListClean.find((n) => { | ||
return n && isAlmostSamePoint2D(n, node, mmTolerance) | ||
return n && isAlmostSamePoint2D(n, node, FLOAT_PRECISION) | ||
}) | ||
@@ -505,6 +508,6 @@ if (!newNode) { | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[0], n, mmTolerance) | ||
isAlmostSamePoint2D(edges[index].outline[0], n, FLOAT_PRECISION) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[1], n, mmTolerance) | ||
isAlmostSamePoint2D(edges[index].outline[1], n, FLOAT_PRECISION) | ||
) | ||
@@ -575,6 +578,6 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[0], n, mmTolerance) | ||
isAlmostSamePoint2D(edges[index].outline[0], n, FLOAT_PRECISION) | ||
) | ||
const node_1_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(edges[index].outline[1], n, mmTolerance) | ||
isAlmostSamePoint2D(edges[index].outline[1], n, FLOAT_PRECISION) | ||
) | ||
@@ -587,3 +590,7 @@ edgeList.push([node_0_index, node_1_index]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(constructionPolyline.outline[index], n, mmTolerance) | ||
isAlmostSamePoint2D( | ||
constructionPolyline.outline[index], | ||
n, | ||
FLOAT_PRECISION | ||
) | ||
) | ||
@@ -594,3 +601,3 @@ const node_1_index = nodeList.findIndex((n) => | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -607,7 +614,7 @@ ) | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
) | ||
const node_1_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[0].point, n, mmTolerance) | ||
isAlmostSamePoint2D(intersectionOnEdge[0].point, n, FLOAT_PRECISION) | ||
) | ||
@@ -618,3 +625,3 @@ edgeList.push([node_0_index_start, node_1_index_start]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[k].point, n, mmTolerance) | ||
isAlmostSamePoint2D(intersectionOnEdge[k].point, n, FLOAT_PRECISION) | ||
) | ||
@@ -625,3 +632,3 @@ const node_1_index = nodeList.findIndex((n) => | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -633,3 +640,7 @@ ) | ||
const node_0_index_end = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnEdge[length - 1].point, n, mmTolerance) | ||
isAlmostSamePoint2D( | ||
intersectionOnEdge[length - 1].point, | ||
n, | ||
FLOAT_PRECISION | ||
) | ||
) | ||
@@ -640,3 +651,3 @@ const node_1_index_end = nodeList.findIndex((n) => | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -654,7 +665,7 @@ ) | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
) | ||
const node_1_index_start = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnPolyline[0].point, n, mmTolerance) | ||
isAlmostSamePoint2D(intersectionOnPolyline[0].point, n, FLOAT_PRECISION) | ||
) | ||
@@ -665,3 +676,3 @@ edgeList.push([node_0_index_start, node_1_index_start]) | ||
const node_0_index = nodeList.findIndex((n) => | ||
isAlmostSamePoint2D(intersectionOnPolyline[k].point, n, mmTolerance) | ||
isAlmostSamePoint2D(intersectionOnPolyline[k].point, n, FLOAT_PRECISION) | ||
) | ||
@@ -672,3 +683,3 @@ const node_1_index = nodeList.findIndex((n) => | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -683,3 +694,3 @@ ) | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -693,3 +704,3 @@ ) | ||
n, | ||
mmTolerance | ||
FLOAT_PRECISION | ||
) | ||
@@ -720,3 +731,3 @@ ) | ||
*/ | ||
function getEdgeListV2(nodes, intersections, edges) { | ||
export function getEdgeListV2(nodes, intersections, edges) { | ||
const edgeList = [] | ||
@@ -751,6 +762,6 @@ const groupedIntersections = {} | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(edge.outline[0], n, mmTolerance) | ||
isAlmostSamePoint2D(edge.outline[0], n, FLOAT_PRECISION) | ||
), | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(edge.outline[1], n, mmTolerance) | ||
isAlmostSamePoint2D(edge.outline[1], n, FLOAT_PRECISION) | ||
), | ||
@@ -769,6 +780,6 @@ ]) | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(tempNodes[i], n, mmTolerance) | ||
isAlmostSamePoint2D(tempNodes[i], n, FLOAT_PRECISION) | ||
), | ||
nodes.findIndex((n) => | ||
isAlmostSamePoint2D(tempNodes[i + 1], n, mmTolerance) | ||
isAlmostSamePoint2D(tempNodes[i + 1], n, FLOAT_PRECISION) | ||
), | ||
@@ -834,2 +845,3 @@ ]) | ||
} | ||
let outlines = cycles | ||
@@ -879,4 +891,4 @@ .map(({ cycle, children }) => { | ||
const CD = vectorLength(v) | ||
if (AB < mmTolerance && CD < mmTolerance) { | ||
if (getDistanceBetweenPoints(A, C) < mmTolerance * 2) { | ||
if (AB < FLOAT_PRECISION && CD < FLOAT_PRECISION) { | ||
if (getDistanceBetweenPoints(A, C) < FLOAT_PRECISION * 2) { | ||
return [ | ||
@@ -893,3 +905,3 @@ { | ||
P = getPointOnLine(A, C, D) | ||
if (getDistanceBetweenPoints(P, A) < mmTolerance) { | ||
if (getDistanceBetweenPoints(P, A) < FLOAT_PRECISION) { | ||
j = vectorLength(substractVector(C, A)) / CD | ||
@@ -907,3 +919,3 @@ return [ | ||
M = getPointOnLine(C, A, B) | ||
if (getDistanceBetweenPoints(M, C) < mmTolerance) { | ||
if (getDistanceBetweenPoints(M, C) < FLOAT_PRECISION) { | ||
h = vectorLength(substractVector(C, A)) / AB | ||
@@ -919,3 +931,3 @@ return [ | ||
} | ||
if (Math.abs(denom_u) / (AB * CD) < 0.01) { | ||
if (Math.abs(denom_u) / (AB * CD) < FLOAT_PRECISION) { | ||
//u,v parallel | ||
@@ -927,4 +939,4 @@ //let's check if they are close | ||
if ( | ||
getDistanceBetweenPoints(A, P) < mmTolerance || | ||
getDistanceBetweenPoints(B, M) < mmTolerance | ||
getDistanceBetweenPoints(A, P) < FLOAT_PRECISION || | ||
getDistanceBetweenPoints(B, M) < FLOAT_PRECISION | ||
) { | ||
@@ -931,0 +943,0 @@ // AB and CD are colinear |
197894
6657