Example #1
0
        private string Euler3()
        {
            Int64 num   = 600851475143;
            Int64 numSq = (Int64)Math.Sqrt((double)num);

            Euler3 e3 = new Euler3();

            e3.FindNPrimes(numSq);
            List <Int64> results = e3.FindDivisors(num);

            return(results[results.Count - 1].ToString());
        }
Example #2
0
 private static void SerializeEulerAngles(IDataBlock block, Euler3 angles)
 {
     block.Writer.Write(angles.Yaw.Radians);
     block.Writer.Write(angles.Pitch.Radians);
     block.Writer.Write(angles.Roll.Radians);
 }
Example #3
0
 public void Write(Euler3 value)
 {
     Write(value.pitch);
     Write(value.yaw);
     Write(value.roll);
 }
Example #4
0
 private static void SerializeEulerAngles(IDataBlock block, Euler3 angles)
 {
     block.Writer.Write(angles.Yaw.Radians);
     block.Writer.Write(angles.Pitch.Radians);
     block.Writer.Write(angles.Roll.Radians);
 }
Example #5
0
        public object ParseArgs(Type type, List <string> args)
        {
            var    input  = args[0];
            object output = null;

            if (type.IsArray)
            {
                throw new NotImplementedException();
            }

            if (type == typeof(byte))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                byte value;
                if (!byte.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(sbyte))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                sbyte value;
                if (!sbyte.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(short))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                short value;
                if (!short.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(ushort))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                ushort value;
                if (!ushort.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(int))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                int value;
                if (!int.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(uint))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                uint value;
                if (!uint.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(long))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                long value;
                if (!long.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(ulong))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                ulong value;
                if (!ulong.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(float))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                float value;
                if (!float.TryParse(input, out value))
                {
                    return(false);
                }
                output = value;
            }
            else if (type == typeof(string))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                output = input;
            }
            else if (type == typeof(TagInstance))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                output = ArgumentParser.ParseTagIndex(Info.Cache, input);
            }
            else if (type == typeof(StringId))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                output = Info.StringIds.GetStringId(input);
            }
            else if (type == typeof(Angle))
            {
                if (args.Count != 1)
                {
                    return(false);
                }
                float value;
                if (!float.TryParse(input, out value))
                {
                    return(false);
                }
                output = Angle.FromDegrees(value);
            }
            else if (type == typeof(Euler2))
            {
                if (args.Count != 2)
                {
                    return(false);
                }
                float yaw, pitch;
                if (!float.TryParse(args[0], out yaw) ||
                    !float.TryParse(args[1], out pitch))
                {
                    return(false);
                }
                output = new Euler2(
                    Angle.FromDegrees(yaw),
                    Angle.FromDegrees(pitch));
            }
            else if (type == typeof(Euler3))
            {
                if (args.Count != 2)
                {
                    return(false);
                }
                float yaw, pitch, roll;
                if (!float.TryParse(args[0], out yaw) ||
                    !float.TryParse(args[1], out pitch) ||
                    !float.TryParse(args[2], out roll))
                {
                    return(false);
                }
                output = new Euler3(
                    Angle.FromDegrees(yaw),
                    Angle.FromDegrees(pitch),
                    Angle.FromDegrees(roll));
            }
            else if (type == typeof(Vector2))
            {
                if (args.Count != 2)
                {
                    return(false);
                }
                float x, y;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y))
                {
                    return(false);
                }
                output = new Vector2(x, y);
            }
            else if (type == typeof(Vector3))
            {
                if (args.Count != 3)
                {
                    return(false);
                }
                float x, y, z;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y) ||
                    !float.TryParse(args[2], out z))
                {
                    return(false);
                }
                output = new Vector3(x, y, z);
            }
            else if (type == typeof(Vector4))
            {
                if (args.Count != 4)
                {
                    return(false);
                }
                float x, y, z, w;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y) ||
                    !float.TryParse(args[2], out z) ||
                    !float.TryParse(args[3], out w))
                {
                    return(false);
                }
                output = new Vector4(x, y, z, w);
            }
            else if (type.IsEnum)
            {
                if (args.Count != 1)
                {
                    return(false);
                }

                var query = args[0];

                var found = Enum.Parse(type, query);

                if (found == null)
                {
                    var nameLow = query.ToLower();
                    var names   = Enum.GetNames(type).Select(i => i.ToLower()).ToList();
                    found = names.Find(n => n == nameLow);

                    if (found == null)
                    {
                        Console.WriteLine("Invalid {0} enum option: {1}", type.Name, args[0]);
                        Console.WriteLine("");

                        Console.WriteLine("Valid options:");
                        foreach (var name in Enum.GetNames(type))
                        {
                            Console.WriteLine("\t{0}", name);
                        }
                        Console.WriteLine();

                        return(false);
                    }
                }

                output = found;
            }
            else if (type == typeof(Range <>))
            {
                var rangeType = type.GenericTypeArguments[0];
                var argCount  = RangeArgCount(rangeType);

                var min = ParseArgs(rangeType, args.Take(argCount).ToList());

                if (min.Equals(false))
                {
                    return(false);
                }

                var max = ParseArgs(rangeType, args.Skip(argCount).Take(argCount).ToList());

                if (max.Equals(false))
                {
                    return(false);
                }

                output = Activator.CreateInstance(type, new object[] { min, max });
            }
            else
            {
                throw new NotImplementedException();
            }

            return(output);
        }
        public object ParseArgs(Type type, List<string> args)
        {
            var input = args[0];
            object output = null;

            if (type.IsArray)
                throw new NotImplementedException();

            if (type == typeof(byte))
            {
                if (args.Count != 1)
                    return false;
                byte value;
                if (!byte.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(sbyte))
            {
                if (args.Count != 1)
                    return false;
                sbyte value;
                if (!sbyte.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(short))
            {
                if (args.Count != 1)
                    return false;
                short value;
                if (!short.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(ushort))
            {
                if (args.Count != 1)
                    return false;
                ushort value;
                if (!ushort.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(int))
            {
                if (args.Count != 1)
                    return false;
                int value;
                if (!int.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(uint))
            {
                if (args.Count != 1)
                    return false;
                uint value;
                if (!uint.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(long))
            {
                if (args.Count != 1)
                    return false;
                long value;
                if (!long.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(ulong))
            {
                if (args.Count != 1)
                    return false;
                ulong value;
                if (!ulong.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(float))
            {
                if (args.Count != 1)
                    return false;
                float value;
                if (!float.TryParse(input, out value))
                    return false;
                output = value;
            }
            else if (type == typeof(string))
            {
                if (args.Count != 1)
                    return false;
                output = input;
            }
            else if (type == typeof(TagInstance))
            {
                if (args.Count != 1)
                    return false;
                output = ArgumentParser.ParseTagIndex(Info.Cache, input);
            }
            else if (type == typeof(StringId))
            {
                if (args.Count != 1)
                    return false;
                output = Info.StringIds.GetStringId(input);
            }
            else if (type == typeof(Angle))
            {
                if (args.Count != 1)
                    return false;
                float value;
                if (!float.TryParse(input, out value))
                    return false;
                output = Angle.FromDegrees(value);
            }
            else if (type == typeof(Euler2))
            {
                if (args.Count != 2)
                    return false;
                float yaw, pitch;
                if (!float.TryParse(args[0], out yaw) ||
                    !float.TryParse(args[1], out pitch))
                    return false;
                output = new Euler2(
                    Angle.FromDegrees(yaw),
                    Angle.FromDegrees(pitch));
            }
            else if (type == typeof(Euler3))
            {
                if (args.Count != 2)
                    return false;
                float yaw, pitch, roll;
                if (!float.TryParse(args[0], out yaw) ||
                    !float.TryParse(args[1], out pitch) ||
                    !float.TryParse(args[2], out roll))
                    return false;
                output = new Euler3(
                    Angle.FromDegrees(yaw),
                    Angle.FromDegrees(pitch),
                    Angle.FromDegrees(roll));
            }
            else if (type == typeof(Vector2))
            {
                if (args.Count != 2)
                    return false;
                float x, y;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y))
                    return false;
                output = new Vector2(x, y);
            }
            else if (type == typeof(Vector3))
            {
                if (args.Count != 3)
                    return false;
                float x, y, z;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y) ||
                    !float.TryParse(args[2], out z))
                    return false;
                output = new Vector3(x, y, z);
            }
            else if (type == typeof(Vector4))
            {
                if (args.Count != 4)
                    return false;
                float x, y, z, w;
                if (!float.TryParse(args[0], out x) ||
                    !float.TryParse(args[1], out y) ||
                    !float.TryParse(args[2], out z) ||
                    !float.TryParse(args[3], out w))
                    return false;
                output = new Vector4(x, y, z, w);
            }
            else if (type.IsEnum)
            {
                if (args.Count != 1)
                    return false;

                var query = args[0];

                var found = Enum.Parse(type, query);

                if (found == null)
                {
                    var nameLow = query.ToLower();
                    var names = Enum.GetNames(type).Select(i => i.ToLower()).ToList();
                    found = names.Find(n => n == nameLow);

                    if (found == null)
                    {
                        Console.WriteLine("Invalid {0} enum option: {1}", type.Name, args[0]);
                        Console.WriteLine("");

                        Console.WriteLine("Valid options:");
                        foreach (var name in Enum.GetNames(type))
                            Console.WriteLine("\t{0}", name);
                        Console.WriteLine();

                        return false;
                    }
                }
                
                output = found;
            }
            else if (type == typeof(Range<>))
            {
                var rangeType = type.GenericTypeArguments[0];
                var argCount = RangeArgCount(rangeType);
                
                var min = ParseArgs(rangeType, args.Take(argCount).ToList());

                if (min.Equals(false))
                    return false;

                var max = ParseArgs(rangeType, args.Skip(argCount).Take(argCount).ToList());

                if (max.Equals(false))
                    return false;

                output = Activator.CreateInstance(type, new object[] { min, max });
            }
            else throw new NotImplementedException();

            return output;
        }