//*************************************** // PointDistance // // use: calculates the absolute value of the distance // between two points using pythagorean theorem private float PointDistance(TwoDPoint a, TwoDPoint b) { float xDif = a.GetX() - b.GetX(); float yDif = a.GetY() - b.GetY(); return(Mathf.Sqrt((xDif * xDif) + (yDif * yDif))); }
static void Main(string[] args) { ThreeDPoint pointA = new ThreeDPoint(3, 4, 5); ThreeDPoint pointB = new ThreeDPoint(3, 4, 5); ThreeDPoint pointC = null; int i = 5; Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB)); Console.WriteLine("pointA == pointB = {0}", pointA == pointB); Console.WriteLine("null comparison = {0}", pointA.Equals(pointC)); Console.WriteLine("Compare to some other type = {0}", pointA.Equals(i)); TwoDPoint pointD = null; TwoDPoint pointE = null; Console.WriteLine("Two null TwoDPoints are equal: {0}", pointD == pointE); pointE = new TwoDPoint(3, 4); Console.WriteLine("(pointE == pointA) = {0}", pointE == pointA); Console.WriteLine("(pointA == pointE) = {0}", pointA == pointE); Console.WriteLine("(pointA != pointE) = {0}", pointA != pointE); System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add(new ThreeDPoint(3, 4, 5)); Console.WriteLine("pointE.Equals(list[0]): {0}", pointE.Equals(list[0])); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public void SetPoints(TwoDPoint[] new_points) { for (int i = 0; i < numPoints; i++) { points[i] = new TwoDPoint(new_points[i].GetX(), new_points[i].GetY()); } }
IEnumerator Coroutine_FillUpBricks() { float posx = MinX; float posy = MinY; probabilityToHideBrick = UnityEngine.Random.Range(0.0f, 0.5f); int x = 0; int y = 0; for (posx = MinX; posx <= MaxX; posx += 1.5f) { for (posy = MinY; posy <= MaxY; posy += 1.0f) { int index = UnityEngine.Random.Range(0, PrefabBricks.Length); GameObject brick = Instantiate(PrefabBricks[index], new Vector3(posx, posy, 0.0f), Quaternion.identity); Brick brickScript = brick.GetComponent <Brick>(); TwoDPoint pt = new TwoDPoint(x, y); brickScript.mPoint = pt; mBricks.Add(pt, brick); y += 1; yield return(null); } x += 1; } }
static void Main(string[] args) { TwoDPoint pointA = new TwoDPoint(3, 4); TwoDPoint pointB = new TwoDPoint(3, 4); int i = 5; // Compare using virtual Equals, static Equals, and == and != operators. // True: Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB)); // True: Console.WriteLine("pointA == pointB = {0}", pointA == pointB); // True: Console.WriteLine("Object.Equals(pointA, pointB) = {0}", Object.Equals(pointA, pointB)); // False: Console.WriteLine("pointA.Equals(null) = {0}", pointA.Equals(null)); // False: Console.WriteLine("(pointA == null) = {0}", pointA == null); // True: Console.WriteLine("(pointA != null) = {0}", pointA != null); // False: Console.WriteLine("pointA.Equals(i) = {0}", pointA.Equals(i)); // CS0019: // Console.WriteLine("pointA == i = {0}", pointA == i); // Compare unboxed to boxed. System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add(new TwoDPoint(3, 4)); // True: Console.WriteLine("pointE.Equals(list[0]): {0}", pointA.Equals(list[0])); // Compare nullable to nullable and to non-nullable. TwoDPoint?pointC = null; TwoDPoint?pointD = null; // False: Console.WriteLine("pointA == (pointC = null) = {0}", pointA == pointC); // True: Console.WriteLine("pointC == pointD = {0}", pointC == pointD); TwoDPoint temp = new TwoDPoint(3, 4); pointC = temp; // True: Console.WriteLine("pointA == (pointC = 3,4) = {0}", pointA == pointC); pointD = temp; // True: Console.WriteLine("pointD == (pointC = 3,4) = {0}", pointD == pointC); // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }
public bool Equals(TwoDPoint p) { // If parameter is null return false: if ((object)p == null) { return(false); } // Return true if the fields match: return((x == p.x) && (y == p.y)); }
static void Main(string[] args) { TwoDPoint pointA = new TwoDPoint(3, 4); TwoDPoint pointB = new TwoDPoint(3, 4); int i = 5; // True: Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB)); // True: Console.WriteLine("pointA == pointB = {0}", pointA == pointB); // True: Console.WriteLine("object.Equals(pointA, pointB) = {0}", object.Equals(pointA, pointB)); // False: Console.WriteLine("pointA.Equals(null) = {0}", pointA.Equals(null)); // False: Console.WriteLine("(pointA == null) = {0}", pointA == null); // True: Console.WriteLine("(pointA != null) = {0}", pointA != null); // False: Console.WriteLine("pointA.Equals(i) = {0}", pointA.Equals(i)); // CS0019: // Console.WriteLine("pointA == i = {0}", pointA == i); // Compare unboxed to boxed. System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add(new TwoDPoint(3, 4)); // True: Console.WriteLine("pointA.Equals(list[0]): {0}", pointA.Equals(list[0])); // Compare nullable to nullable and to non-nullable. TwoDPoint?pointC = null; TwoDPoint?pointD = null; // False: Console.WriteLine("pointA == (pointC = null) = {0}", pointA == pointC); // True: Console.WriteLine("pointC == pointD = {0}", pointC == pointD); TwoDPoint temp = new TwoDPoint(3, 4); pointC = temp; // True: Console.WriteLine("pointA == (pointC = 3,4) = {0}", pointA == pointC); pointD = temp; // True: Console.WriteLine("pointD == (pointC = 3,4) = {0}", pointD == pointC); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
private void varInitialization() { currentPoint = new TwoDPoint(0, 0); startPoint = new TwoDPoint(0, 0); currentPointList = new List <TwoDPoint>(); currentPointList.Add(new TwoDPoint(0, 0)); reducedPoints = new TwoDPoint[pointsPerGesture]; for (int i = 0; i < pointsPerGesture; i++) { reducedPoints[i] = new TwoDPoint(0, 0); } gestureStarted = false; gestureComplete = false; inputReady = false; currentGesture = new DrawnGesture("currentGesture", pointsPerGesture); }
public override bool Equals(System.Object obj) { if (obj == null) { return(false); } TwoDPoint p = obj as TwoDPoint; if (p == null) { return(false); } // Return true if the fields match return((x == p.x) && (y == p.y)); }
//*************************************** // MapPoints // // use: maps the list of recorded points to a desired // number of points by calculating an even distance // between such a number of points and interpolating // when that distance is reached upon traversal of the // list // Called after scaling on every gesture // // param: gesture: the object to store the new array private void MapPoints(DrawnGesture gesture) { reducedPoints[0].SetX(currentPointList[0].GetX()); reducedPoints[0].SetY(currentPointList[0].GetY()); int newIndex = 1; float totalDistance = TotalDistance(); float coveredDistance = 0; float thisDistance = 0; float idealInterval = totalDistance / pointsPerGesture; for (int i = 0; i < currentPointList.Count - 1; i++) { thisDistance = PointDistance(currentPointList[i], currentPointList[i + 1]); bool passedIdeal = (coveredDistance + thisDistance) >= idealInterval; if (passedIdeal) { TwoDPoint reference = currentPointList[i]; while (passedIdeal && newIndex < reducedPoints.Length) { float percentNeeded = (idealInterval - coveredDistance) / thisDistance; if (percentNeeded > 1f) { percentNeeded = 1f; } if (percentNeeded < 0f) { percentNeeded = 0f; } float new_x = (((1f - percentNeeded) * reference.GetX()) + (percentNeeded * currentPointList[i + 1].GetX())); float new_y = (((1f - percentNeeded) * reference.GetY()) + (percentNeeded * currentPointList[i + 1].GetY())); reducedPoints[newIndex] = new TwoDPoint(new_x, new_y); reference = reducedPoints[newIndex]; newIndex++; thisDistance = (coveredDistance + thisDistance) - idealInterval; coveredDistance = 0; passedIdeal = (coveredDistance + thisDistance) >= idealInterval; } coveredDistance = thisDistance; } else { coveredDistance += thisDistance; } gesture.SetPoints(reducedPoints); } }
public override bool Equals(System.Object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to Point return false. TwoDPoint p = obj as TwoDPoint; if ((System.Object)p == null) { return(false); } // Return true if the fields match: return((x == p.x) && (y == p.y)); }