//placeholder to hold action space for whole platform: innerPlaceholder, enemies, walls, gap private void SetOuterPlaceholder(GameObject previousPlatform, GameObject currentPlatform) { Vector3 extents = GetPlatformExtents(currentPlatform); Vector3 extension = new Vector3(_extensionWidth, _extensionHeight, 0); extents += extension; extents = MathMethod.LossyToLocal(extents, currentPlatform.transform.lossyScale); Transform outerPlaceholderTransform = currentPlatform.transform.Find("OuterPlaceholder"); Transform innerPlaceholderTransform = currentPlatform.transform.Find("InnerPlaceholder"); outerPlaceholderTransform.gameObject.SetActive(true); outerPlaceholderTransform.localScale = extents; outerPlaceholderTransform.localPosition = innerPlaceholderTransform.localPosition; float gap; if (previousPlatform.transform.rotation == currentPlatform.transform.rotation) { gap = GetBetweenGap(previousPlatform.transform, currentPlatform.transform); } else { gap = GetCornerGap(previousPlatform.transform, currentPlatform.transform); } float localGap = MathMethod.LossyToLocal(gap, currentPlatform.transform.lossyScale.z); outerPlaceholderTransform.localScale += new Vector3(0, 0, localGap); outerPlaceholderTransform.localPosition += new Vector3(0, 0, -localGap / 2); }
public void MathMethodDouble() { MathMethod mathMethod = new MathMethod(); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.NULL, 1.0, 2.0) == 0, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.ADD, 1.0, 2.0) == 3.0, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.MINUS, 4.0, 2.0) == 2.0, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.MULTIPLY, 4.0, 2.0) == 8.0, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.DEVIDE, 2.0, 2.0) == 1.0, "It is true"); }
public void MathMethodInt() { MathMethod mathMethod = new MathMethod(); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.NULL, 1, 2) == 0, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.ADD, 1, 2) == 3, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.MINUS, 4, 2) == 2, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.MULTIPLY, 4, 2) == 8, "It is true"); Assert.IsTrue(mathMethod.Opr(MathMethod.ENUM_OPR.DEVIDE, 2, 2) == 1, "It is true"); }
private void UpdateTraveledDistance(Vector3 velocity) { float stepDistance = velocity.magnitude; _traveledDistance += stepDistance; if (MathMethod.Approximately(_traveledDistance, travelDistance, 3)) { _traveledDistance = 0; DestinationReached = !DestinationReached; } }
private void CreateCornerWalls(Transform previousOuterPlaceholder, Transform currentOuterPlaceholder, List <GameObject> surroundings) { float side = MathMethod.VectorSign(previousOuterPlaceholder.forward); GameObject sideWall = InstantiateSideWall(currentOuterPlaceholder, side); GameObject backWall = InstantiateBackWall(currentOuterPlaceholder); TrimPreviousOverlap(previousOuterPlaceholder, backWall.transform); TrimSideWallOverlap(previousOuterPlaceholder, backWall.transform, sideWall.transform); surroundings.Add(sideWall); surroundings.Add(backWall); }
public static bool ManipulateNodeValue(this XmlNode nodeTarget, MathMethod method, int val = 2, int min = int.MinValue + 1, int max = int.MaxValue - 1) { int output = 0; if (int.TryParse(nodeTarget.InnerText, out int input)) { output = input.DoAction(method, val); output = method == MathMethod.Special ? output.ClampSpec(min, max) : output.Clamp(min, max); nodeTarget.InnerText = output.ToString(); } return(nodeTarget.InnerText == output.ToString()); }
public static double AggAfterComplexMethodCall2( List<double> list, MathMethod method, Aggregator agg = null) { List<double> ret = new List<double>(); foreach (var elt in list) { ret.Add(method(elt)); } return (agg ?? Sum)(ret); // replaces if (agg==null) agg=Sum; }
public SingleArgumentMathFunction( IValueGetter arg, MathMethod mathMethod, Token source) { this.arg = arg; this.mathMethod = mathMethod; Type argType = arg.GetValueType(); if (!(argType == typeof(double) || argType == typeof(int))) { throw new ScriptParsingException( source: source, message: $"Cannot perform Math.{mathMethod} on non-numerical value {arg} of type {argType.Name}"); } switch (mathMethod) { case MathMethod.Floor: case MathMethod.Ceiling: case MathMethod.Round: case MathMethod.Abs: valueType = argType; break; case MathMethod.Sign: valueType = typeof(int); break; case MathMethod.Ln: case MathMethod.Log10: case MathMethod.Exp: case MathMethod.Sqrt: case MathMethod.Sin: case MathMethod.Cos: case MathMethod.Tan: case MathMethod.Asin: case MathMethod.Acos: case MathMethod.Atan: case MathMethod.Sinh: case MathMethod.Cosh: case MathMethod.Tanh: //Only return doubles. valueType = typeof(double); break; default: throw new ArgumentException($"Unexpected Operator: {mathMethod}"); } }
public DoubleArgumentMathFunction( IValueGetter arg1, IValueGetter arg2, MathMethod mathMethod, Token source) { Type arg1Type = arg1.GetValueType(); Type arg2Type = arg2.GetValueType(); this.arg1 = arg1; this.arg2 = arg2; this.mathMethod = mathMethod; if (!(arg1Type == typeof(double) || arg1Type == typeof(int))) { throw new ScriptParsingException( source: source, message: $"First Argument of Math.{mathMethod} not of expected type int or bool: {arg1.GetValueType().Name}"); } if (!(arg2Type == typeof(double) || arg2Type == typeof(int))) { throw new ScriptParsingException( source: source, message: $"Second Argument of Math.{mathMethod} not of expected type int or bool: {arg2.GetValueType().Name}"); } if (arg1Type == arg2Type) { valueType = arg1Type; } else { valueType = typeof(double); } switch (mathMethod) { case MathMethod.Min: case MathMethod.Max: //Acceptable break; default: throw new ArgumentException($"Unexpected MathMethod: {mathMethod}"); } }
public static bool ManipulateNodeValue(this XmlNode nodeTarget, MathMethod method, double val = 2d, double min = double.MinValue + 1d, double max = double.MaxValue - 1d, int digits = 8) { double output = 0d; if (double.TryParse(nodeTarget.InnerText, out double input)) { if (digits == -1) { digits = input.HasDecimals(out int newDigits) ? newDigits : 0; } output = input.DoAction(method, val); output = method == MathMethod.Special ? output.ClampSpec(min, max, digits) : output.Clamp(min, max, digits); nodeTarget.InnerText = output.ToString(); } return(nodeTarget.InnerText == output.ToString()); }
public static bool ManipulateNodeValue(this XmlNode nodeTarget, MathMethod method, float val = 2f, float min = float.MinValue + 1f, float max = float.MaxValue - 1f, int digits = 16) { float output = 0f; if (float.TryParse(nodeTarget.InnerText, out float input)) { if (digits == -1) { digits = input.HasDecimals(out int newDigits) ? newDigits : 0; } output = input.DoAction(method, val); output = method == MathMethod.Special ? output.ClampSpec(min, max, digits) : output.Clamp(min, max, digits); nodeTarget.InnerText = output.ToString(); } return(nodeTarget.InnerText == output.ToString()); }
private void UpdateDirection(Vector3 straightVelocity) { float stepDistance = straightVelocity.magnitude; _loopTraveledDistance += stepDistance; if (MathMethod.Approximately(_loopTraveledDistance, GetCircleCircumference() / 2, 3)) { _loopCounter += 0.5f; _loopTraveledDistance = 0; if (_loopCounter >= loops) { _direction *= -1; _angle *= -1; _loopCounter = 0; DestinationReached = !DestinationReached; } } }
private void InstantiateSideWalls(Transform currentPlaceholder, out GameObject leftWall, out GameObject rightWall) { PlaceholderFlag flag = GetFlag(currentPlaceholder); if (flag != null) { float side = MathMethod.VectorSign(flag.OccupiedSide); if (side == 1) { leftWall = InstantiateSideWall(currentPlaceholder, -side); rightWall = null; } else { leftWall = null; rightWall = InstantiateSideWall(currentPlaceholder, -side); } } else { leftWall = InstantiateSideWall(currentPlaceholder, -1); rightWall = InstantiateSideWall(currentPlaceholder, 1); } }
public static float DoAction(this float input, MathMethod method, float val = 2f) { switch (method) { case MathMethod.Add when val.NotZero(): return(input + val); case MathMethod.Subtract when val.NotZero(): return(input - val); case MathMethod.Multiply when input.NotZeroOrOne() && val.NotZeroOrOne(): return(input * val); case MathMethod.Divide when input.NotZeroOrOne() && val.NotZeroOrOne(): return(input / val); case MathMethod.Special when input.NotZero() && val.NotZeroOrOne(): return(input > 0 ? input * val : input / val); case MathMethod.None: default: return(input); } }
static void Test3() { //10+5 = 15 Console.WriteLine("Enter string"); string str = Console.ReadLine(); char Sign = ' '; try { if (str.Contains('+')) { Sign = '+'; } else if (str.Contains('-')) { Sign = '-'; } else if (str.Contains('*')) { Sign = '*'; } else if (str.Contains('/')) { Sign = '/'; } else { Sign = ' '; } string[] numbers = str.Split(Sign, StringSplitOptions.RemoveEmptyEntries); double av = double.Parse(numbers[0]); double bv = double.Parse(numbers[1]); MathMethod mathod = null; switch (Sign) { case '+': mathod = (a, b) => a + b; break; case '-': mathod = (a, b) => a - b; break; case '*': mathod = (a, b) => a * b; break; case '/': mathod = (a, b) => a / b; break; } //Console.WriteLine(mathod(a, b)); Console.WriteLine(mathod?.Invoke(av, bv)); ShowMethod sm = d => Console.WriteLine($"d={d}"); Show show = () => Console.WriteLine($"Hello"); show += () => Console.WriteLine($"By"); sm(159.36); show(); } catch (Exception e) { Console.WriteLine(e.Message); throw; } }
static void Test1() { //10+5 = 15 Console.WriteLine("Enter string"); string str = Console.ReadLine(); char Sign = ' '; try { if (str.Contains('+')) { Sign = '+'; } else if (str.Contains('-')) { Sign = '-'; } else if (str.Contains('*')) { Sign = '*'; } else if (str.Contains('/')) { Sign = '/'; } else { Sign = ' '; } string[] numbers = str.Split(Sign, StringSplitOptions.RemoveEmptyEntries); double a = double.Parse(numbers[0]); double b = double.Parse(numbers[1]); MathMethod mathod = null; MyMath algebra = new MyMath(); switch (Sign) { case '+': mathod = new MathMethod(algebra.Sum); // старий запис //Console.WriteLine(a+b); break; case '-': mathod = algebra.Sub; break; case '*': mathod = MyMath.Mult; break; case '/': mathod = MyMath.Div; break; } //Console.WriteLine(mathod(a, b)); Console.WriteLine(mathod?.Invoke(a, b)); Console.WriteLine("-------------------------------------------------"); MathMethod math = null; math = MyMath.Mult; // ДОДАЄМО МЕТОДИ math += MyMath.Div; math += algebra.Sub; math += algebra.Sum; Console.WriteLine(math?.Invoke(a, b)); math -= algebra.Sum; // видаляємо методи foreach (MathMethod fun in math.GetInvocationList()) { Console.WriteLine(fun(a, b)); } } catch (Exception e) { Console.WriteLine(e.Message); throw; } }
public int DoMaths(int a, int b, MathMethod mathMethod) { return(mathMethod(a, b)); }
public Config() { flags = 0; obfuscation = EmailObfuscation.JavaScript; math = MathMethod.AsciiMathML; }