SegmentedAnglePrecision.java

net.minecraft.util.SegmentedAnglePrecision

信息

  • 全限定名:net.minecraft.util.SegmentedAnglePrecision
  • 类型:public class
  • 包:net.minecraft.util
  • 源码路径:src/main/java/net/minecraft/util/SegmentedAnglePrecision.java
  • 起始行号:L5
  • 职责:

    TODO

字段/常量

  • mask

    • 类型: int
    • 修饰符: private final
    • 源码定位: L6
    • 说明:

      TODO

  • precision

    • 类型: int
    • 修饰符: private final
    • 源码定位: L7
    • 说明:

      TODO

  • degreeToAngle

    • 类型: float
    • 修饰符: private final
    • 源码定位: L8
    • 说明:

      TODO

  • angleToDegree

    • 类型: float
    • 修饰符: private final
    • 源码定位: L9
    • 说明:

      TODO

内部类/嵌套类型

构造器

public SegmentedAnglePrecision(int bitPrecision) @ L11

  • 构造器名:SegmentedAnglePrecision
  • 源码定位:L11
  • 修饰符:public

参数:

  • bitPrecision: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public boolean isSameAxis(int binaryAngleA, int binaryAngleB) @ L25

  • 方法名:isSameAxis
  • 源码定位:L25
  • 返回类型:boolean
  • 修饰符:public

参数:

  • binaryAngleA: int
  • binaryAngleB: int

说明:

TODO

public int fromDirection(Direction direction) @ L30

  • 方法名:fromDirection
  • 源码定位:L30
  • 返回类型:int
  • 修饰符:public

参数:

  • direction: Direction

说明:

TODO

public int fromDegreesWithTurns(float degrees) @ L39

  • 方法名:fromDegreesWithTurns
  • 源码定位:L39
  • 返回类型:int
  • 修饰符:public

参数:

  • degrees: float

说明:

TODO

public int fromDegrees(float degrees) @ L43

  • 方法名:fromDegrees
  • 源码定位:L43
  • 返回类型:int
  • 修饰符:public

参数:

  • degrees: float

说明:

TODO

public float toDegreesWithTurns(int binaryAngle) @ L47

  • 方法名:toDegreesWithTurns
  • 源码定位:L47
  • 返回类型:float
  • 修饰符:public

参数:

  • binaryAngle: int

说明:

TODO

public float toDegrees(int binaryAngle) @ L51

  • 方法名:toDegrees
  • 源码定位:L51
  • 返回类型:float
  • 修饰符:public

参数:

  • binaryAngle: int

说明:

TODO

public int normalize(int binaryAngle) @ L56

  • 方法名:normalize
  • 源码定位:L56
  • 返回类型:int
  • 修饰符:public

参数:

  • binaryAngle: int

说明:

TODO

public int getMask() @ L60

  • 方法名:getMask
  • 源码定位:L60
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

代码

public class SegmentedAnglePrecision {
    private final int mask;
    private final int precision;
    private final float degreeToAngle;
    private final float angleToDegree;
 
    public SegmentedAnglePrecision(int bitPrecision) {
        if (bitPrecision < 2) {
            throw new IllegalArgumentException("Precision cannot be less than 2 bits");
        } else if (bitPrecision > 30) {
            throw new IllegalArgumentException("Precision cannot be greater than 30 bits");
        } else {
            int twoPi = 1 << bitPrecision;
            this.mask = twoPi - 1;
            this.precision = bitPrecision;
            this.degreeToAngle = twoPi / 360.0F;
            this.angleToDegree = 360.0F / twoPi;
        }
    }
 
    public boolean isSameAxis(int binaryAngleA, int binaryAngleB) {
        int semicircleMask = this.getMask() >> 1;
        return (binaryAngleA & semicircleMask) == (binaryAngleB & semicircleMask);
    }
 
    public int fromDirection(Direction direction) {
        if (direction.getAxis().isVertical()) {
            return 0;
        } else {
            int segmentedAngle2bit = direction.get2DDataValue();
            return segmentedAngle2bit << this.precision - 2;
        }
    }
 
    public int fromDegreesWithTurns(float degrees) {
        return Math.round(degrees * this.degreeToAngle);
    }
 
    public int fromDegrees(float degrees) {
        return this.normalize(this.fromDegreesWithTurns(degrees));
    }
 
    public float toDegreesWithTurns(int binaryAngle) {
        return binaryAngle * this.angleToDegree;
    }
 
    public float toDegrees(int binaryAngle) {
        float degrees = this.toDegreesWithTurns(this.normalize(binaryAngle));
        return degrees >= 180.0F ? degrees - 360.0F : degrees;
    }
 
    public int normalize(int binaryAngle) {
        return binaryAngle & this.mask;
    }
 
    public int getMask() {
        return this.mask;
    }
}

引用的其他类