diff --git a/src/hooks/roofcover/useRoofAllocationSetting.js b/src/hooks/roofcover/useRoofAllocationSetting.js index f93e230d..3ebaa56c 100644 --- a/src/hooks/roofcover/useRoofAllocationSetting.js +++ b/src/hooks/roofcover/useRoofAllocationSetting.js @@ -473,7 +473,20 @@ export function useRoofAllocationSetting(id) { // Filter out any eaveHelpLines that are already in lines to avoid duplicates const existingEaveLineIds = new Set(roofBase.lines.map((line) => line.id)) const newEaveLines = roofEaveHelpLines.filter((line) => !existingEaveLineIds.has(line.id)) - roofBase.lines = [...newEaveLines] + // Filter out lines from roofBase.lines that share any points with newEaveLines + const linesToKeep = roofBase.lines.filter(roofLine => { + return !newEaveLines.some(eaveLine => { + // Check if any endpoint of roofLine matches any endpoint of eaveLine + return ( + // Check if any endpoint of roofLine matches any endpoint of eaveLine + (Math.abs(roofLine.x1 - eaveLine.x1) < 0.1 && Math.abs(roofLine.y1 - eaveLine.y1) < 0.1) || // p1 matches p1 + (Math.abs(roofLine.x2 - eaveLine.x2) < 0.1 && Math.abs(roofLine.y2 - eaveLine.y2) < 0.1) // p2 matches p2 + ); + }); + }); + +// Combine remaining lines with newEaveLines + roofBase.lines = [...linesToKeep, ...newEaveLines]; } else { roofBase.lines = [...roofEaveHelpLines] }