public void Test_0_plus_0_plus_0() { var res = Arithmetics.Add(false, false, false); res.High.Should().BeFalse(); res.Low.Should().BeFalse(); }
} // End Property Slope // https://stackoverflow.com/questions/17692922/check-is-a-point-x-y-is-between-two-points-drawn-on-a-straight-line public bool IsPointOnLine(MyPoint2D <T> p) { T norm = this.Vector.MagnitudeSquared; MyVector2D <T> vec1 = new MyVector2D <T>(this.m_start, p); MyVector2D <T> vec2 = new MyVector2D <T>(this.m_end, p); T dist = Arithmetics <T> .Add(vec1.MagnitudeSquared, vec2.MagnitudeSquared); if (norm.Equals(dist)) { return(true); } T delta = Arithmetics <T> .Subtract(vec1.MagnitudeSquared, vec2.MagnitudeSquared); decimal decDelta = System.Convert.ToDecimal(delta); decDelta = System.Math.Abs(decDelta); // Greatest possible floating-point difference decimal decFloatEpsilon = System.Convert.ToDecimal(float.Epsilon); if (decDelta <= decFloatEpsilon) { return(true); } return(false); } // End Function IsPointOnLine
public void Test_1_plus_1_plus_1() { var res = Arithmetics.Add(true, true, true); res.High.Should().BeTrue(); res.Low.Should().BeTrue(); }
public IActionResult About() { int value1 = 2; int value2 = 2; ViewData["Message"] = string.Format("{0} + {1} = {2}", value1, value2, Arithmetics.Add(value1, value2)); return View(); }
} // End Operator + public static MyPoint2D <T> operator +(MyPoint2D <T> point, MyVector2D <T> a) { MyPoint2D <T> p = point.Clone(); p.X = Arithmetics <T> .Add(p.X, a.X); p.Y = Arithmetics <T> .Add(p.Y, a.Y); return(p); } // End Operator +
} // End Operator != public static MyVector2D <T> operator +(MyVector2D <T> a, MyVector2D <T> b) { MyVector2D <T> v = a.Clone(); v.X = Arithmetics <T> .Add(v.X, b.X); v.Y = Arithmetics <T> .Add(v.Y, b.Y); return(v); } // End Operator +
} // End function CrossP // The dot product (also called the scalar product) is the magnitude of // vector b multiplied by the size of the projection of a onto b. // The size of the projection is a cosθ (where θ is the angle between the 2 vectors). // https://coderwall.com/p/icvt-g/2d-vector-dot-product // where theta is the angle between u and v, given by the dot product // cos(theta) = u dotp v public static T DotP(MyVector2D <T> a, MyVector2D <T> b) { T s1 = Arithmetics <T> .Multiply(a.X, b.X); T s2 = Arithmetics <T> .Multiply(a.Y, b.Y); //A * B = ax*bx+ay*by+az*bz T retValue = Arithmetics <T> .Add(s1, s2); return(retValue); } // End function DotP
} // End function Angle_Degrees public MyPoint2D <T> Schnittpunktli(MyPoint2D <T> p1, MyVector2D <T> vec1, MyPoint2D <T> p2, MyVector2D <T> vec2) { T x1 = Arithmetics <T> .Add(p1.X, vec1.X); T y1 = Arithmetics <T> .Add(p1.Y, vec1.Y); T x2 = Arithmetics <T> .Add(p2.X, vec2.X); T y2 = Arithmetics <T> .Add(p2.Y, vec2.Y); return(Schnittpunktli(p1, new MyPoint2D <T>(x1, x1), p2, new MyPoint2D <T>(x2, y2))); } // End Function Schnittpunktli
public void Math_WhenTwoCorrectNumberSumIsCorrect_TestShouldPass() { var math = new Arithmetics(); int num1; int num2; int expectedResult; num1 = 12; num2 = 8; expectedResult = 20; int actualResult = math.Add(num1, num2); Assert.AreEqual(expectedResult, actualResult); }
} // End Function ToString /// <summary> /// Returns a new Vector that is the linear blend of the 2 given Vectors /// </summary> /// <param name="a">First input vector</param> /// <param name="b">Second input vector</param> /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param> /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns> public static MyPoint2D <T> Lerp(MyPoint2D <T> a, MyPoint2D <T> b, T blend) { T bxax = Arithmetics <T> .Subtract(b.X, a.X); T byay = Arithmetics <T> .Subtract(b.Y, a.Y); T f1 = Arithmetics <T> .Multiply(blend, bxax); T f2 = Arithmetics <T> .Multiply(blend, byay); T x = Arithmetics <T> .Add(f1, a.X); T y = Arithmetics <T> .Add(f2, a.Y); return(new MyPoint2D <T>(x, y)); } // End Function Lerp
} // End Function ToString /// <summary> /// Returns a new Vector that is the linear blend of the 2 given Vectors /// </summary> /// <param name="a">First input vector</param> /// <param name="b">Second input vector</param> /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param> /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns> public static MyVector3D <T> Lerp(MyVector3D <T> a, MyVector3D <T> b, T blend) { T bxax = Arithmetics <T> .Subtract(b.X, a.X); T byay = Arithmetics <T> .Subtract(b.Y, a.Y); T bzaz = Arithmetics <T> .Subtract(b.Z, a.Z); T f1 = Arithmetics <T> .Multiply(blend, bxax); T f2 = Arithmetics <T> .Multiply(blend, byay); T f3 = Arithmetics <T> .Multiply(blend, bzaz); T x = Arithmetics <T> .Add(f1, a.X); T y = Arithmetics <T> .Add(f2, a.Y); T z = Arithmetics <T> .Add(f3, a.Z); return(new MyVector3D <T>(x, y, z)); } // End Function Lerp
static void Main(string[] args) { var math = new Arithmetics(); int num1; int num2; int sum; int sub; string temp; Console.WriteLine("Write first number:"); temp = Console.ReadLine(); num1 = int.Parse(temp); Console.WriteLine("Write second number:"); temp = Console.ReadLine(); num2 = int.Parse(temp); sum = math.Add(num1, num2); Console.WriteLine($"We added {num1} and {num2} and got --> {sum}"); sub = math.Minus(num1, num2); Console.WriteLine($"We subtract {num1} and {num2} and got --> {sub}"); }