Esempio n. 1
0
        private void BuildRing(HalfEdge eStartRing)
        {
            CoordinateList line = new CoordinateList();
            HalfEdge       e    = eStartRing;

            Coordinate orig = e.Orig;

            line.Add(orig.Clone(), false);
            // scan along the path until a node is found (if one exists)
            while (e.Sym.Degree() == 2)
            {
                HalfEdge eNext = e.Next;
                // check if edges form a ring - if so, we're done
                if (eNext == eStartRing)
                {
                    break;
                }

                // add point to line, and move to next edge
                orig = eNext.Orig;
                line.Add(orig.Clone(), false);
                e = eNext;
            }
            // add final node
            Coordinate dest = e.Dest;

            line.Add(dest.Clone(), false);

            // store the scanned line
            AddLine(line);
        }
Esempio n. 2
0
        public override MapObject Copy(IDGenerator generator)
        {
            var e = new Entity(generator.GetNextObjectID())
            {
                GameData   = GameData,
                EntityData = EntityData.Clone(),
                Origin     = Origin.Clone()
            };

            CopyBase(e, generator);
            return(e);
        }
Esempio n. 3
0
        public void TestClone()
        {
            Coordinate c     = new Coordinate(100.0, 200.0, 50.0);
            Coordinate clone = (Coordinate)c.Clone();

            Assert.IsTrue(c.Equals3D(clone));
        }
Esempio n. 4
0
        private IPolygon CreateSelectionPolygon(Coordinate worldPosition)
        {
            if (MultiSelectionMode == MultiSelectionMode.Rectangle)
            {
                if (0 == Math.Abs(mouseDownLocation.X - worldPosition.X))
                {
                    return(null);
                }
                if (0 == Math.Abs(mouseDownLocation.Y - worldPosition.Y))
                {
                    return(null);
                }
                return(CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X),
                                     Math.Max(mouseDownLocation.Y, worldPosition.Y),
                                     Math.Max(mouseDownLocation.X, worldPosition.X),
                                     Math.Min(mouseDownLocation.Y, worldPosition.Y)));
            }
            var vertices = selectPoints.Select(point => Map.ImageToWorld(point)).ToList();

            if (vertices.Count == 1)
            {
                // too few points to create a polygon
                return(null);
            }
            vertices.Add((Coordinate)worldPosition.Clone());
            vertices.Add((Coordinate)vertices[0].Clone());
            ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());

            return(GeometryFactory.CreatePolygon(newLinearRing, null));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="errorType"></param>
 /// <param name="pt"></param>
 public TopologyValidationError(TopologyValidationErrors errorType, Coordinate pt)
 {
     this.errorType = errorType;
     if (pt != null)
     {
         this.pt = (Coordinate)pt.Clone();
     }
 }
Esempio n. 6
0
        public void EqualOperator_Works()
        {
            Coordinate coor1      = new Coordinate(0, 1);
            Coordinate coor1Clone = (Coordinate)coor1.Clone();

            (coor1 == coor1Clone).Should().BeTrue();
            (coor1 == new Coordinate(coor1.X + 1, coor1.Y)).Should().BeFalse();
        }
