fix: Clamp leader rotation limits to prevent extreme angles and add a safety check for inverted limits.

This commit is contained in:
2025-11-28 01:27:57 +01:00
parent 7c03eecd30
commit 268488d93d
+25 -4
View File
@@ -137,8 +137,19 @@ export class CardPhysics {
this.updateMassScale();
// Constrain leader limits to ensure follower stays within [-5, 5]
this.minLimit = Math.max(this.minLimit, -this.ROTATION_LIMIT - offset);
this.maxLimit = Math.min(this.maxLimit, this.ROTATION_LIMIT - offset);
// But clamp the result to never exceed the global limits [-5, 5]
// This prevents the leader from being forced into extreme angles by far-away followers
const calculatedMin = -this.ROTATION_LIMIT - offset;
const calculatedMax = this.ROTATION_LIMIT - offset;
this.minLimit = Math.max(this.minLimit, Math.min(this.ROTATION_LIMIT, Math.max(-this.ROTATION_LIMIT, calculatedMin)));
this.maxLimit = Math.min(this.maxLimit, Math.max(-this.ROTATION_LIMIT, Math.min(this.ROTATION_LIMIT, calculatedMax)));
// Safety: If limits invert (min > max), prioritize keeping leader near 0
if (this.minLimit > this.maxLimit) {
this.minLimit = -this.ROTATION_LIMIT;
this.maxLimit = this.ROTATION_LIMIT;
}
}
removeFollower(card: LayoutCard) {
@@ -172,9 +183,19 @@ export class CardPhysics {
// Re-apply limits
const offset = f.offsetRotation;
this.minLimit = Math.max(this.minLimit, -this.ROTATION_LIMIT - offset);
this.maxLimit = Math.min(this.maxLimit, this.ROTATION_LIMIT - offset);
const calculatedMin = -this.ROTATION_LIMIT - offset;
const calculatedMax = this.ROTATION_LIMIT - offset;
this.minLimit = Math.max(this.minLimit, Math.min(this.ROTATION_LIMIT, Math.max(-this.ROTATION_LIMIT, calculatedMin)));
this.maxLimit = Math.min(this.maxLimit, Math.max(-this.ROTATION_LIMIT, Math.min(this.ROTATION_LIMIT, calculatedMax)));
}
// Safety check
if (this.minLimit > this.maxLimit) {
this.minLimit = -this.ROTATION_LIMIT;
this.maxLimit = this.ROTATION_LIMIT;
}
this.updateMassScale();
}