function rotateSegment(segment, angle, rotationPoint) {
const cosAngle = Math.cos(angle);
const sinAngle = Math.sin(angle);
const [startX, startY] = segment[0];
const [endX, endY] = segment[1];
const [rotationX, rotationY] = rotationPoint;
const translatedStart = [startX - rotationX, startY - rotationY];
const rotatedStart = [
translatedStart[0] * cosAngle - translatedStart[1] * sinAngle,
translatedStart[0] * sinAngle + translatedStart[1] * cosAngle
];
const translatedEnd = [endX - rotationX, endY - rotationY];
const rotatedEnd = [
translatedEnd[0] * cosAngle - translatedEnd[1] * sinAngle,
translatedEnd[0] * sinAngle + translatedEnd[1] * cosAngle
];
return [
[rotatedStart[0] + rotationX, rotatedStart[1] + rotationY],
[rotatedEnd[0] + rotationX, rotatedEnd[1] + rotationY]
];
}