Esempio n. 7
0
        public void CloneTest()
        {
            var    target   = new Coordinate(5, 15);
            object expected = new Coordinate(5, 15);

            object actual = target.Clone();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 8
0
        public void CloneTest()
        {
            var target = new Coordinate(5, 15);
            object expected = new Coordinate(5, 15);

            object actual = target.Clone();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 9
0
        public ValidationError(ValidationErrorType errorType, Coordinate pt)
        {
            if (pt == null)
            {
                throw new ArgumentNullException("pt");
            }

            this.errorType = errorType;
            this.pt        = pt.Clone();
        }
Esempio n. 10
0
        public virtual object Clone()
        {
            Line l = new Line();

            l.Coordinate = Coordinate.Clone() as AxisCoordinate;
            l.LineWidth  = LineWidth;
            l.MarkColor  = MarkColor;
            l.Text       = Text;

            return(l);
        }
Esempio n. 11
0
        public void test_Clone()
        {
            //create a coordinate
            Coordinate coord = new Coordinate(testX, testY, testZ);

            //create a new coordinate by cloning the first
            Coordinate coord2 = coord.Clone() as Coordinate;

            //check that the values are the same
            Assertion.AssertEquals("Clone: ", true, coord.Equals(coord2));
        }
Esempio n. 12
0
    public Coordinate fixedCoordinate(Coordinate coor)
    {
        if (t.InMap(coor) == true)
        {
            return(coor.Clone());
        }
        int x, y;

        x = Mathf.Clamp(coor.x, 0, t.UnitCounts.x - 1);
        y = Mathf.Clamp(coor.y, 0, t.UnitCounts.y - 1);
        return(new Coordinate(x, y));
    }
Esempio n. 13
0
 private void SetClickOnExistingSelection(bool set, Coordinate worldPosition)
 {
     clickOnExistingSelection = set;
     if (clickOnExistingSelection)
     {
         orgMouseDownLocation = (Coordinate)worldPosition.Clone();
     }
     else
     {
         orgMouseDownLocation = null;
     }
 }
        /// <summary>
        /// Move the last coordinate added
        /// </summary>
        /// <param name="worldCoord">The new position</param>
        internal override void MoveCoordinate(Coordinate worldCoord)
        {
            if (LastCoordinate != null)
            {
                var coordinates = this.Coordinates;

                LastMouseCoordinate = worldCoord.Clone();

                ActiveCollection.MovedCoordinate(coordinates, LastMouseCoordinate);

                CreateFeatureGeometry();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Builds a line starting from the given edge.
        /// The start edge origin is a node (valence = 1 or >= 3),
        /// unless it is part of a pure ring.
        /// </summary>
        /// <remarks>
        /// A pure ring has no other incident lines.
        /// In this case the start edge may occur anywhere on the ring.
        /// </remarks>
        /// <remarks>
        /// The line is built up to the next node encountered,
        /// or until the start edge is re-encountered
        /// (which happens if the edges form a ring).
        /// </remarks>
        /// <param name="eStart"></param>
        private void BuildLine(HalfEdge eStart)
        {
            CoordinateList   line = new CoordinateList();
            DissolveHalfEdge e    = (DissolveHalfEdge)eStart;

            _ringStartEdge = null;

            MarkHalfEdge.MarkBoth(e);
            Coordinate orig = e.Orig;

            line.Add(orig.Clone(), false);
            // scan along the path until a node is found (if one exists)
            while (e.Sym.Degree() == 2)
            {
                UpdateRingStartEdge(e);
                DissolveHalfEdge eNext = (DissolveHalfEdge)e.Next;
                // check if edges form a ring - if so, we're done
                if (eNext == eStart)
                {
                    BuildRing(_ringStartEdge);
                    return;
                }
                // add point to line, and move to next edge
                orig = eNext.Orig;
                line.Add(orig.Clone(), false);
                e = eNext;
                MarkHalfEdge.MarkBoth(e);
            }
            // add final node
            Coordinate dest = e.Dest;

            line.Add(dest.Clone(), false);

            // queue up the final node edges
            StackEdges(e.Sym);
            // store the scanned line
            AddLine(line);
        }
Esempio n. 16
0
        public void ClonedCoordinateMustHaveSameXAndYThanOriginal()
        {
            // Given
            int        coordX   = 10;
            int        coordY   = 20;
            Coordinate original = new Coordinate(coordX, coordY);

            // When
            Coordinate copied = original.Clone();

            // Then
            Assert.IsTrue(original.X == coordX, "Cloned X must be same as Original X");
            Assert.IsTrue(original.Y == coordY, "Cloned Y must be same as Original Y");
        }
        public static Coordinate FindElement2(int[,] matrix, Coordinate origin, Coordinate dest, int x)
        {
            if (!origin.Inbounds(matrix) || !dest.Inbounds(matrix))
            {
                return(null);
            }
            if (matrix[origin.row, origin.column] == x)
            {
                return(origin);
            }
            else if (!origin.IsBefore(dest))
            {
                return(null);
            }

            /* Set start to start of diagonal and end to the end of the diagonal. Since
             * the grid may not be square, the end of the diagonal may not equal dest.
             */
            Coordinate start    = (Coordinate)origin.Clone();
            int        diagDist = Math.Min(dest.row - origin.row, dest.column - origin.column);
            Coordinate end      = new Coordinate(start.row + diagDist, start.column + diagDist);
            Coordinate p        = new Coordinate(0, 0);

            /* Do binary search on the diagonal, looking for the first element greater than x */
            while (start.IsBefore(end))
            {
                p.SetToAverage(start, end);
                if (x > matrix[p.row, p.column])
                {
                    start.row    = p.row + 1;
                    start.column = p.column + 1;
                }
                else
                {
                    end.row    = p.row - 1;
                    end.column = p.column - 1;
                }
            }

            /* Split the grid into quadrants. Search the bottom left and the top right. */
            return(PartitionAndSearch(matrix, origin, dest, start, x));
        }
Esempio n. 18
0
        public static List <Coordinate> GetCoordinates(Coordinate topLeft, int length, Alignment alignment)
        {
            var coordinates = new List <Coordinate>();
            var horizontal  = alignment == Alignment.Horizontal;

            for (int i = 0; i < length; i++)
            {
                var newCoordinate = (Coordinate)topLeft.Clone();
                if (horizontal)
                {
                    newCoordinate.XCoordinate += i;
                }
                else
                {
                    newCoordinate.YCoordinate += i;
                }
                coordinates.Add(newCoordinate);
            }
            return(coordinates);
        }
Esempio n. 19
0
        private IsoscelesRightTriangle CreateTriangleFromCoordinates(Coordinate coor1, Coordinate coor2,
                                                                     Coordinate coor3, string label)
        {
            //right sight up triangle:
            Coordinate newCoor1 = (Coordinate)coor1.Clone();
            Coordinate newCoor2 = (Coordinate)coor2.Clone();
            Coordinate newCoor3 = (Coordinate)coor3.Clone();

            List <Coordinate> triangleCoorindates = new List <Coordinate>
            {
                newCoor1,
                newCoor2,
                newCoor3
            };


            var newTriangle = new IsoscelesRightTriangle(_properties.NonHypotenuseSideLengthInPixels, triangleCoorindates, label);

            return(newTriangle);
        }
Esempio n. 20
0
        public Page MovePageUnit(Page page, Coordinate from, Coordinate to)
        {
            var pageUnits = page.Contents[from.X, from.Y];

            foreach (var pageUnit in pageUnits)
            {
                pageUnit.Coordinate = (Coordinate)to.Clone();

                if (page.Contents[to.X, to.Y] == null)
                {
                    page.Contents[to.X, to.Y] = new List <PageUnit>();
                }

                page.Contents[to.X, to.Y].Add(pageUnit);
            }

            page.Contents[from.X, from.Y] = null;

            return(page);
        }
Esempio n. 21
0
        public void ClonedClass_ShouldBe_DecoupledFromOriginalClass()
        {
            // Arrange
            int originalX  = 10;
            int originalY  = 20;
            int clonedX    = 2000;
            int clonedY    = 3000;
            var coordinate = new Coordinate(originalX, originalY);
            // Act
            var coordinateClone = coordinate.Clone() as Coordinate;

            coordinateClone.X = clonedX;
            coordinateClone.Y = clonedY;
            // Assert
            Assert.IsNotNull(coordinateClone);
            // Original object should not be touched
            Assert.AreEqual(originalX, coordinate.X);
            Assert.AreEqual(originalY, coordinate.Y);
            Assert.AreEqual(clonedX, coordinateClone.X);
            Assert.AreEqual(clonedY, coordinateClone.Y);
        }
        /// <summary>
        /// Add a world coordinate to the measurer
        /// </summary>
        internal override void AddCoordinate(Coordinate worldCoord)
        {
            if (ActiveCollection.CanAddCoordinate())
            {
                var coordinates = this.Coordinates;
                if (LastCoordinate == null)
                {
                    ActiveCollection.CoordinateSystem = this.CoordinateSystem;
                    ActiveCollection.Transform        = this.PixelToWorldTransform;
                    coordinates.Clear();
                }

                var coordinateToAdd = worldCoord.Clone();
                coordinates.Add(coordinateToAdd);

                ActiveCollection.AddedCoordinate(coordinates, coordinateToAdd);
                LastCoordinate = coordinateToAdd;

                CreateFeatureGeometry();
            }
        }
Esempio n. 23
0
        private static Coordinate findMyPivot(double[,] matrix, double target, Coordinate s, Coordinate e)
        {
            if ((!s.inBound(matrix)) || (!e.inBound(matrix)))
            {
                return(null);
            }
            else if (matrix[s.col, s.row] == target)
            {
                return(s);
            }
            else if (!s.isBefore(e))
            {
                return(null);
            }
            Coordinate ss     = s.Clone();
            int        DisCol = e.col - s.col;
            int        DisRow = e.row - s.row;
            int        Dis    = System.Math.Min(DisCol, DisRow);
            Coordinate ee     = new Coordinate(s.col + Dis, s.row + Dis);
            Coordinate p      = new Coordinate();

            while (ss.isBefore(ee))
            {
                p.setToMid(ss, ee);
                if (target > matrix[p.col, p.row])
                {
                    ss.col = p.col + 1;
                    ss.row = p.row + 1;
                }
                else
                {
                    ee.col = p.col - 1;
                    ee.row = p.col - 1;
                }
            }

            return(ss);
        }
Esempio n. 24
0
        private static ILineString AppendCurvePoint(ILineString lineString, Coordinate worldPos)
        {
            List <Coordinate> vertices = new List <Coordinate>();

            for (int i = 0; i < lineString.Coordinates.Length; i++)
            {
                if (1 == i)
                {
                    // remove duplicate start points, see MouseDown
                    if ((lineString.Coordinates[0].X != lineString.Coordinates[1].X) &&
                        (lineString.Coordinates[0].Y != lineString.Coordinates[1].Y))
                    {
                        vertices.Add(lineString.Coordinates[i]);
                    }
                }
                else
                {
                    vertices.Add(lineString.Coordinates[i]);
                }
            }
            vertices.Add((Coordinate)worldPos.Clone());
            return(GeometryFactory.CreateLineString(vertices.ToArray()));
        }
Esempio n. 25
0
        public Coordinate Transform(Coordinate coordinate)
        {
            var xy = new[] { coordinate.X, coordinate.Y };

            double[] z = null;
            if (!coordinate.Z.Equals(Coordinate.NullOrdinate))
            {
                z = new[] { coordinate.Z }
            }
            ;

            Reproject.ReprojectPoints(xy, z, Source, Target, 0, 1);

            var ret = (Coordinate)coordinate.Clone();

            ret.X = xy[0];
            ret.Y = xy[1];
            if (z != null)
            {
                ret.Z = z[0];
            }

            return(ret);
        }
Esempio n. 26
0
        private static Coordinate findMyPivot(double[,] matrix, double target, Coordinate s, Coordinate e)
        {
            if ((!s.inBound(matrix)) || (!e.inBound(matrix)))
            {
                return null;
            }
            else if (matrix[s.col, s.row] == target)
            {
                return s;
            }
            else if (!s.isBefore(e))
            {
                return null;
            }
            Coordinate ss = s.Clone();
            int DisCol = e.col - s.col;
            int DisRow = e.row - s.row;
            int Dis = System.Math.Min(DisCol, DisRow);
            Coordinate ee = new Coordinate(s.col + Dis, s.row + Dis);
            Coordinate p = new Coordinate();
            while (ss.isBefore(ee))
            {
                p.setToMid(ss, ee);
                if (target > matrix[p.col, p.row])
                {
                    ss.col = p.col + 1;
                    ss.row = p.row + 1;
                }
                else
                {
                    ee.col = p.col - 1;
                    ee.row = p.col - 1;
                }
            }

            return ss;
        }
Esempio n. 27
0
 public void Clone_should_create_a_new_instance_of_Coordinate()
 {
     coordinate.Clone()
     .Should().Not.Be.SameInstanceAs(coordinate);
 }
Esempio n. 28
0
    /*
     * La génétation du chemin comprend l'algorithme A*
     * et la construction de la chaine de déplacement pour se rendre du départ à l'arrivé en remontant l'analyse de A*
     */
    private void PathGeneration()
    {
        cible  = new Coordinate(x_cible, y_cible);
        depart = new Coordinate(x_depart, y_depart);


        //graph (contient les obstacles)

        int infini = (largeur * hauteur) ^ 2;

        Dictionary <int, Coordinate> Q_listeDeSommet = new Dictionary <int, Coordinate>();
        Dictionary <Coordinate, int> dT = new Dictionary <Coordinate, int>(); //Coordinate S1, int ordre_de_vérification
        Dictionary <Coordinate, int> dH = new Dictionary <Coordinate, int>(); //Coordinate S1, int fonction_de_cout (et valeur infini2 pour les obstacles)

        cheminInverse = new Dictionary <Coordinate, int>();


        //populer la liste Q de tout les sommets du graph

        for (int i = 0; i < largeur * hauteur; i++)
        {
            Q_listeDeSommet[i] = new Coordinate();
        }


        int k_indexe = 0;

        for (int l = 0; l < largeur; l++)
        {
            for (int h = 0; h < hauteur; h++)
            {
                Coordinate coordinate = new Coordinate(l, h);

                Q_listeDeSommet[k_indexe] = coordinate;

                if (graph[coordinate]) //obstacle
                {
                    dH[coordinate] = infini * 2;
                }

                dT[coordinate] = infini;

                if (!dH.ContainsKey(coordinate)) // si il n'y a pas déjà un obstacle
                {
                    //la fonction de coût est la distance pythagorienne entre le sommet actuel et le sommet d'arrivé

                    int delta_x = (x_cible - l) * (x_cible - l);
                    int delta_y = (y_cible - h) * (y_cible - h);

                    int fonction_h = (int)(Mathf.Sqrt(delta_x + delta_y));
                    dH[coordinate] = fonction_h;
                }

                k_indexe++;
            }
        }

        dT[depart] = 0; //l'ordre de la case de départ est 0

        bool fin = false;


        int tour = 0;

        while (Q_listeDeSommet.Count > 0 && !fin)
        {
            tour++;

            int valeurMin  = infini * 4;
            int indexeMinQ = 0;               //WARNING

            Coordinate s1 = new Coordinate(); // (0,0)

            foreach (KeyValuePair <int, Coordinate> sommet in Q_listeDeSommet)
            {
                try
                {
                    if ((dT[sommet.Value] + dH[sommet.Value]) < valeurMin)
                    {
                        valeurMin  = dT[sommet.Value] + dH[sommet.Value];
                        indexeMinQ = sommet.Key;

                        s1.Clone(sommet.Value);
                    }
                }
                catch (KeyNotFoundException)
                {
                    //la position de i à été supprimé
                }
            }


            //la cible est-elle atteinte?
            if (cible.Equals(s1))
            {
                fin = true;
            }



            //on retire s1 de Q
            bool indexeRemoved = false;
            indexeRemoved = Q_listeDeSommet.Remove(indexeMinQ);



            //on ajoute s1 au graph cheminInverse
            //contruit le graph qui servira à remonter l'ordre T en fesait ainsi le chemin inverse.
            cheminInverse[s1] = dT[s1];



            //check et assigner l'ordre T les quatres directions haut, droit, bas, gauche

            Coordinate haut   = new Coordinate(s1.X, s1.Y + 1);
            Coordinate droit  = new Coordinate(s1.X + 1, s1.Y);
            Coordinate bas    = new Coordinate(s1.X, s1.Y - 1);
            Coordinate gauche = new Coordinate(s1.X - 1, s1.Y);

            //haut
            try
            {
                if (dT[haut] > dT[s1] + 1 && dH[haut] < infini * 2)
                {
                    dT[haut] = dT[s1] + 1;
                }
            }
            catch (KeyNotFoundException)
            {
                //s1 est en haut du graph
            }

            //droite
            try
            {
                if (dT[droit] > dT[s1] + 1 && dH[droit] < infini * 2)
                {
                    dT[droit] = dT[s1] + 1;
                }
            }
            catch (KeyNotFoundException)
            {
                //s1 est à droite du graph
            }

            //bas
            try
            {
                if (dT[bas] > dT[s1] + 1 && dH[bas] < infini * 2)
                {
                    dT[bas] = dT[s1] + 1;
                }
            }
            catch (KeyNotFoundException)
            {
                //s1 est en bas du graph
            }

            //gauche
            try
            {
                if (dT[gauche] > dT[s1] + 1 && dH[gauche] < infini * 2)
                {
                    dT[gauche] = dT[s1] + 1;
                }
            }
            catch (KeyNotFoundException)
            {
                //s1 est à gauche du graph
            }
        }


        //faire le chemin inverse
        Coordinate positionChemin = new Coordinate();

        positionChemin.Clone(cible); //on commence par la fin, par la cible

        int indexPath = 0;


        //on remonte le chemin et on arrête à la position de depart
        while (!positionChemin.Equals(depart))
        {
            Vector2Int direction = new Vector2Int();
            int        ordreMin  = infini;

            //check et assigner l'ordre T les quatres directions haut, droit, bas, gauche

            Coordinate haut   = new Coordinate(positionChemin.X, positionChemin.Y + 1);
            Coordinate droit  = new Coordinate(positionChemin.X + 1, positionChemin.Y);
            Coordinate bas    = new Coordinate(positionChemin.X, positionChemin.Y - 1);
            Coordinate gauche = new Coordinate(positionChemin.X - 1, positionChemin.Y);

            //haut
            try
            {
                if (ordreMin > cheminInverse[haut])
                {
                    ordreMin  = cheminInverse[haut];
                    direction = Vector2Int.down; //chemin inverse
                }
            }
            catch (KeyNotFoundException)
            {
                //la position en haut n'a pas d'ordre
            }

            //droite
            try
            {
                if (ordreMin > cheminInverse[droit])
                {
                    ordreMin  = cheminInverse[droit];
                    direction = Vector2Int.left; //chemin inverse
                    //direction = Vector2Int.right;
                }
            }
            catch (KeyNotFoundException)
            {
                //la position à droite n'a pas d'ordre
            }

            //bas
            try
            {
                if (ordreMin > cheminInverse[bas])
                {
                    ordreMin  = cheminInverse[bas];
                    direction = Vector2Int.up; //chemin inverse
                    //direction = Vector2Int.down;
                }
            }
            catch (KeyNotFoundException)
            {
                //la position en bas n'a pas d'ordre
            }

            //gauche
            try
            {
                if (ordreMin > cheminInverse[gauche])
                {
                    ordreMin  = cheminInverse[gauche];
                    direction = Vector2Int.right; //chemin inverse
                    //direction = Vector2Int.left;
                }
            }
            catch (KeyNotFoundException)
            {
                //la position à gauche n'a pas d'ordre
            }

            if (direction == Vector2Int.down)
            {
                //la position actu a monté
                positionChemin.Y++;
            }
            else if (direction == Vector2Int.left)
            {
                //la position actu est allé vers la droite
                positionChemin.X++;
            }
            else if (direction == Vector2Int.up)
            {
                //la position actu a dessendu
                positionChemin.Y--;
            }
            else if (direction == Vector2Int.right)
            {
                //la position actu est allé vers la gauche
                positionChemin.X--;
            }

            path[indexPath] = direction;
            //
            indexPath++;
        }
    }
 /// <summary>
 /// Initializes a new instance of the TopologyValidationError class.
 /// </summary>
 public TopologyValidationError(int errorType, Coordinate pt)
 {
     this._errorType = errorType;
     this._pt        = (Coordinate)pt.Clone();
 }