예제 #1
0
    private static VInt3 ClosestPoint(ref VInt3 point, ref VInt3 lineStart, ref VInt3 lineDir, int lineLen)
    {
        long num = VInt3.DotXZLong(point - lineStart, lineDir);

        num = IntMath.Clamp(num, 0L, (long)(lineLen * 1000));
        return(IntMath.Divide(lineDir, num, 1000000L) + lineStart);
    }
예제 #2
0
    public static VInt3 NearestPointStrictXZ(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point)
    {
        VInt3 rhs = lineEnd - lineStart;
        long  max = rhs.sqrMagnitudeLong2D;

        if (max == 0)
        {
            return(lineStart);
        }
        long m = IntMath.Clamp(VInt3.DotXZLong(point - lineStart, rhs), 0L, max);

        return(IntMath.Divide(rhs, m, max) + lineStart);
    }
예제 #3
0
    public static VInt3 NearestPointStrict(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point)
    {
        VInt3 rhs = lineEnd - lineStart;
        long  sqrMagnitudeLong = rhs.sqrMagnitudeLong;

        if (sqrMagnitudeLong == 0)
        {
            return(lineStart);
        }
        long m = IntMath.Clamp(VInt3.DotLong(point - lineStart, rhs), 0L, sqrMagnitudeLong);

        return(IntMath.Divide(rhs, m, sqrMagnitudeLong) + lineStart);
    }
예제 #4
0
    public static VInt2 ClosestPointOnSegment(VInt2 lineStart, VInt2 lineEnd, VInt2 point)
    {
        var  dir     = lineEnd - lineStart;
        long sqrMagn = dir.sqrMagnitudeLong;

        if (sqrMagn <= 1)
        {
            return(lineStart);
        }

        long factor = VInt2.DotLong(point - lineStart, dir) / sqrMagn;

        return(lineStart + dir * (int)IntMath.Clamp(0, 1000, factor));
    }
예제 #5
0
        public static VInt3 NearestPointStrictXZ(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point)
        {
            VInt3 vInt = lineEnd - lineStart;
            long  sqrMagnitudeLong2D = vInt.sqrMagnitudeLong2D;

            if (sqrMagnitudeLong2D == 0L)
            {
                return(lineStart);
            }
            long num = VInt3.DotXZLong(point - lineStart, vInt);

            num = IntMath.Clamp(num, 0L, sqrMagnitudeLong2D);
            return(IntMath.Divide(vInt, num, sqrMagnitudeLong2D) + lineStart);
        }
예제 #6
0
 protected override void Set(int value) =>
 this.impl_ = IntMath.Clamp(this.Min, value, this.Max);