Example #1
0
        /// <summary>
        /// Plot vector nodes to the Eucledian plain.
        /// </summary>
        /// <param name="vector">A vector Node/Coordinate.</param>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.DimensionException">Thrown when invalid number of dimensions.</exception>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.CoordinateException">Thrown when coordinates are missing.</exception>
        /// <exception cref="OctagonSquare.ProximityMatch.Exceptions.UniqueIdException">Thrown when uniqueId is exists.</exception>
        public void Plot(IVector vector, out long uniqueid)
        {
            try
            {
                if (this.Dimension != vector.Coordinate.Length)
                {
                    throw new DimensionException("Invalid dimension!!.");
                }

                if (this.Dimension < 2)
                {
                    throw new DimensionException("Atleast two dimensions are required!!.");
                }

                if (!vector.Coordinate.All(x => x.HasValue))
                {
                    throw new CoordinateException("Missing coordinate.");
                }

                if (vector.UniqueId <= 0)
                {
                    vector.UniqueId = GenerateUniqueId();
                }

                //All good, try create a vector node/coordinate now.

                if (this.ItemDictionary.ContainsKey(vector.UniqueId))
                {
                    throw new UniqueIdException("UniqueId already exist!!.");
                }

                this.ItemDictionary.Add(vector.UniqueId, vector.Copy <IVector>());
                uniqueid = vector.UniqueId;

                var vectorNode = new VectorNode(
                    uniqueid: vector.UniqueId,
                    angles: GenerateAngles(vector),
                    distance: EuclideanDistance(vector.Coordinate, CreateDouble(vector.Coordinate.Length))
                    );

                //Indexing vectors based on cos(beta) angle and Euclidean distance from orgin.
                var angleKey             = Math.Truncate(vectorNode.Angles[0]);
                var distanceFromOrginKey = Math.Truncate(vectorNode.DistanceFromOrgin / 10);

                if (this.VectorDictionary.ContainsKey(angleKey))
                {
                    if (this.VectorDictionary[angleKey].ContainsKey(distanceFromOrginKey))
                    {
                        this.VectorDictionary[angleKey][distanceFromOrginKey].Add(vectorNode);
                    }
                    else
                    {
                        this.VectorDictionary[angleKey].Add(distanceFromOrginKey, new List <VectorNode> {
                            vectorNode
                        });
                    }
                }
                else
                {
                    var distanceFromOrginDictionary = new Dictionary <double, List <VectorNode> >();
                    distanceFromOrginDictionary.Add(distanceFromOrginKey, new List <VectorNode>()
                    {
                        vectorNode
                    });
                    this.VectorDictionary.Add(angleKey, distanceFromOrginDictionary);
                }

                //Build indexes.
                AddIndex(vector);

                mu += angleKey;
                n++;

                //Ploting done!! now fire the finished event.
                PlotingFinishedEvent(new PlotEventArgs(vectorNode));
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Example #2
0
 public UpdateEventArgs(VectorNode _vnode, bool?_status = null)
     : base(_vnode.UniqueId)
 {
     vnode  = _vnode;
     status = _status;
 }