import * as Types from "../../../../types/world/worldTypes";

function updateLinesPositions(
    DragedPoint: Types.Mesh | { uuid: string, position: Types.Vector3 },
    lines: Types.RefLines
): Types.NumberArray {

    ////////// Updating the lines position based on the dragged point's position //////////

    const objectUUID = DragedPoint.uuid;
    const affectedLines: Types.NumberArray = [];

    lines.current.forEach((line, index) => {
        let lineUpdated = false;
        line.forEach((point) => {
            const [position, uuid] = point;
            if (uuid === objectUUID) {
                position.x = DragedPoint.position.x;
                position.y = 0.01;
                position.z = DragedPoint.position.z;
                lineUpdated = true;
            }
        });
        if (lineUpdated) {
            affectedLines.push(index);
        }
    });

    return affectedLines;
}

export default updateLinesPositions;
