Exemplo n.º 1
0
 public void Point()
 {
     //Do various Point method calls to cover the point class with sufficient testing
     Point p0 = new Point();
     Point p1 = new Point(0, 0);
     Point p2 = new Point(450, 120);
     Assert.IsTrue(p0.IsEmpty());
     Assert.IsFalse(p1.IsEmpty());
     Assert.AreNotEqual(p0, p1);
     Assert.AreEqual(450, p2.X);
     Assert.AreEqual(120, p2.Y);
     Assert.AreNotSame(p2.Clone(), p2);
     p0 = p2.Clone();
     p0.X += 100;
     p0.Y = 150;
     p0[0] += p0[1];
     Assert.AreEqual(new Point(700, 150), p0);
     Assert.AreEqual(p2, p2.GetBoundingBox().Min);
     Assert.AreEqual(p2, p2.GetBoundingBox().Max);
     Assert.IsTrue(p2.IsSimple());
     Assert.IsFalse(p2.IsEmpty());
     Assert.AreEqual(2, p2.NumOrdinates);
     Assert.AreEqual(new Point(400, 100), p2 + new Point(-50, -20));
     Assert.AreEqual(new Point(500, 100), p2 - new Point(-50, 20));
     Assert.AreEqual(new Point(900, 240), p2*2);
     Assert.AreEqual(0, p2.Dimension);
     Assert.AreEqual(450, p2[0]);
     Assert.AreEqual(120, p2[1]);
     Assert.IsNull(p2.Boundary());
     Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
     Assert.Greater(p2.CompareTo(p1), 0);
     Assert.Less(p1.CompareTo(p2), 0);
     Assert.AreEqual(p2.CompareTo(new Point(450, 120)), 0);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a new shape object.
        /// </summary>
        /// <param name="shapeMode">The desired shape.</param>
        public GMareCollision(Point[] points)
        {
            // Set nodes.
            _points = (Point[])points.Clone();

            // Set node rectangles.
            SetNodes();
        }
 public IObjectiveFunction Fork()
 {
     return(new ForwardDifferenceGradientObjectiveFunction(this.InnerObjectiveFunction.Fork(), LowerBound, UpperBound, this.RelativeIncrement, this.MinimumIncrement)
     {
         Point = Point?.Clone(),
         GradientEvaluated = GradientEvaluated,
         ValueEvaluated = ValueEvaluated,
         _gradient = _gradient?.Clone()
     });
 }
Exemplo n.º 4
0
        public void DoIt()
        {
            var point = new Point();
            point.Desc.Name = "point one";
            point.Desc.UId = "1-2-3";
            point.X = 10;
            point.Y = 20;

            var point2 = (Point)point.Clone();
            point2.Desc.Name = "point two";
            point2.X = 200;

            Console.Out.WriteLine(point);
            Console.Out.WriteLine(point2);
        }
Exemplo n.º 5
0
        private void CalculateCollision(Vector velocity, LWShape target)
        {
            if (target == null)
            {
                return;
            }

            Distance min = new Distance
            {
                x = float.MaxValue,
                y = float.MaxValue
            };
            Point       collisionPoint = Point.CreateInvalidPoint();
            LineSegment collisionLine  = null;

            foreach (LineSegment originalLineSegment in _shape)
            {
                foreach (LineSegment targetLineSegment in target.GetSegments())
                {
                    Point originalPoint = originalLineSegment.from;

                    if (target.IsWithIn(originalPoint) &&
                        !target.IsWithIn(originalPoint + velocity))
                    {
                        continue;
                    }

                    LineSegment trajectory = LineSegment.Create(
                        originalPoint, originalPoint + velocity
                        );
                    Point intersection = LWCollide.Math.Intersection(trajectory, targetLineSegment);

                    if (intersection.IsInvalidPoint())
                    {
                        continue;
                    }

                    if (Distance.Create(originalPoint, intersection).GetPower() < min.GetPower())
                    {
                        collisionPoint = intersection;
                        min            = Distance.Create(originalPoint, intersection);
                    }

                    collisionLine = targetLineSegment.Clone();
                }
            }

            // does not collide
            if (collisionPoint.IsInvalidPoint() ||
                collisionLine == null)
            {
                _cache.Register(
                    _shape,
                    target.GetSegments(),
                    _position,
                    target.GetPosition(),
                    velocity,
                    collisionPoint.Clone(),
                    min.Clone(),
                    Vector.Create(),
                    Vector.Create());

                return;
            }


            float primaryVectorLength   = (float)System.Math.Sqrt((double)min.GetPower());
            float secondaryVectorLength = (float)System.Math.Sqrt((double)velocity.GetPower()) - primaryVectorLength;

            Vector primaryVector   = velocity * (float)(primaryVectorLength / System.Math.Sqrt((double)velocity.GetPower()));
            Vector secondaryVector = LWCollide.Math.GetLineVector(velocity, collisionLine) * secondaryVectorLength;

            _cache.Register(
                _shape,
                target.GetSegments(),
                _position,
                target.GetPosition(),
                velocity,
                collisionPoint.Clone(),
                min.Clone(),
                primaryVector,
                secondaryVector);
        }
Exemplo n.º 6
0
        public static Area GetArea(int rotation, Point lineEnd)
        {
            Point topLeft = lineEnd.Clone();
            Point bottomRight = lineEnd.Clone();
            if (rotation == (int) ArrowDirection.Up)
            {
                topLeft.Offset(-(ArrowHeight / 2), -ArrowWidth);
                bottomRight.Offset(ArrowHeight / 2, 0);
            } else if (rotation == (int) ArrowDirection.Down)
            {
                topLeft.Offset(-(ArrowHeight / 2), 0);
                bottomRight.Offset(ArrowHeight / 2, ArrowWidth);
            } else if (rotation == (int) ArrowDirection.Right)
            {
                topLeft.Offset(0, -(ArrowHeight / 2));
                bottomRight.Offset(ArrowWidth, ArrowHeight / 2);
            } else if (rotation == (int) ArrowDirection.Left)
            {
                topLeft.Offset(-(ArrowWidth), -(ArrowHeight / 2));
                bottomRight.Offset(0, ArrowHeight / 2);
            }

            return new Area(topLeft, bottomRight);
        }
Exemplo n.º 7
0
 public Area(Point topLeft, Point bottomRight)
 {
     TopLeft = topLeft.Clone();
     BottomRight = bottomRight.Clone();
 }
Exemplo n.º 8
0
 public Point GetPosition()
 {
     return(_position.Clone());
 }
Exemplo n.º 9
0
        private static List <Point> RenderPoints(bool[,] maze, IMazeOptions options, int mazeWidth, int mazeLength)
        {
            var outer = options.Thickness;
            var inner = options.InnerThickness;

            var points = new List <Point>();

            for (var z = 1; z < mazeLength - 1; z += 2)
            {
                for (var x = 1; x < mazeWidth - 1; x += 2)
                {
                    var cellX   = (x - 1) / 2;
                    var cellZ   = (z - 1) / 2;
                    var topleft = new Point
                    {
                        X         = options.X + cellX * (outer + inner),
                        Y         = options.Y,
                        Z         = options.Z + cellZ * (outer + inner),
                        BlockName = options.Block
                    };

                    if (maze[x, z - 1]) // top
                    {
                        for (var x2 = 0; x2 < outer + outer + inner; x2++)
                        {
                            for (var z2 = 0; z2 < outer; z2++)
                            {
                                var cell = topleft.Clone();
                                cell.X += x2;
                                cell.Z += z2;
                                points.Add(cell);
                            }
                        }
                    }
                    if (maze[x, z + 1]) // bottom
                    {
                        for (var x2 = 0; x2 < outer + outer + inner; x2++)
                        {
                            for (var z2 = outer + inner; z2 < outer + outer + inner; z2++)
                            {
                                var cell = topleft.Clone();
                                cell.X += x2;
                                cell.Z += z2;
                                points.Add(cell);
                            }
                        }
                    }
                    if (maze[x - 1, z]) // left
                    {
                        for (var z2 = 0; z2 < outer + outer + inner; z2++)
                        {
                            for (var x2 = 0; x2 < outer; x2++)
                            {
                                var cell = topleft.Clone();
                                cell.X += x2;
                                cell.Z += z2;
                                points.Add(cell);
                            }
                        }
                    }
                    if (maze[x + 1, z]) // right
                    {
                        for (var z2 = 0; z2 < outer + outer + inner; z2++)
                        {
                            for (var x2 = outer + inner; x2 < outer + outer + inner; x2++)
                            {
                                var cell = topleft.Clone();
                                cell.X += x2;
                                cell.Z += z2;
                                points.Add(cell);
                            }
                        }
                    }
                }
            }

            // raise the maze
            if (options.Height == 1)
            {
                return(points.Distinct().ToList());
            }

            var ypoints = new List <Point>();

            for (var y = 0; y < options.Height; y++)
            {
                foreach (var p in points.Distinct())
                {
                    var yp = p.Clone();
                    yp.Y = options.Y + y;
                    ypoints.Add(yp);
                }
            }

            return(ypoints);
        }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (moving != null)                                                 // jeśli bool moving jest rózny on null
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);     //inicjalizuj wektor kierunkowy
            Vector2 ndir = dir.normalized;                                  //utwórz wektor jednostkowy z "dir"
            Vector2 adir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); //utwórz wektor o wartościach zawsze dodatnich

            NewIndex = Point.Clone(moving.index);                           // skopiuj obecną wartość index do nowej zmiennej
            Point add = Point.Zero;                                         // utworz nowy punkt o wspolrzednych (0,0)

            //uproszcznie wzglednej pozycji myszki wokol punktu odniesienia do GORA DOL PRAWO LEWO
            switch (CheckPositionOnBoard(NewIndex))
            {
            case 1:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                            // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : 0, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                       // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : 0)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                   //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 2:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : 0, 0));  //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 0 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 3:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 0 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 0 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 4:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 0 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : 0));  //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 5:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : 0));  //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 6:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : 0, 0));  //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 7:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 0 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 8:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 0 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }

            case 9:
            {
                if (dir.magnitude > 16)
                {
                    if (adir.x > adir.y)                             // jezeli w wektorze [x,y] : |x| > |y|
                    {
                        add = (new Point((ndir.x > 0) ? 1 : -1, 0)); //to zmienna "add" jest punktem (1 dla ndir.x > 0 oraz -1 dla ndir.x < 0 , 0)
                    }
                    else if (adir.y > adir.x)                        // jezeli w wektorze [x,y] : |x| < |y|
                    {
                        add = (new Point(0, (ndir.y > 0) ? 1 : -1)); //to zmienna "add" jest punktem (0, 1 dla ndir.y > 0 oraz -1 dla ndir.y < 0)
                    }
                }                                                    //jeżeli dlugosc wektora kierunkowego jest > 16 to:
                break;
            }
            } // ogranicz tworzenie wektora kierunkowego w zależnoeści od pozycji na planszy

            NewIndex.Add_indirect(add); // dodaj do zmiennej typu Point NewIndex zmienną add, jeden z wariantów : (1,0), (-1,0), (0,1), (0,-1)
            Vector2 pos = game.GetPositionFromPoint(moving.index);
            //utwórz wektor[x,y] "pos" o wartosci pozycji obecnego elementu.
            //GameBoard game -> GetPostiionFromPoint ( TilePiece moving -> index (Point))

            if (!NewIndex.Equals(moving.index))             //jezeli funkcja NewIndex typu Point zwroci true to :
            {
                pos += Point.Multiply(add, 10).ToVector();  //dodaj do zmiennej "pos" typu Vector2 nowy wektor kierunkowy o dlugosci 10
            }

            moving.MovePositionTo(pos); //uzyj funkcji MovePositionTo z parametrem pos typu Vector2 ze zmiennej moving typu TilePiece
        }
    }
