internal Common.LineSegment GetReturnLine(LineSegment incoming)
 {
     if (overrideMagnitude == double.MinValue)
         return new LineSegment(incoming.EndingPos, ReturnAngle, incoming.Magnitude());
     else
         return new LineSegment(incoming.EndingPos, ReturnAngle, overrideMagnitude); ;
 }
 public LineSegment GetReflectionLine()
 {
     if(reflectionLine == null) {
         reflectionLine = new LineSegment(segmentToReturnOn.Magnitude(), lineToCenter.Angle().Adjust(new Angle(90, true)), incomingPath.EndingPos);
     }
     return reflectionLine;
 }
 public void op_SubtractionTest()
 {
     LineSegment a = new LineSegment(new Vector(3, 2), new Vector(1, 5));
     LineSegment b = new LineSegment(new Vector(1, 2), new Vector(6, 9));
     LineSegment expected = null;
     LineSegment actual;
     actual = (a - b);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        public bool PassedEscapedFromEllipseTest(System.Windows.Media.Geometry geometry, LineSegment path)
        {
            if (this == null)
                throw new NullReferenceException();

            var intersect2 = geometry.FillContainsWithDetail(
                    new System.Windows.Media.RectangleGeometry(GetReturnLine(path).AsSystemRect()));
            if (intersect2 != System.Windows.Media.IntersectionDetail.Empty) {
                return false;
            } else return true;
        }
 internal void InitiateRandomWalk(Vector startingPosition = null, double stepSize = 5, int numberOfSteps = 100000)
 {
     this.numberOfSteps = numberOfSteps;
     startingPosition = CurrentPosition;
     if (startingPosition == null) {
         CurrentPosition = new Vector(boardBounds.Width / 2, boardBounds.Height / 2);
     }
     Vector endingPosition = null;
     for (stepCounter = 0; stepCounter < numberOfSteps; stepCounter++) {
         double angleToWalk = newDirectionGenerator();
         double x2 = CurrentPosition.GetX() + stepSize * Math.Cos(angleToWalk);
         double y2 = CurrentPosition.GetY() + stepSize * Math.Sin(angleToWalk);
         endingPosition = new Vector(x2, y2);
         LineSegment newPath = new LineSegment(CurrentPosition, endingPosition);
         pathWalker(newPath, Color.Blue);
         testForCollisionAndAdd(newPath);
     }
 }
 public void SetLineFromAngleAlone(LineSegment incomingPath)
 {
 }
 public ReflectionReturnValue(Angle angle, LineSegment lineToCenter)
 {
     this.Angle = angle;
     this.lineToCenter = lineToCenter;
 }
 public void Add(LineSegment addMe)
 {
     fullPath.Add(addMe);
 }
        private void testForCollisionAndAdd(LineSegment path)
        {
            ReflectionReturnValue reflectedLine = null;
            foreach (IObstruction obst in obstructions) {
                reflectedLine = obst.TestForCollision(path);
                if (reflectedLine != null && reflectedLine.Angle != null && stepCounter < numberOfSteps) {
                    reflectedLine.SetLineFromAngleAlone(path);
                    reflectedLine.PrintReflectionLine(g);
                    pathWalker(reflectedLine.GetLineToReturnOn(), Color.Red);
                    //LineSegment reflectedLine = new LineSegment(path.EndingPos, angleToReturnOn, path.Magnitude());
                    //pathWalker(reflectedLine, Color.Red);

                    testForCollisionAndAdd(reflectedLine.GetLineToReturnOn());
                }
            }
        }
 private bool youGotOutOfTheEllipse(LineSegment resultantVector)
 {
     if (Geometry.FillContainsWithDetail(resultantVector.AsLineGeometry()) != System.Windows.Media.IntersectionDetail.Empty) {
         return false;
     } else return true;
 }
 private Vector checkForPassedWalls(LineSegment path)
 {
     Vector newEndPoint = null;
     if (path.EndingPos.GetX() > Map.Width) {
         horizBoardIdx++;
         newEndPoint = new Vector(path.EndingPos.GetX() - Map.Width, path.EndingPos.GetY());
     }
     if (path.EndingPos.GetX() < 0) {
         horizBoardIdx--;
         newEndPoint = new Vector(path.EndingPos.GetX() + Map.Width, path.EndingPos.GetY());
     }
     if (path.EndingPos.GetY() > Map.Height) {
         vertBoardIdx++;
         newEndPoint = new Vector(path.EndingPos.GetX(), path.EndingPos.GetY() - Map.Height);
     }
     if (path.EndingPos.GetY() < 0) {
         vertBoardIdx--;
         newEndPoint = new Vector(path.EndingPos.GetX(), path.EndingPos.GetY() + Map.Height);
     }
     return newEndPoint;
 }
 private void testForCollisionAndAdd(LineSegment path)
 {
     ReflectedLine reflectedLine = null;
     Rectangle rectOfCentersToCheck = getRectangleForCentersToCheck(path);
     foreach (IObstruction obst in obstructions.Where(i => rectOfCentersToCheck.ContainsPoint(i.CenterPoint))) {
         reflectedLine = obst.TestForCollision(path);
         if (reflectedLine != null && reflectedLine.ReturnAngle != null && stepCounter < numberOfSteps) {
             if (!reflectedLine.PassedEscapedFromEllipseTest(obst.Geometry, path)) {
                 //This means we didn't get away
                 //Print relevant error data!!
                 pathWalker(reflectedLine.GetReturnLine(path), Color.Green);
                 //stepCounter = numberOfSteps;
             } else {
                 pathWalker(reflectedLine.GetReturnLine(path), Color.Red);
                 testForCollisionAndAdd(reflectedLine.GetReturnLine(path));
             }
         }
     }
 }
 private void pathWalker(LineSegment path, Color color)
 {
     stepCounter++;
     if (color == null)
         color = Color.Brown;
     printToBoard(path, color);
     fullPath.Add(path);
     var newEndPt = checkForPassedWalls(path);
     if (newEndPt == null)
         CurrentPosition = path.EndingPos;
     else CurrentPosition = newEndPt;
 }
 private Rectangle getRectangleForCentersToCheck(LineSegment path)
 {
     int leftEdge = (int)path.EndingPos.GetX() - Map.AxisMax;
     if (leftEdge < 0)
         leftEdge += Map.Width;
     int topEdge = (int)path.EndingPos.GetY() - Map.AxisMax;
     if (topEdge < 0)
         topEdge += Map.Height;
     int width = Map.AxisMax * 2;
     if (width + leftEdge > Map.Width)
     {}
     int height = Map.AxisMax * 2;
     if(height + topEdge > Map.Height)
     {}
     return new Rectangle(leftEdge, topEdge, height, width);
     //TODO: This code is buggy/not working and must be fixed!! The bounding rectangle of centers should wrap around the borders!!!!
 }
 public ReflectionReturnValue TestForCollision(LineSegment path)
 {
     var rectangle = new System.Windows.Rect((int)path.EndingPos.GetX(), (int)path.EndingPos.GetY(), 1,0);
     var intersect = Geometry.FillContainsWithDetail(new System.Windows.Media.RectangleGeometry(rectangle));
     if (intersect != System.Windows.Media.IntersectionDetail.Empty) {
         Angle incomingLineAngle = 180 - path.Angle();
         Angle incidentAngle = path.AngleBetweenPoints(CenterPoint);
         Debug.Print("Angle of incoming line: " +incomingLineAngle.ToString());
         Debug.Print("Angle to center line: " + incidentAngle.InDegrees().ToString());
         Angle returnAngle = path.Angle() - incidentAngle * 2;
         Debug.Print("Return Angle: " + returnAngle.ToString());
         return new ReflectionReturnValue(returnAngle, new LineSegment(CenterPoint, path.EndingPos));
     }
     return null;
 }
 public ReflectionReturnValue TestForCollision(LineSegment path)
 {
     Angle angleToReturnOn = null;
     if (path.Angle().InRadians() == 0)
         throw new Exception("This should never happen!");
     if (path.EndingPos.GetX() <= BoundingRectangle.Left || path.EndingPos.GetX() >= BoundingRectangle.Right){
         angleToReturnOn =new Angle(path.YComponent(), -path.XComponent());
     }
     if (path.EndingPos.GetY() >= BoundingRectangle.Bottom) {
         angleToReturnOn= new Angle(-path.YComponent(), path.XComponent());
     }
     if (path.EndingPos.GetY() <= BoundingRectangle.Top) {
         angleToReturnOn = new Angle(path.YComponent(), path.XComponent()).Negate();
     }
     return new ReflectionReturnValue(angleToReturnOn);
 }
Esempio n. 17
0
 public void ReflectLineTest()
 {
     Vector start = null; // TODO: Initialize to an appropriate value
     Vector end = null; // TODO: Initialize to an appropriate value
     LineSegment target = new LineSegment(start, end); // TODO: Initialize to an appropriate value
     LineSegment lineToReflectOver = null; // TODO: Initialize to an appropriate value
     LineSegment expected = null; // TODO: Initialize to an appropriate value
     LineSegment actual;
     actual = target.ReflectOverLineThroughOrigin(lineToReflectOver);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 private void pathWalker(LineSegment path, Color color)
 {
     stepCounter++;
     if (color == null)
         color = Color.Brown;
     printToBoard(path, color);
     fullPathWalked.Add(path);
     CurrentPosition = path.EndingPos;
 }
 private void printToBoard(LineSegment path, Color color)
 {
     Point startingPoint = new Point((int)path.StartingPos.GetX(), (int)path.StartingPos.GetY());
     Point endingPoint = new Point((int)path.EndingPos.GetX(), (int)path.EndingPos.GetY());
     g.DrawLine(new System.Drawing.Pen(color, 1f), startingPoint, endingPoint);
 }
        public ReflectedLine TestForCollision(Common.LineSegment path)
        {
            var intersect = Geometry.FillContainsWithDetail(new System.Windows.Media.RectangleGeometry(path.AsSystemRect()));
            if (intersect != System.Windows.Media.IntersectionDetail.Empty) {
                Angle incidentAngle = path.AngleBetweenPoints(CenterPoint);
                Angle incidentAngleTimesTwo = incidentAngle * 2;
                Angle threesixtyMinus = (new Angle(360, true) - incidentAngleTimesTwo);

                Common.LineSegment lineToCenter = new Common.LineSegment(path.EndingPos, CenterPoint);
                Angle oneEighty = new Angle(180, true);
                //SEARCH FOR THE RETURN ANGLE:
                var outLine = computeReturnAngle(oneEighty, path.Angle(), threesixtyMinus, incidentAngle, path);
                if (outLine != null)
                    return outLine;
                outLine = computeReturnAngle(oneEighty, path.Angle(), -threesixtyMinus, incidentAngle, path);
                if (outLine != null)
                    return outLine;

                outLine.Extend(path.Magnitude());
                outLine = computeReturnAngle(oneEighty, path.Angle(), threesixtyMinus, incidentAngle, path);
                if (outLine != null && outLine.PassedEscapedFromEllipseTest(Geometry, path) == true)
                    return outLine;
                outLine = computeReturnAngle(oneEighty, path.Angle(), -threesixtyMinus, incidentAngle, path);
                if (outLine != null && outLine.PassedEscapedFromEllipseTest(Geometry, path) == true)
                    return outLine;
                throw new Exception();
            }
            return null;
        }