linesToDraw = {
const basicPointsPairs = pointPairsOnASide(facets).map((pair) => {
return {
...pair,
face: 0
}
})
let results = []
const extent = {
x: [Infinity, -Infinity],
y: [Infinity, -Infinity]
}
d3.range(sides).reduce((memo, i) => {
const transform = (pair) => {
const v1 = rotateVector({ x: pair.x1, y: pair.y1 }, rotationRequired.rotation)
const v2 = rotateVector({ x: pair.x2, y: pair.y2 }, rotationRequired.rotation)
const x1 = v1.x + rotationRequired.translation.x
const y1 = v1.y + rotationRequired.translation.y
const x2 = v2.x + rotationRequired.translation.x
const y2 = v2.y + rotationRequired.translation.y
if (x1 < extent.x[0] || x2 < extent.x[0]) { extent.x[0] = Math.min(x1, x2) }
if (x1 > extent.x[1] || x2 > extent.x[1]) { extent.x[1] = Math.max(x1, x2) }
if (y1 < extent.y[0] || y2 < extent.y[0]) { extent.y[0] = Math.min(y1, y2) }
if (y1 > extent.y[1] || y2 > extent.y[1]) { extent.y[1] = Math.max(y1, y2) }
return {
...pair,
x1,
y1,
x2,
y2,
face: i,
}
}
const linesGivenSide = (i === 0) ? memo : memo.map(transform)
results = results.concat(linesGivenSide)
return linesGivenSide
}, basicPointsPairs)
const xShift = (extent.x[0] < 0) ? Math.abs(extent.x[0]) : 0
const yShift = (extent.y[0] < 0) ? Math.abs(extent.y[0]) : 0
return results.map((pair) => {
const switchFromCutToFold = (pair.segment === jointSegment)
&& !(pair.face === 0 && pair.side === "left")
&& !(pair.face === sides - 1 && pair.side === "right")
return {
...pair,
x1: pair.x1 + midlineOffset + 22 + xShift,
x2: pair.x2 + midlineOffset + 22 + xShift,
y1: pair.y1 + 22 + yShift,
y2: pair.y2 + 22 + yShift,
type: switchFromCutToFold ? "fold" : pair.type,
tabs: !noTabSegments.includes(pair.segment)
}
})
}