Exemplo n.º 11
0
        public void Clone_a_valid_point_should_equal()
        {
            var point = new Point(100, 50);

            point.Clone().Equals(point).Should().BeTrue();
        }
Exemplo n.º 12
0
        public static Point[] SphericalDensify(Point p0, Point p1, double length, Unit unit)
        {
            Point xyz0 = SphToCart3d(p0, unit);
            Point xyz1 = SphToCart3d(p1, unit);

            double dot01     = Dot(xyz0, xyz1);
            double angle01   = Math.Acos(dot01);
            double threshold = ToRadian(length, unit);

            int n = (int)(angle01 / threshold);

            if (n < 1)
            {
                return(new Point[0]);
            }

            // make sure the number of additional points is even
            // this way there will always be a segment in the middle
            // and something may be drawn there
            if (n % 2 != 0)
            {
                ++n;
            }

            Point axis;

            if (!Equals(angle01, Math.PI))
            {
                axis = Cross(xyz0, xyz1);
                VecNormalize(axis);
            }
            else
            {
                double halfPi = HalfAngle(unit) / 2;
                if (Equals(p0[1], halfPi))
                {
                    axis = new Point(0, 1, 0);
                }
                else if (Equals(p0[1], -halfPi))
                {
                    axis = new Point(0, -1, 0);
                }
                else
                {
                    double lon = ToRadian(p0[0], unit);
                    axis = new Point(Math.Sin(lon), -Math.Cos(lon), 0);
                }
            }

            double step = angle01 / (n + 1);

            Point[] result = new Point[n];

            double a = step;

            for (int i = 0; i < n; ++i, a += step)
            {
                // Axis-Angle rotation
                // see: https://en.wikipedia.org/wiki/Axis-angle_representation
                double cos_a = Math.Cos(a);
                double sin_a = Math.Sin(a);
                // cos_a * v
                Point s1 = xyz0.Clone();
                Mul(s1, cos_a);
                // sin_a * (n x v)
                Point s2 = Cross(axis, xyz0);
                Mul(s2, sin_a);
                // (1 - cos_a)(n.v) * n
                Point s3 = axis.Clone();
                Mul(s3, (1.0 - cos_a) * Dot(axis, xyz0));
                // v_rot = cos_a * v + sin_a * (n x v) + (1 - cos_a)(n.v) * e
                Point v_rot = s1.Clone();
                Add(v_rot, s2);
                Add(v_rot, s3);

                result[i] = Cart3dToSph(v_rot, unit);
            }

            return(result);
        }
