geforkt von Mirrors/Paper
SPIGOT-5240: Vector.angle not valid for angles very close to each other
By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Ursprung
5397c5b7be
Commit
e5c9e369ed
@ -1,6 +1,7 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Doubles;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@ -202,7 +203,7 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
* @return angle in radians
|
||||
*/
|
||||
public float angle(@NotNull Vector other) {
|
||||
double dot = dot(other) / (length() * other.length());
|
||||
double dot = Doubles.constrainToRange(dot(other) / (length() * other.length()), -1.0, 1.0);
|
||||
|
||||
return (float) Math.acos(dot);
|
||||
}
|
||||
|
@ -114,4 +114,12 @@ public class VectorTest {
|
||||
assertEquals(a, v.angle(axis), Vector.getEpsilon());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSmallAngle() {
|
||||
Vector a = new Vector(-0.13154885489775203, 0.0, 0.12210868381700482);
|
||||
Vector b = new Vector(-0.7329152226448059, -0.0, 0.6803199648857117);
|
||||
|
||||
assertTrue(Double.isFinite(a.angle(b)));
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren