| 179 | */ |
| 180 | @nodeName('Line') |
| 181 | export class Line extends Curve { |
| 182 | /** |
| 183 | * Rotate the points to minimize the overall distance traveled when tweening. |
| 184 | * |
| 185 | * @param points - The points to rotate. |
| 186 | * @param reference - The reference points to which the distance is measured. |
| 187 | * @param closed - Whether the points form a closed polygon. |
| 188 | */ |
| 189 | private static rotatePoints( |
| 190 | points: Vector2[], |
| 191 | reference: Vector2[], |
| 192 | closed: boolean, |
| 193 | ) { |
| 194 | if (closed) { |
| 195 | let minDistance = Infinity; |
| 196 | let bestOffset = 0; |
| 197 | for (let offset = 0; offset < points.length; offset += 1) { |
| 198 | const distance = calculateLerpDistance(points, reference, offset); |
| 199 | if (distance < minDistance) { |
| 200 | minDistance = distance; |
| 201 | bestOffset = offset; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if (bestOffset) { |
| 206 | const spliced = points.splice(0, bestOffset); |
| 207 | points.splice(points.length, 0, ...spliced); |
| 208 | } |
| 209 | } else { |
| 210 | const originalDistance = calculateLerpDistance(points, reference, 0); |
| 211 | const reversedPoints = [...points].reverse(); |
| 212 | const reversedDistance = calculateLerpDistance( |
| 213 | reversedPoints, |
| 214 | reference, |
| 215 | 0, |
| 216 | ); |
| 217 | if (reversedDistance < originalDistance) { |
| 218 | points.reverse(); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Distribute additional points along the polyline. |
| 225 | * |
| 226 | * @param points - The points of a polyline along which new points should be |
| 227 | * distributed. |
| 228 | * @param count - The number of points to add. |
| 229 | */ |
| 230 | private static distributePoints(points: Vector2[], count: number) { |
| 231 | if (points.length === 0) { |
| 232 | for (let j = 0; j < count; j++) { |
| 233 | points.push(Vector2.zero); |
| 234 | } |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (points.length === 1) { |
nothing calls this directly
no test coverage detected