Exemplo n.º 13
0
        private static void Free()
        {
            var arrivedPosition = new Point()
            {
                y            = robotPosition.y,
                type         = 1,
                x            = robotPosition.x,
                parent       = (Point)robotPosition.Clone(),
                backtracking = robotPosition.backtracking
            };

            switch (direction)
            {
            case "U": arrivedPosition.y++; if (!arrivedPosition.backtracking)
                {
                    q.Push(arrivedPosition.Down(true));
                }
                break;

            case "D": arrivedPosition.y--; if (!arrivedPosition.backtracking)
                {
                    q.Push(arrivedPosition.Up(true));
                }
                break;

            case "R": arrivedPosition.x++; if (!arrivedPosition.backtracking)
                {
                    q.Push(arrivedPosition.Left(true));
                }
                break;

            case "L": arrivedPosition.x--; if (!arrivedPosition.backtracking)
                {
                    q.Push(arrivedPosition.Right(true));
                }
                break;
            }
            passedCoordinates.Add(arrivedPosition);
            if (passedCoordinates.Find(x => x.x == arrivedPosition.x && x.y == arrivedPosition.y + 1) is null)
            {
                var test = arrivedPosition.Up(false);
                q.Push(test);
            }
            if (passedCoordinates.Find(x => x.x == arrivedPosition.x && x.y == arrivedPosition.y - 1) is null)
            {
                q.Push(arrivedPosition.Down(false));
            }
            if (passedCoordinates.Find(x => x.x == arrivedPosition.x - 1 && x.y == arrivedPosition.y) is null)
            {
                q.Push(arrivedPosition.Left(false));
            }
            if (passedCoordinates.Find(x => x.x == arrivedPosition.x + 1 && x.y == arrivedPosition.y) is null)
            {
                q.Push(arrivedPosition.Right(false));
            }

            robotPosition.x            = arrivedPosition.x;
            robotPosition.y            = arrivedPosition.y;
            robotPosition.backtracking = arrivedPosition.backtracking;
            robotPosition.parent       = (Point)robotPosition.Clone();
        }
