Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Clamp(double t)
 {
     if (IsDecreasing)
     {
         return(SlurMath.Clamp(t, B, A));
     }
     else
     {
         return(SlurMath.Clamp(t, A, B));
     }
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static Vec3d LABtoLCH(Vec3d color)
        {
            double l = color.X;
            double a = color.Y;
            double b = color.Z;

            double c = Math.Sqrt(a * a + b * b);
            double h = Math.Atan2(b, a);

            h = (h > 0.0) ? SlurMath.ToDegrees(h) : SlurMath.ToDegrees(360.0 - Math.Abs(h));

            return(new Vec3d(l, c, h));
        }
Esempio n. 3
0
        /// <summary>
        /// Shifts a subset of a list of items in place.
        /// </summary>
        public static void Shift <T>(this IList <T> list, int offset, int from, int to)
        {
            if (list is T[])
            {
                ArrayExtensions.Shift((T[])list, offset, from, to);
                return;
            }

            offset = SlurMath.Mod2(offset, to - from + 1);
            Reverse(list, from, from + offset - 1);
            Reverse(list, from + offset, to);
            Reverse(list, from, to);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public bool ApproxEquals(ref Matrix3d other, double tolerance = SlurMath.ZeroTolerance)
        {
            return
                (SlurMath.ApproxEquals(M00, other.M00, tolerance) &&
                 SlurMath.ApproxEquals(M01, other.M01, tolerance) &&
                 SlurMath.ApproxEquals(M02, other.M02, tolerance) &&

                 SlurMath.ApproxEquals(M10, other.M10, tolerance) &&
                 SlurMath.ApproxEquals(M11, other.M11, tolerance) &&
                 SlurMath.ApproxEquals(M12, other.M12, tolerance) &&

                 SlurMath.ApproxEquals(M20, other.M20, tolerance) &&
                 SlurMath.ApproxEquals(M21, other.M21, tolerance) &&
                 SlurMath.ApproxEquals(M22, other.M22, tolerance));
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        public static double Lerp(this double[] vector, double t)
        {
            int last = vector.Length - 1;

            t = SlurMath.Fract(t * last, out int i);

            if (i < 0)
            {
                return(vector[0]);
            }
            else if (i >= last)
            {
                return(vector[last]);
            }

            return(SlurMath.Lerp(vector[i], vector[i + 1], t));
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        public static double Lerp(this IReadOnlyList <double> vector, double factor)
        {
            int last = vector.Count - 1;

            factor = SlurMath.Fract(factor * last, out int i);

            if (i < 0)
            {
                return(vector[0]);
            }
            else if (i >= last)
            {
                return(vector[last]);
            }

            return(SlurMath.Lerp(vector[i], vector[i + 1], factor));
        }
        /// <summary>
        ///
        /// </summary>
        public static void Lerp(this Vec3d[][] vectors, double[] t, int size, Vec3d[] result)
        {
            int last = vectors.Length - 1;

            for (int j = 0; j < size; j++)
            {
                double tj = SlurMath.Fract(t[j] * last, out int i);

                if (i < 0)
                {
                    result[j] = vectors[0][j];
                }
                else if (i >= last)
                {
                    result[j] = vectors[last][j];
                }
                else
                {
                    result[j] = Vec3d.Lerp(vectors[i][j], vectors[i + 1][j], tj);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Nearest(double t)
 {
     return(SlurMath.Nearest(t, T0, T1));
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <exception cref="DivideByZeroException">
 /// thrown if the domain is invalid </exception>
 public double Normalize(double t)
 {
     return(SlurMath.Normalize(t, T0, T1));
 }
Esempio n. 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 public float Evaluate(float t)
 {
     return(SlurMath.Lerp(A, B, t));
 }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float SmootherStep(float t)
 {
     return(SlurMath.SmootherStep(t, A, B));
 }
Esempio n. 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 public double Evaluate(double t)
 {
     return(SlurMath.Lerp(A, B, t));
 }
Esempio n. 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Wrap(double t)
 {
     return(SlurMath.Wrap(t, T0, T1));
 }
Esempio n. 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Normalize(float t)
 {
     return(SlurMath.Normalize(t, A, B));
 }
Esempio n. 15
0
        /// <summary>
        /// Converts from euclidean to spherical coordiantes.
        /// (x,y,z) = (radius, azimuth, polar)
        /// </summary>
        /// <returns></returns>
        public Vec3d ToSpherical()
        {
            double r = Length;

            return(new Vec3d(r, Math.Atan(Y / X), SlurMath.AcosSafe(Z / r)));
        }
Esempio n. 16
0
        /// <summary>
        /// Returns the minimum angle between two vectors.
        /// </summary>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <returns></returns>
        public static double Angle(Vec3d v0, Vec3d v1)
        {
            var d = v0.SquareLength * v1.SquareLength;

            return(d > 0.0 ? SlurMath.AcosSafe(Dot(v0, v1) / Math.Sqrt(d)) : 0.0);
        }
Esempio n. 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(Vec2d other, Vec2d tolerance)
 {
     return
         (SlurMath.ApproxEquals(X, other.X, tolerance.X) &&
          SlurMath.ApproxEquals(Y, other.Y, tolerance.Y));
 }
Esempio n. 18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(Vec2d other, double tolerance = SlurMath.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(X, other.X, tolerance) &&
          SlurMath.ApproxEquals(Y, other.Y, tolerance));
 }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Nearest(float t)
 {
     return(SlurMath.Nearest(t, A, B));
 }
Esempio n. 20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Ramp(double t)
 {
     return(SlurMath.Ramp(t, T0, T1));
 }
Esempio n. 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double SmoothStep(double t)
 {
     return(SlurMath.SmoothStep(t, T0, T1));
 }
Esempio n. 22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Nearest(double t)
 {
     return(SlurMath.Nearest(t, A, B));
 }
Esempio n. 23
0
 /// <summary>
 ///
 /// </summary>
 public bool IsUnit(double tolerance = SlurMath.ZeroTolerance)
 {
     return(SlurMath.ApproxEquals(SquareLength, 1.0, tolerance));
 }
Esempio n. 24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double SmootherStep(double t)
 {
     return(SlurMath.SmootherStep(t, A, B));
 }
Esempio n. 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Normalize(double t)
 {
     return(SlurMath.Normalize(t, A, B));
 }
Esempio n. 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Ramp(float t)
 {
     return(SlurMath.Ramp(t, A, B));
 }
Esempio n. 27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Ramp(double t)
 {
     return(SlurMath.Ramp(t, A, B));
 }
Esempio n. 28
0
 /// <summary>
 /// Returns a random vector which has components within the given interval.
 /// </summary>
 /// <param name="random"></param>
 /// <param name="t0"></param>
 /// <param name="t1"></param>
 /// <returns></returns>
 public static Vec2d NextVec2d(this Random random, double t0, double t1)
 {
     return(new Vec2d(
                SlurMath.Lerp(t0, t1, random.NextDouble()),
                SlurMath.Lerp(t0, t1, random.NextDouble())));
 }
Esempio n. 29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Wrap(double t)
 {
     return(SlurMath.Wrap(t, A, B));
 }
Esempio n. 30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(Intervald other, double tolerance = SlurMath.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(A, other.A, tolerance) &&
          SlurMath.ApproxEquals(B, other.B, tolerance));
 }