Exemplo n.º 14
0
 public Node(float position, TNodePayload payload, Point point)
 {
     Position = Math.Round(position, 3).ToFloat();
     Payload  = payload;
     Point    = point.Clone();
 }
Exemplo n.º 15
0
 private Point[] refine_center(Point[] last_center, Image<Gray, Byte> img)
 {
     Point[] center = last_center.Clone() as Point[];
     for (int iter = 0; iter < 3; iter++)
     {
         for (int i = 0; i < 2; i++)
         {
             Rectangle ROI = new Rectangle(Math.Max(center[i].X - 50,0),Math.Max( center[i].Y - 50,0),Math.Min(center[i].X+50,img.Width),Math.Min(center[i].Y+50,img.Height));
             ROI.Width -= ROI.X;
             ROI.Height -= ROI.Y;
             try
             {
                 Emgu.CV.CvInvoke.cvSetImageROI(img, ROI);
                 if (img.GetMoments(false).GravityCenter.x > 0)
                 {
                     center[i].X = ROI.X + (int)img.GetMoments(false).GravityCenter.x;
                     center[i].Y = ROI.Y + (int)img.GetMoments(false).GravityCenter.y;
                 }
             }
             catch { }
             Emgu.CV.CvInvoke.cvResetImageROI(img);
         }
     }
     return center;
 }
 private PolygonRegularizer(Point[] vertices)
 {
     this.vertices = (Point[])vertices.Clone();
 }
Exemplo n.º 17
0
    public static void Main()
    {
        Point p1 = new Point(50, 50);
        Point p2 = p1;
        p2.X = 0;
        Console.WriteLine(p1);
        Console.WriteLine(p2);

        Point p3 = new Point(100, 100);
        Point p4 = (Point) p3.Clone();
        p4.Y = 0;
        Console.WriteLine(p3);
        Console.WriteLine(p4);

        Point2 p5 = new Point2(100, 100, "Jane");
        Point2 p6 = (Point2) p5.Clone();
        Console.WriteLine(p5);
        Console.WriteLine(p6);
        p6.desc.PetName = "My new Point2";
        p6.X = 9;
        Console.WriteLine(p5);
        Console.WriteLine(p6);
    }
Exemplo n.º 18
0
 /// <summary>
 /// Clones this instance.
 /// </summary>
 /// <returns></returns>
 public ICoordinate Clone()
 {
     return(new Coordinate(_point.Clone()));
 }
Exemplo n.º 19
0
        private void FindPointsInRange(IAxis x_axis, IAxis y_axis, out Point[] points)
        {
            points = new Point[0];

            if ((x_axis == null || !x_axis.HasValidRange) ||
                (y_axis == null || !y_axis.HasValidRange))
            {
                // we need both axes to be valid to draw anything
                return;
            }

            ArrayList points_list = new ArrayList();

            TreeIter iter;

            if (!model.GetIterFirst(out iter))
            {
                return;
            }

            Point prev_point = null;

            do
            {
                IComparable x_val, y_val;
                if (!GetValue(iter, 0, out x_val) ||
                    !GetValue(iter, 1, out y_val))
                {
                    continue;
                }

                // don't clip a gapped point
                if (PointGapFunc != null &&
                    PointGapFunc(model, iter))
                {
                    if (x_axis.IsInRange(x_val))
                    {
                        Point p = new Point(x_axis.ValueToGridCoords(x_val),
                                            y_axis.ValueToGridCoords(y_val),
                                            x_val, y_val);
                        p.IsAGap = true;
                        points_list.Add(p);
                    }
                    continue;
                }

                // create a line segment between the previous
                // point and the current point and see if the
                // segment intersects the viewing plane
                Point b = new Point(x_axis.ValueToGridCoords(x_val),
                                    y_axis.ValueToGridCoords(y_val),
                                    x_val, y_val);
                Point a = new Point(b.X, b.Y, b.XValue, b.YValue);

                if (prev_point != null)
                {
                    a = prev_point;
                }

                // copy b before it becomes clipped
                prev_point = b.Clone() as Point;

                TreePath path = model.GetPath(iter);
                if (selected_path != null &&
                    selected_path.Compare(path) == 0)
                {
                    b.IsSelected = true;
                }

                if (focused_path != null &&
                    focused_path.Compare(path) == 0)
                {
                    b.IsFocused = true;
                }

                if (ClipSegment(x_axis, y_axis, ref a, ref b))
                {
                    if (a != b && a.IsClipped)
                    {
                        points_list.Add(a);
                    }

                    points_list.Add(b);
                }
            } while (model.IterNext(ref iter));

            // Sort this list on the x axis
            points_list.Sort(new PointXAxisIComparer());

            points = (Point[])points_list.ToArray(typeof(Point));
        }
Exemplo n.º 20
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Point SetGeometry(this Point point, Point newPoint)
        {
            return(newPoint.Clone());
        }
Exemplo n.º 21
0
 public Point CopyCenter()
 {
     return(_center.Clone());
 }
Exemplo n.º 22
0
        /// <summary>
        /// Find the nearest point.
        /// </summary>
        public Point Interpolate(Point start, Point finish, int axissIndex, double?isolevel = null)
        {
            var    startValue  = start.Get(axissIndex) > finish.Get(axissIndex) ? finish.Get(axissIndex) : start.Get(axissIndex);
            var    finishValue = start.Get(axissIndex) > finish.Get(axissIndex) ? start.Get(axissIndex) : finish.Get(axissIndex);
            var    curA        = startValue;
            var    curB        = finishValue;
            double funcA       = 0;
            double funcB       = 0;
            double calcA       = 0;
            double calcB       = 0;

            var point = start.Clone();
            // Some constants
            var c          = (3 - Math.Sqrt(5)) / 2;
            var fi         = (Math.Sqrt(5) + 1) / 2;
            var calculated = Calculated.FirstIteration;

            for (; ;)
            {
                if ((curB - curA < accuracyEpsilon) && calculated != Calculated.FirstIteration)
                {
                    var pointToReturn = point.Clone();
                    if (GetNearestOrMin(funcA, funcB, isolevel))
                    {
                        pointToReturn.Set(axissIndex, curA);
                    }
                    else
                    {
                        pointToReturn.Set(axissIndex, curB);
                    }

                    return(pointToReturn);
                }

                calcA = curA + c * (curB - curA);
                point.Set(axissIndex, calcA);

                var toSet = Calc(point);
                calcB = curA + (1 - c) * (curB - curA);
                point.Set(axissIndex, calcB);

                var toSet2 = Calc(point);

                if (toSet.HasValue)
                {
                    funcA = toSet.Value;
                }

                if (toSet2.HasValue)
                {
                    funcB = toSet2.Value;
                }


                var forcedExit = false;
                if (!toSet.HasValue || !toSet2.HasValue)
                {
                    // Cannot calculate the value. Get the nearest value and exit.
                    forcedExit = true;
                }

                var result = GetNearestOrMin(funcA, funcB, isolevel);

                if (result)
                {
                    curB = calcB;

                    // This will exit from the function.
                    if (forcedExit)
                    {
                        curA = curB;
                    }

                    calculated = Calculated.B;
                }
                else
                {
                    curA = calcA;

                    if (forcedExit)
                    {
                        curB = curA;
                    }

                    calculated = Calculated.A;
                }
            }
        }
Exemplo n.º 23
0
 public Point[] RecalibratePolygon(Point[] akershusPoly)
 {
     Point[] tempList = (Point[])akershusPoly.Clone();
     //for (int i = 0; i < tempList.Length; i++)
     //{
     //    tempList[i].X = tempList[i].X + m_game.MapProvider.Map.Rectangle.X;
     //    tempList[i].Y = tempList[i].Y + m_game.MapProvider.Map.Rectangle.Y;
     //}
     for (int i = 0; i < tempList.Length; i++)
     {
         tempList[i] = RecalibratePoint( tempList[i] );
     }
     return tempList;
 }
Exemplo n.º 24
0
        /***************************************************/

        private static double ShearAreaLine(Point ptA, Point ptB, double s, double tol = Tolerance.Distance)
        {
            //TODO Should do some checks if these are good Tolerances
            Point a = ptA.Clone();
            Point b = ptB.Clone();

            double axbx = a.X - b.X;

            if (Math.Abs(axbx) < tol)  // The solution is zero
            {
                return(0);
            }

            double byay = b.Y - a.Y;
            double ax2  = Math.Pow(a.X, 2);
            double ay2  = Math.Pow(a.Y, 2);

            double horizTol = -Math.Min(b.Y, a.Y) * 0.003;   // the bigger function becomes erratic under thease valuse (tested value)

            horizTol = horizTol < tol ? tol : horizTol;

            if (Math.Abs(byay) < horizTol)  // The solution for a "constant" integral, i.e. horizontal line
            {
                return((axbx) * (
                           10 * a.Y * Math.Pow(axbx, 2) * (3 * ax2 * a.Y - 2 * s)
                           - 30 * a.X * a.Y * axbx * (ax2 * a.Y - 2 * s)
                           + 15 * Math.Pow(ax2 * a.Y - 2 * s, 2)
                           + 3 * ay2 * Math.Pow(axbx, 4)
                           - 15 * a.X * ay2 * Math.Pow(axbx, 3)
                           ) / (60 * a.Y));
            }

            if (a.Y > -tol)  //Everithing should happen below the X-axis
            {
                a.Y  = -tol;
                ay2  = Math.Pow(a.Y, 2);
                byay = b.Y - a.Y;
            }
            if (b.Y > -tol)  // and these should never be zero
            {
                b.Y  = -tol;
                byay = b.Y - a.Y;
            }
            // if this change made (Math.Abs(byay) < Tolerance.MicroDistance) = true it is problem


            double ax3 = Math.Pow(a.X, 3);

            double bx2 = Math.Pow(b.X, 2);
            double bx3 = Math.Pow(b.X, 3);

            double ay3 = Math.Pow(a.Y, 3);

            double by2 = Math.Pow(b.Y, 2);
            double by3 = Math.Pow(b.Y, 3);

            double byay2 = Math.Pow(byay, 2);

            // Formula derivation outlined in https://github.com/BHoM/documentation/wiki/Shear-Area-Derivation
            double A =
                -(
                    20 * Math.Pow(axbx, 2) *
                    (24 * s * byay2 + a.Y *
                     (
                         -39 * by2 * ax2 + 6 * b.Y * a.X * a.Y * (14 * a.X - b.X) +
                         ay2 * (-44 * ax2 + 4 * a.X * b.X + bx2)
                     )
                    )
                    )
                / (byay2);
            double B =
                -(
                    30 * axbx *
                    (a.Y *
                     (
                         18 * by3 * ax3
                         + 3 * by2 * ax2 * a.Y * (5 * b.X - 23 * a.X)
                         + 6 * b.Y * a.X * ay2 * (13 * ax2 - 3 * a.X * b.X - bx2)
                         + ay3 * (-28 * ax3 + 6 * ax2 * b.X + 3 * a.X * bx2 + bx3)
                     )
                     - 12 * s * byay2 * (3 * b.Y * a.X + a.Y * (b.X - 4 * a.X))
                    )
                    )
                / (Math.Pow(byay, 3));
            double C =
                (
                    60 * a.Y * axbx *
                    (a.Y * (2 * a.X + b.X) - 3 * b.Y * a.X)
                    * (a.Y *
                       (
                           6 * by2 * ax2
                           - 3 * b.Y * a.X * a.Y * (3 * a.X + b.X)
                           + ay2 * (4 * ax2 + a.X * b.X + bx2)
                       )
                       - 12 * s * byay2
                       )
                )
                / (Math.Pow(byay, 4));
            double D =
                (
                    60 * Math.Log(b.Y / a.Y)
                    * Math.Pow(
                        a.Y * (3 * by2 * ax2 - 3 * b.Y * a.X * a.Y * (a.X + b.X)
                               + ay2 * (ax2 + a.X * b.X + bx2))
                        - 6 * s * byay2
                        , 2)
                )
                / (Math.Pow(byay, 5));
            double E =
                40 * byay * Math.Pow(axbx, 4)
                - 48 * Math.Pow(axbx, 3) * (3 * b.Y * a.X - 5 * a.X * a.Y + 2 * a.Y * b.X)
                + (15 * Math.Pow(axbx, 2)
                   * (
                       9 * by2 * ax2
                       - 6 * b.Y * a.X * a.Y * (8 * a.X - 5 * b.X)
                       + ay2 * (40 * ax2 - 32 * a.X * b.X + bx2))
                   ) / (byay);

            double factor = (axbx / 2160);

            return((A + B + C + D + E) * factor);
        }
Exemplo n.º 25
0
 public static Geometry Intersection(Point point1, Point point2)
 {
     return(point2.IsIntersects(point1) ? point1.Clone() : null);
 }
Exemplo n.º 26
0
        public static bool EnumeratePointsBetween(Point from, Point to, double maxDelta, PointDelegate callback)
        {
            if (from.Equals(to))
                return callback(from.Clone());

            var c = (int)(from.GetDistanceTo(to) / maxDelta + 2);
            maxDelta = from.GetDistanceTo(to) / c;
            var dir = (to - from).Normalized();
            for (var i = 0; i <= c; i++)
            {
                // from + dir * (maxDelta * i)
                if (!callback(new Point(from.X + dir.X * maxDelta * i, from.Y + dir.Y * maxDelta * i)))
                    return false;
            }
            return true;
        }
Exemplo n.º 27
0
        public void DrawNavSymbol(Graphics g, SolidBrush sb, int x, int y, Point[] symbol, Orientation or, bool SkyDir, bool shrink)
        {
            Point[] pa = (Point[])symbol.Clone();
            int len = pa.Length;

            for (int i = 0; i < len; i++)
            {
                switch (or)
                {
                    case Orientation.mirrorX:
                        pa[i].X = NavSymbol_size - pa[i].X;
                        break;
                    case Orientation.mirrorY:
                        pa[i].Y = NavSymbol_size - pa[i].Y;
                        break;
                    case Orientation.right:
                        pa[i].Y = symbol[i].X;
                        pa[i].X = NavSymbol_size - symbol[i].Y;
                        break;
                    case Orientation.left:
                        pa[i].Y = NavSymbol_size - symbol[i].X;
                        pa[i].X = symbol[i].Y;
                        break;
                }
                if (SkyDir)
                    if (or == Orientation.right || or == Orientation.left)
                        pa[i].Y -= NavSymbol_size / 5;
                    else
                        pa[i].X -= NavSymbol_size / 5;
                if (shrink)
                {
                    pa[i].X /= 2;
                    pa[i].Y /= 2;
                }
                pa[i].X += x;
                pa[i].Y += y;
            }
            Pen pen = new Pen(Color.Black, NavSymbol_size / (shrink ? 24 : 12));
            g.DrawPolygon(pen, pa);
            g.FillPolygon(sb, pa);
            if (symbol == arrow_to)
            {
                DrawNavSymbol(g, sb, x, y, line_to, or, false, shrink);     //draw other parts of symbol
                if (SkyDir)
                {
                    string s;
                    int dx, dy;
                    float fontsize;
                    int quot;
                    switch (or)
                    {
                        case Orientation.normal: s = "N"; dx = 60; dy = 50; break;
                        case Orientation.left: s = "W"; dx = 50; dy = 50; break;
                        case Orientation.right: s = "E"; dx = 0; dy = 40; break;
                        case Orientation.mirrorY: s = "S"; dx = 60; dy = -10; break;
                        default: s = ""; dx = x; dy = y; break;
                    }
                    if (shrink)
                    { fontsize = 8; quot = 200; }
                    else
                    { fontsize = 20; quot = 100; }
                    Font font = new Font("Arial", fontsize * parent.df, FontStyle.Bold);
                    dx = dx * NavSymbol_size / quot + x;
                    dy = dy * NavSymbol_size / quot + y;
                    g.DrawString(s, font, sb, dx, dy);
                }
            }
        }
 internal void SetLocation(Point p)
 {
     location = p.Clone();
 }
Exemplo n.º 29
0
        /// <summary>
        /// position = sign((Bx - Ax) * (Y - Ay) - (By - Ay) * (X - Ax))
        /// </summary>
        /// <param name="jointPosition"></param>
        /// <param name="endPoint"></param>
        /// <returns></returns>
        public Quadrant InWhichQuadrant(Point jointPosition, Point endPoint)
        {
            var normalVectorPoint1 = jointPosition.Clone();
            var normalVectorPoint2 = CalculateNormalVectorPoint(normalVectorPoint1);
            var infinityFlag       = false;

            if (double.IsInfinity(normalVectorPoint2.Y))
            {
                infinityFlag = true;
            }


            var jointQuadrant = InWhichQuadrant(jointPosition);
            var pointX        = 0;
            var pointXn       = 0;

            switch (jointQuadrant)
            {
            case Quadrant.I:
                pointX  = 50;
                pointXn = -50;
                break;

            case Quadrant.II:
                pointX  = 50;
                pointXn = -50;
                break;

            case Quadrant.III:
                pointX  = -50;
                pointXn = 50;
                break;

            case Quadrant.IV:
                pointX  = -50;
                pointXn = 50;
                break;
            }

            var vectorXPoint1 = jointPosition;
            var vectorXPoint2 = CalculatePointFromEquation(pointX, zeroPoint, jointPosition);

            normalVectorPoint2 = infinityFlag ? new Point()
            {
                X = normalVectorPoint2.X, Y = jointPosition.X
            } : CalculatePointFromEquation(pointXn, normalVectorPoint1, normalVectorPoint2);
            if (Equals(vectorXPoint2, default(Point)) || Equals(normalVectorPoint2, default(Point)))
            {
                return(Quadrant.None);
            }

            var positionByX = PositionSignByVector(vectorXPoint1, vectorXPoint2, endPoint);
            var positionByY = PositionSignByVector(normalVectorPoint1, normalVectorPoint2, endPoint);

            switch (positionByX)
            {
            case 0:
            case 1:
                return(positionByY <= 0 ? Quadrant.I : Quadrant.II);

            case -1:
                return(positionByY >= 0 ? Quadrant.III : Quadrant.IV);

            default: return(Quadrant.None);
            }
        }
Exemplo n.º 30
0
 public APuck(Point pos, Point speed, Point goalie)
     : base(pos, speed, 0)
 {
     if (goalie != null)
         Goalie = goalie.Clone();
 }
Exemplo n.º 31
0
 public Area(Point topLeft, double actualWidth, double actualHeight)
 {
     TopLeft = topLeft.Clone();
     BottomRight = new Point(TopLeft.X + actualWidth, TopLeft.Y + actualHeight);
 }