Пример #1
0
        /// <summary>
        /// Moves the port on the link and optionally reconnects to a new
        /// port.
        /// </summary>
        /// <param name="cmdTarget">Unused</param>
        /// <returns>true if successful, otherwise false</returns>
        /// <remarks>
        /// First, any existing connections on the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.MoveLinkCmd.LinkPort"/>
        /// are removed. Next, if the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.MoveLinkCmd.Points"/>
        /// property is not null it is used to update link's vertices. And
        /// finally, the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.MoveLinkCmd.LinkPort"/>
        /// is connected to the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.MoveLinkCmd.TargetPort"/>.
        /// </remarks>
        public override bool Do(object cmdTarget)
        {
            bool success = false;

            if (this.link != null && this.linkPort != null)
            {
                this.link.DisconnectAll(this.linkPort);

                if (this.points != null)
                {
                    IServiceProvider linkSvcProvider = this.link as IServiceProvider;
                    if (linkSvcProvider != null)
                    {
                        IPoints ptsObj = linkSvcProvider.GetService(typeof(IPoints)) as IPoints;
                        if (ptsObj != null)
                        {
                            ptsObj.SetPoints(this.points);
                        }
                    }
                }

                if (this.targetPort != null)
                {
                    this.link.Connect(this.linkPort, this.targetPort);
                }
            }

            return(success);
        }
Пример #2
0
        public void Draw(
            GridRange range,
            IPoints points) {

            DrawingContext drawingContext = RenderOpen();
            DoubleCollection xCollection = new DoubleCollection();
            DoubleCollection yCollection = new DoubleCollection();

            try {
                // vertical line
                double renderHeight = points.yPosition[range.Rows.Start + range.Rows.Count] - points.yPosition[range.Rows.Start];
                Rect verticalLineRect = new Rect(new Size(GridLineThickness, renderHeight));
                foreach (int i in range.Columns.GetEnumerable()) {
                    verticalLineRect.X = points.xPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, verticalLineRect);
                    xCollection.Add(verticalLineRect.X);
                }

                // horizontal line
                double renderWidth = points.xPosition[range.Columns.Start + range.Columns.Count] - points.xPosition[range.Columns.Start];
                Rect horizontalLineRect = new Rect(new Size(renderWidth, GridLineThickness));
                foreach (int i in range.Rows.GetEnumerable()) {
                    horizontalLineRect.Y = points.yPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, horizontalLineRect);
                    yCollection.Add(horizontalLineRect.Y);
                }

                XSnappingGuidelines = xCollection;
                YSnappingGuidelines = yCollection;
            } finally {
                drawingContext.Close();
            }
        }
Пример #3
0
        private void PollingTimerEllapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (_isPollingCancelled)
                {
                    _pointsToPoll = null;
                }
                else
                {
                    _pointsToPoll.Read();

                    ReadCount++;
                }
            }
            catch (Exception ex)
            {
                AddLogEntry(ex.Message);

                ErrorCount++;
            }
            finally
            {
                if (!_isPollingCancelled && _pointsToPoll != null)
                {
                    _pollingTimer.Start();
                }
            }
        }
Пример #4
0
        private void draw_btn_Click(object sender, EventArgs e)
        {
            figure = null;
            switch (figure_tabControl.SelectedIndex)
            {
            case 0:
                figure = new Detail((float)X_nud.Value, (float)Y_nud.Value, (float)A_nud.Value, (float)B_nud.Value, (float)C_nud.Value, (float)D_nud.Value, (float)E_nud.Value, (float)R1_nud.Value, (float)R2_nud.Value, (float)R3_nud.Value);
                break;

            case 1:
                figure = new Curve((float)Acurve_nud.Value);
                //Form form = new Form();
                //RichTextBox rtb1 = new RichTextBox();
                //foreach (MyPoint p in figure.GetPoints())
                //    rtb1.Text += $"\n X: {p.Point.X}; Y: {p.Point.Y}";
                //rtb1.Parent = form;
                //rtb1.Width = 300;
                ////rtb1.Height = form.Height = figure.GetPoints().Count * 10;
                //form.ShowDialog();
                break;
            }

            if (figure != null)
            {
                draw.SetFigure(figure);
            }
            showField.Image = draw.ShowDrawing();

            angleShow         = 0;
            xShift            = 0;
            yShift            = 0;
            angle_label.Text  = $"Angle: {angleShow}";
            xShift_label.Text = $"X Shift: {xShift}";
            yShift_label.Text = $"Y Shift: {yShift}";
        }
Пример #5
0
        /// <summary>
        /// Calculates the point at which the given label should be positioned.
        /// </summary>
        /// <remarks>
        /// This method is called by the label itself in order to find out where
        /// it should be positioned.
        /// <seealso cref="Syncfusion.Windows.Forms.Diagram.Label"/>
        /// <seealso cref="Syncfusion.Windows.Forms.Diagram.ILabelContainer"/>
        /// </remarks>
        public override PointF CalcLabelPosition(Label label)
        {
            PointF ptLabel       = new PointF(0, 0);
            bool   pctAlongFound = false;

            int pctAlongLine = (int)label.GetPropertyValue("LabelPercentAlongLine");

            IPoints pts = this.Points;
            int     vertexIdx1;
            int     vertexIdx2;

            PointF[] ptAlongLine = new PointF[1];

            if (pts != null)
            {
                pctAlongFound = Geometry.CalcPercentageAlong(pts, pctAlongLine, out ptAlongLine[0], out vertexIdx1, out vertexIdx2);

                if (pctAlongFound)
                {
                    Matrix worldXform = this.WorldTransform;
                    worldXform.TransformPoints(ptAlongLine);
                    ptLabel = ptAlongLine[0];
                }
            }

            if (!pctAlongFound)
            {
                // Unable to calculate label position based on percentage
                // along the line. Use the center point of the bounding box
            }

            return(ptLabel);
        }
 public static void Normalize(this IPoints list)
 {
     foreach (var p in list.Data)
     {
         p.Normalize();
     }
 }
Пример #7
0
 public void Clear()
 {
     figure     = null;
     grid       = null;
     showFigure = false;
     showGrid   = false;
 }
Пример #8
0
        public Algorithm(
            IPoints points, IRectangle rect, StrategyType type = StrategyType.Grid, ILog2 log = null)
        {
            _log      = log ?? new NoLog();
            Rectangle = rect;
            Points    = points.Data;
            Singles   = new List <IP>();
            Knn       = new NearestNeighbor();

            GridContainer = new GridContainer(Rectangle, Points);

            switch (type)
            {
            case StrategyType.Naive:
                Strategy = new NaiveStrategy(_log);
                break;

            case StrategyType.Grid:
                Strategy = new GridStrategy(_log);
                break;

            case StrategyType.KdTree:
                Strategy = new KdTreeStrategy(Points);
                break;

            default:
                throw new NotImplementedException("Unknown strategy");
            }

            //_log.Info(MethodBase.GetCurrentMethod(), "object init");
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pts"></param>
        /// <returns></returns>
        public static double CalcLineLength(IPoints pts)
        {
            if (pts == null)
            {
                throw new EInvalidParameter();
            }

            double length     = 0.0f;
            int    vertexIdx1 = 0;
            int    vertexIdx2 = 1;
            PointF vertex1;
            PointF vertex2;
            int    numPts = pts.PointCount;

            while (vertexIdx2 < numPts)
            {
                vertex1 = pts.GetPoint(vertexIdx1);
                vertex2 = pts.GetPoint(vertexIdx2);
                length += Geometry.PointDistance(vertex1, vertex2);
                vertexIdx1++;
                vertexIdx2++;
            }

            return(length);
        }
Пример #10
0
        public void Draw(
            GridRange range,
            IPoints points)
        {
            DrawingContext   drawingContext = RenderOpen();
            DoubleCollection xCollection    = new DoubleCollection();
            DoubleCollection yCollection    = new DoubleCollection();

            try {
                // vertical line
                double renderHeight     = points.yPosition[range.Rows.Start + range.Rows.Count] - points.yPosition[range.Rows.Start];
                Rect   verticalLineRect = new Rect(new Size(GridLineThickness, renderHeight));
                foreach (int i in range.Columns.GetEnumerable())
                {
                    verticalLineRect.X = points.xPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, verticalLineRect);
                    xCollection.Add(verticalLineRect.X);
                }

                // horizontal line
                double renderWidth        = points.xPosition[range.Columns.Start + range.Columns.Count] - points.xPosition[range.Columns.Start];
                Rect   horizontalLineRect = new Rect(new Size(renderWidth, GridLineThickness));
                foreach (int i in range.Rows.GetEnumerable())
                {
                    horizontalLineRect.Y = points.yPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, horizontalLineRect);
                    yCollection.Add(horizontalLineRect.Y);
                }

                XSnappingGuidelines = xCollection;
                YSnappingGuidelines = yCollection;
            } finally {
                drawingContext.Close();
            }
        }
Пример #11
0
        public Algorithm(
            IPoints points, IRectangle rect, StrategyType type = StrategyType.Grid, ILog2 log = null)
        {
            _log = log ?? new NoLog();
            Rectangle = rect;
            Points = points.Data;
            Singles = new List<IP>();
            Knn = new NearestNeighbor();

            GridContainer = new GridContainer(Rectangle, Points);

            switch (type)
            {
                case StrategyType.Naive:
                    Strategy = new NaiveStrategy(_log);
                    break;
                case StrategyType.Grid:
                    Strategy = new GridStrategy(_log);
                    break;
                case StrategyType.KdTree:
                    Strategy = new KdTreeStrategy(Points);
                    break;
                default:
                    throw new NotImplementedException("Unknown strategy");
            }

            //_log.Info(MethodBase.GetCurrentMethod(), "object init");
        }
Пример #12
0
        static public List <MyPoint> Projective(IPoints figure, MyPoint startPoint, MyPoint X_AxleEnd, MyPoint Y_AxleEnd)
        {
            List <MyPoint> myPoints = figure.GetPoints();
            float          X0       = startPoint.Point.X;
            float          Y0       = startPoint.Point.Y;
            float          W0       = startPoint.Weight;

            float Xx = X_AxleEnd.Point.X;
            float Yx = X_AxleEnd.Point.Y;
            float Wx = X_AxleEnd.Weight;

            float Xy = Y_AxleEnd.Point.X;
            float Yy = Y_AxleEnd.Point.Y;
            float Wy = Y_AxleEnd.Weight;


            foreach (MyPoint p in myPoints)
            {
                float X = p.Point.X;
                float Y = p.Point.Y;
                float W = p.Weight;

                float newX = (X0 * W0 + Xx * Wx * X + Xy * Wy * Y) / (W0 + Wx * X + Wy * Y);
                float newY = (Y0 * W0 + Yx * Wx * X + Yy * Wy * Y) / (W0 + Wx * X + Wy * Y);
                p.SetPoint(new PointF(newX, newY));
            }


            return(myPoints);
        }
 // O(n), could be O(logn-ish) using range search or similar, no problem when points are <500.000
 public static IPoints FilterDataset(IPoints dataset, Boundary viewport)
 {
     //return new Points { Data = dataset.Data.Where(i => MathTool.IsInsideWiden(viewport, i)).ToList() };
     return(new Points {
         Data = dataset.Data.Where(i => MathTool.IsInside(viewport, i)).ToList()
     });
 }
 protected ClusterAlgorithmBase(IPoints dataset)
 {
     if (dataset == null)
     {
         throw new ApplicationException(string.Format("dataset is null"));
     }
     Dataset = dataset;
 }
 public void GetPoints(IPoints creature)
 {
     _score   += creature.Value;
     _elScore += creature.Value;
     Console.WriteLine($"You have saved a {creature.Name}");
     //Thread.Sleep(1000);
     Console.WriteLine($"+{creature.Value} points");
 }
 protected ClusterAlgorithmBase(IPoints dataset)
 {
     if (dataset == null)
     {
         throw new ApplicationException(string.Format("dataset is null"));
     }
     Dataset = dataset;
 }
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pt"></param>
        private void MoveVertex(System.Drawing.Point pt)
        {
            if (this.Controller == null || this.View == null)
            {
                return;
            }

            if (this.editMode != EditMode.Moving || this.trackingNode == null)
            {
                return;
            }

            if (this.View.Grid.SnapToGrid)
            {
                pt = this.View.SnapPointToGrid(pt);
            }

            IPoints objPoints = this.trackingNode as IPoints;

            if (objPoints != null)
            {
                this.View.Refresh(this.trackingRect);

                ITransform objXform = this.trackingNode as ITransform;
                PointF[]   ptWorld  = new PointF[1]
                {
                    this.View.ViewToWorld(this.View.DeviceToView(pt))
                };

                if (objXform != null)
                {
                    Matrix worldTransform = objXform.WorldTransform;
                    worldTransform.Invert();
                    worldTransform.TransformPoints(ptWorld);
                }
                objPoints.SetPoint(this.vertexIdx, ptWorld[0]);

                int prevStack = Global.SelectMatrixStack(Global.TemporaryStack);
                Global.MatrixStack.Clear();

                ITransform nodeTrans = this.trackingNode as ITransform;
                if (nodeTrans != null)
                {
                    Global.MatrixStack.Push(nodeTrans.ParentTransform);
                }

                IGraphics nodeGrfx = this.trackingNode as IGraphics;
                if (nodeGrfx != null)
                {
                    this.trackingPath = nodeGrfx.GraphicsPath;
                }

                Global.SelectMatrixStack(prevStack);

                this.trackingRect = this.View.DrawTrackingPath(this.trackingPath);
            }
        }
Пример #18
0
 protected Level(int slowActionGame, int snakeLevelLength, int applesTarget, int negativePointsPerMissedApple)
 {
     this.SlowActionGame               = slowActionGame;
     this.InitialSnakeLevelLength      = snakeLevelLength;
     this.ApplesTarget                 = applesTarget;
     this.NegativePointsPerMissedApple = negativePointsPerMissedApple;
     this.levelPoints = new Points(snakeLevelLength);
     this.obstacles   = new List <IObstacle>();
 }
Пример #19
0
 public Draw(Bitmap _sizeBmp, IPoints _F, Grid _G, bool _showGrid)
 {
     figure     = _F;
     grid       = _G;
     showGrid   = _showGrid;
     showFigure = true;
     gridBmp    = DrawGrid(grid);
     figureBmp  = DrawFigure(figure);
 }
        // Circular mean, very relevant for points around New Zealand, where lon -180 to 180 overlap
        // Adapted Centroid Calculation of N Points for Google Maps usage
        public static IP GetCentroidFromClusterLatLon(IPoints list) //O(n)
        {
            int count;

            if (list == null || (count = list.Count) == 0)
            {
                return(null);
            }

            if (count == 1)
            {
                return(list.Data.First());
            }

            // http://en.wikipedia.org/wiki/Circular_mean
            // http://stackoverflow.com/questions/491738/how-do-you-calculate-the-average-of-a-set-of-angles

            /*
             *                    1/N*  sum_i_from_1_to_N sin(a[i])
             *  a = atan2      ---------------------------
             *                    1/N*  sum_i_from_1_to_N cos(a[i])
             */

            double lonSin = 0;
            double lonCos = 0;
            double latSin = 0;
            double latCos = 0;

            foreach (var p in list.Data)
            {
                lonSin += Math.Sin(p.X.LatLonToRadian());
                lonCos += Math.Cos(p.X.LatLonToRadian());
                latSin += Math.Sin(p.Y.LatLonToRadian());
                latCos += Math.Cos(p.Y.LatLonToRadian());
            }

            lonSin /= count;
            lonCos /= count;

            double radx = 0;
            double rady = 0;

            if (Math.Abs(lonSin - 0) > Numbers.Epsilon && Math.Abs(lonCos - 0) > Numbers.Epsilon)
            {
                radx = Math.Atan2(lonSin, lonCos);
                rady = Math.Atan2(latSin, latCos);
            }
            var x = radx.RadianToLatLon();
            var y = rady.RadianToLatLon();

            var centroid = new P {
                X = x, Y = y, C = count
            };

            return(centroid);
        }
        public IPoints RunClusterAlgo(ClusterInfo clusterInfo)
        {
            // Skip points outside the grid
            IPoints filtered = clusterInfo.IsFilterData ? FilterDataset(Dataset, Grid) : Dataset;

            // Put points in buckets
            foreach (var p in filtered.Data)
            {
                var idxy = GetPointMappedIds(p, Grid, DeltaX, DeltaY);
                var idx  = idxy[0];
                var idy  = idxy[1];

                // Bucket id
                var id = GetId(idx, idy);

                // Bucket exists, add point
                if (BucketsLookup.ContainsKey(id))
                {
                    BucketsLookup[id].Points.Add(p);
                }
                // New bucket, create and add point
                else
                {
                    var bucket = new Bucket(idx, idy, id);
                    bucket.Points.Add(p);
                    BucketsLookup.Add(id, bucket);
                }
            }

            // Calculate centroid for all buckets
            SetCentroidForAllBuckets(BucketsLookup.Values);

            // Merge if gridpoint is to close
            if (AlgoConfig.DoMergeGridIfCentroidsAreCloseToEachOther)
            {
                MergeClustersGrid();
            }

            if (AlgoConfig.DoUpdateAllCentroidsToNearestContainingPoint)
            {
                UpdateAllCentroidsToNearestContainingPoint();
            }

            // Check again
            // Merge if gridpoint is to close
            if (AlgoConfig.DoMergeGridIfCentroidsAreCloseToEachOther &&
                AlgoConfig.DoUpdateAllCentroidsToNearestContainingPoint)
            {
                MergeClustersGrid();
                // And again set centroid to closest point in bucket
                UpdateAllCentroidsToNearestContainingPoint();
            }

            return(GetClusterResult(Grid));
        }
Пример #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="percent"></param>
        /// <param name="ptReturn"></param>
        /// <param name="vertexIdx1"></param>
        /// <param name="vertexIdx2"></param>
        /// <returns></returns>
        public static bool CalcPercentageAlong(IPoints pts, int percent, out System.Drawing.PointF ptReturn, out int vertexIdx1, out int vertexIdx2)
        {
            bool found = false;

            if (pts == null)
            {
                throw new EInvalidParameter();
            }

            if (percent < 0 || percent > 100)
            {
                throw new EInvalidParameter();
            }

            int    numPts      = pts.PointCount;
            double totalLength = Geometry.CalcLineLength(pts);
            double lengthAlong = totalLength * (percent / 100.0f);
            double lengthSoFar = 0.0f;
            PointF vertex1;
            PointF vertex2;
            double curSegmentLength;
            double curSegmentPct;

            vertexIdx1 = 0;
            vertexIdx2 = 1;
            ptReturn   = new PointF(0, 0);

            while (vertexIdx2 < numPts && !found)
            {
                vertex1          = pts.GetPoint(vertexIdx1);
                vertex2          = pts.GetPoint(vertexIdx2);
                curSegmentLength = Geometry.PointDistance(vertex1, vertex2);
                if (curSegmentLength > 0.0f && (lengthSoFar + curSegmentLength) >= lengthAlong)
                {
                    // calculate percentage along this segment
                    curSegmentPct = (lengthAlong - lengthSoFar) * 100.0f / curSegmentLength;

                    // find the point on the segment
                    double ptX = vertex1.X + (curSegmentPct * (vertex2.X - vertex1.X) / 100.0f);
                    double ptY = vertex1.Y + (curSegmentPct * (vertex2.Y - vertex1.Y) / 100.0f);
                    ptReturn = new PointF((float)ptX, (float)ptY);

                    // Exit loop and return
                    found = true;
                }
                else
                {
                    vertexIdx1++;
                    vertexIdx2++;
                }
            }

            return(found);
        }
        public GridCluster(IPoints dataset, JsonGetMarkersReceive jsonReceive)
            : base(dataset)
        {
            // Important, set _delta and _grid values in constructor as first step
            var deltas = GetDelta(jsonReceive);
            DeltaX = deltas[0];
            DeltaY = deltas[1];
            Grid = GetBoundaryExtended(jsonReceive);
            Lines = new List<Line>();

            if (AlgoConfig.DoShowGridLinesInGoogleMap) MakeLines(jsonReceive);
        }
Пример #24
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private bool CreateCollection(IEnumerable <ContourLoadSet> loads)
        {
            foreach (ContourLoadSet load in loads)
            {
                try
                {
                    //Ensure points describe a closed polyline
                    List <Point> loadPoints = load.Contour.ControlPoints();
                    if (loadPoints.First() != loadPoints.Last())
                    {
                        loadPoints.Add(loadPoints.Last().DeepClone());
                    }

                    //Find the layout to apply to
                    IStories   ramStories = m_Model.GetStories();
                    IStory     loadStory  = loadPoints.First().GetStory(ramStories);
                    double     storyElev  = loadStory.dElevation;
                    IFloorType floorType  = loadStory.GetFloorType();

                    ISurfaceLoadSets floorLoads   = floorType.GetSurfaceLoadSets2();
                    int             nextId        = floorLoads.GetCount();
                    ISurfaceLoadSet ramLoad       = floorLoads.Add(nextId, loadPoints.Count());
                    IPoints         verticePoints = ramLoad.GetPoints();

                    List <SCoordinate> checkList = new List <SCoordinate>();
                    SCoordinate        verticeCoord;

                    for (int i = 0; i < loadPoints.Count(); i++)
                    {
                        verticeCoord = loadPoints[i].ToRAM();
                        verticePoints.Delete(i);
                        verticePoints.InsertAt2(i, verticeCoord.dXLoc, verticeCoord.dYLoc, 0);
                        checkList.Add(verticeCoord);
                    }
                    ramLoad.SetPoints(verticePoints);

                    ramLoad.lPropertySetUID = (int)GetAdapterId(load.UniformLoadSet);
                }

                catch
                {
                    CreateElementError("UniformLoadSet", load.Name);
                }
            }



            //Save file
            m_IDBIO.SaveDatabase();

            return(true);
        }
        public static void SaveDataSetToFile(IPoints dataset, string filename = null)
        {
            if (filename == null)
            {
                SaveDataSetToFile(dataset, DatasetSerializeName);
            }

            var objectToSerialize = new DatasetToSerialize {
                Dataset = dataset
            };

            new Serializer().SerializeObject(FolderPath + filename, objectToSerialize);
        }
Пример #26
0
        static public List <MyPoint> Move(IPoints figure, int x_move, int y_move)
        {
            List <MyPoint> myPoints = figure.GetPoints();

            foreach (MyPoint p in myPoints)
            {
                PointF newPoint = p.GetPoint();
                newPoint.X += x_move;
                newPoint.Y += y_move;
                p.SetPoint(newPoint);
            }
            return(myPoints);
        }
Пример #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        void IMouseEventReceiver.MouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            System.Drawing.Point ptScreen = new System.Drawing.Point(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                if (this.Active)
                {
                    this.drawing  = true;
                    this.tracking = false;
                    if (this.trackingPts != null)
                    {
                        this.Controller.View.DrawTrackingLines(this.trackingPts);
                    }
                    this.trackingPts = null;
                }
                else
                {
                    // Test to see if user clicked a port on a link
                    if (this.HitTestLinkPorts(ptScreen))
                    {
                        IServiceProvider linkSvcProvider = this.selectedLink as IServiceProvider;
                        if (linkSvcProvider != null)
                        {
                            IPoints linkPts = linkSvcProvider.GetService(typeof(IPoints)) as IPoints;
                            if (linkPts != null)
                            {
                                this.points.Clear();
                                System.Drawing.Point[] existingPts = this.View.GetDevicePoints(linkPts);
                                if (existingPts != null)
                                {
                                    for (int ptIdx = 0; ptIdx < existingPts.Length - 1; ptIdx++)
                                    {
                                        this.points.Add(existingPts[ptIdx]);
                                    }
                                }
                                this.movingLinkPort = true;
                                this.Controller.ActivateTool(this);
                                this.tracking = true;
                                this.InitTrackingPoints();
                                if (this.trackingPts != null)
                                {
                                    this.Controller.View.DrawTrackingLines(this.trackingPts);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #28
0
        /// <summary>
        /// Constructs a link given a link shape object.
        /// </summary>
        /// <param name="linkPoints">Link shape object to attach</param>
        /// <remarks>
        /// <para>
        /// Instead of calling the
        /// <see cref="Syncfusion.Windows.Forms.Diagram.Link.CreateLinkShape"/>
        /// method to create the link shape, this constructor takes the link shape
        /// object as a parameter and attaches it to the link. A link shape is
        /// any object that supports the IPoints interface.
        /// </para>
        /// <seealso cref="Syncfusion.Windows.Forms.Diagram.IPoints"/>
        /// </remarks>
        public Link(IPoints linkPoints)
        {
            if (linkPoints != null)
            {
                INode childNode = linkPoints as INode;
                if (childNode != null)
                {
                    this.AppendChild(childNode);
                }
            }

            this.Ports.Add(CreateTailPort());
            this.Ports.Add(CreateHeadPort());
        }
Пример #29
0
        internal void ArrangeVisuals(IPoints points)
        {
            foreach (int c in _dataViewport.Columns.GetEnumerable())
            {
                foreach (int r in _dataViewport.Rows.GetEnumerable())
                {
                    var visual = _visualGrid[r, c];

                    Debug.Assert(r == visual.Row && c == visual.Column);
                    Debug.Assert(points.Width[c] >= visual.Size.Width && points.Height[r] >= visual.Size.Height);

                    double cellX = points.xPosition[c];
                    double cellY = points.yPosition[r];
                    double cellW = points.Width[c];
                    double cellH = points.Height[r];
                    visual.CellBounds = new Rect(cellX, cellY, cellW, cellH);

                    bool   alignRight = visual.TextAlignment == TextAlignment.Right;
                    double x          = cellX + (alignRight ? (cellW - visual.Size.Width - visual.Margin - GridLineThickness) : visual.Margin);
                    double y          = cellY + visual.Margin;

                    var transform = visual.Transform as TranslateTransform;
                    if (transform == null)
                    {
                        visual.Transform = new TranslateTransform(x, y);
                    }
                    else
                    {
                        transform.X = x;
                        transform.Y = y;
                    }

                    visual.X = x;
                    visual.Y = y;
                    visual.Draw();
                }
            }

            // special handling for Row/Column header's size: this will layout system (measure/arrange) to know the size of component properly.
            if (ScrollDirection == ScrollDirection.Horizontal)
            {
                Height = points.Height[0];
            }
            else if (ScrollDirection == ScrollDirection.Vertical)
            {
                Width = points.Width[0];
            }

            _gridLine?.Draw(_dataViewport, points);
        }
Пример #30
0
        /// <summary>
        /// Moves the vertex of the node by the specified amount.
        /// </summary>
        /// <param name="cmdTarget">Unused</param>
        /// <returns>true if successful, otherwise false</returns>
        /// <remarks>
        /// The node must support the IPoints interface. The IPoints.SetPoint
        /// method is used to move the point by the specified offset.
        /// </remarks>
        public override bool Do(object cmdTarget)
        {
            bool success = false;

            if (this.Node != null)
            {
                IPoints objPoints = this.Node as IPoints;
                if (objPoints != null)
                {
                    ITransform objTransform  = this.Node as ITransform;
                    Matrix     worldXform    = null;
                    Matrix     invWorldXform = null;

                    if (objTransform != null)
                    {
                        worldXform    = objTransform.WorldTransform;
                        invWorldXform = worldXform.Clone();
                        invWorldXform.Invert();
                    }

                    if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount)
                    {
                        PointF[] pt = new PointF[1]
                        {
                            objPoints.GetPoint(this.vertexIdx)
                        };

                        if (worldXform != null)
                        {
                            worldXform.TransformPoints(pt);
                        }

                        pt[0].X += this.dx;
                        pt[0].Y += this.dy;

                        if (invWorldXform != null)
                        {
                            invWorldXform.TransformPoints(pt);
                        }

                        objPoints.SetPoint(this.vertexIdx, pt[0]);

                        success = true;
                    }
                }
            }

            return(success);
        }
Пример #31
0
        public void Load()
        {
            InitRenderer();

            _resourceManager.Configure(_renderer);

            _curve          = new Curve("curve", 2);
            _curve.Material = _resourceManager.GetMaterial("lineMaterial");
            _curve.Configure(_renderer);

            _points          = new Points("points", 5);
            _points.Material = _resourceManager.GetMaterial("pointMaterial");

            _points.Configure(_renderer);
        }
Пример #32
0
        static public List <MyPoint> Turn(IPoints figure, float angle, PointF axle)
        {
            List <MyPoint> myPoints = figure.GetPoints();

            angle *= (float)Math.PI / 180;
            foreach (MyPoint p in myPoints)
            {
                PointF oldPoint = p.GetPoint();
                PointF newPoint = new PointF();
                newPoint.X = (float)(axle.X + (oldPoint.X - axle.X) * Math.Cos(angle) - (oldPoint.Y - axle.Y) * Math.Sin(angle));
                newPoint.Y = (float)(axle.Y + (oldPoint.X - axle.X) * Math.Sin(angle) + (oldPoint.Y - axle.Y) * Math.Cos(angle));
                p.SetPoint(newPoint);
            }
            return(myPoints);
        }
        public GridCluster(IPoints dataset, JsonGetMarkersReceive jsonReceive)
            : base(dataset)
        {
            // Important, set _delta and _grid values in constructor as first step
            var deltas = GetDelta(jsonReceive);

            DeltaX = deltas[0];
            DeltaY = deltas[1];
            Grid   = GetBoundaryExtended(jsonReceive);
            Lines  = new List <Line>();

            if (AlgoConfig.DoShowGridLinesInGoogleMap)
            {
                MakeLines(jsonReceive);
            }
        }
Пример #34
0
        static public List <MyPoint> Affine(IPoints figure, PointF x_Vector, PointF y_Vector, PointF startPoint)
        {
            List <MyPoint> myPoints = figure.GetPoints();

            foreach (MyPoint p in myPoints)
            {
                PointF oldPoint = p.GetPoint();
                PointF newPoint = new PointF();

                newPoint.X = startPoint.X + x_Vector.X * oldPoint.X + y_Vector.X * oldPoint.Y;
                newPoint.Y = startPoint.Y + x_Vector.Y * oldPoint.X + y_Vector.Y * oldPoint.Y;

                p.SetPoint(newPoint);
            }
            return(myPoints);
        }
        //O(n)
        // Circular mean, very relevant for points around New Zealand, where lon -180 to 180 overlap
        // Adapted Centroid Calculation of N Points for Google Maps usage
        public static IP GetCentroidFromClusterLatLon(IPoints list)
        {
            int count;
            if (list == null || (count = list.Count) == 0) return null;

            if (count == 1)
            {
                return list.Data.First();
            }

            // http://en.wikipedia.org/wiki/Circular_mean
            // http://stackoverflow.com/questions/491738/how-do-you-calculate-the-average-of-a-set-of-angles
            /*
                                  1/N*  sum_i_from_1_to_N sin(a[i])
                a = atan2      ---------------------------
                                  1/N*  sum_i_from_1_to_N cos(a[i])
             */

            double lonSin = 0;
            double lonCos = 0;
            double latSin = 0;
            double latCos = 0;
            foreach (var p in list.Data)
            {
                lonSin += Math.Sin(p.X.LatLonToRadian());
                lonCos += Math.Cos(p.X.LatLonToRadian());
                latSin += Math.Sin(p.Y.LatLonToRadian());
                latCos += Math.Cos(p.Y.LatLonToRadian());
            }

            lonSin /= count;
            lonCos /= count;

            double radx = 0;
            double rady = 0;

            if (Math.Abs(lonSin - 0) > Numbers.Epsilon && Math.Abs(lonCos - 0) > Numbers.Epsilon)
            {
                radx = Math.Atan2(lonSin, lonCos);
                rady = Math.Atan2(latSin, latCos);
            }
            var x = radx.RadianToLatLon();
            var y = rady.RadianToLatLon();

            var centroid = new P{X=x, Y=y, C = count };
            return centroid;
        }
        // O(n)
        public IP GetClosestPoint(IP from, IPoints list)
        {
            var min = double.MaxValue;
            IP closests = null;
            foreach (var p in list.Data)
            {
                var d = MathTool.Distance(from, p);
                if (d >= min)
                {
                    continue;
                }

                // update
                min = d;
                closests = p;
            }
            return closests;
        }
 public void SetRange(IPoints points)
 {
     this.Data.Clear();
     this.Data.AddRange(points.Data);
 }
Пример #38
0
        internal void MeasurePoints(IPoints points, GridRange newViewport, IGrid<string> data, bool refresh) {
            var orgGrid = _visualGrid;
            _visualGrid = new Grid<TextVisual>(
                newViewport,
                (r, c) => {
                    if (!refresh && _dataViewport.Contains(r, c)) {
                        return orgGrid[r, c];
                    }
                    var visual = new TextVisual();
                    visual.Row = r;
                    visual.Column = c;
                    visual.Text = data[r, c];
                    visual.Typeface = Typeface;
                    visual.FontSize = FontSize; // FontSize here is in device independent pixel, and Visual's FormattedText API uses the same unit
                    visual.Foreground = Foreground;
                    return visual;
                });

            _visualChildren.Clear();
            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    visual.Draw();
                    points.Width[c] = visual.Size.Width + (visual.Margin * 2) + GridLineThickness;
                    points.Height[r] = visual.Size.Height + (visual.Margin * 2) + GridLineThickness;

                    _visualChildren.Add(_visualGrid[r, c]);
                }
            }

            _dataViewport = newViewport;
        }
 public DatasetToSerialize()
 {
     Dataset = new Points();
 }
 // O(n), could be O(logn-ish) using range search or similar, no problem when points are <500.000
 public static IPoints FilterDataset(IPoints dataset, Boundary viewport)
 {
     //return new Points { Data = dataset.Data.Where(i => MathTool.IsInsideWiden(viewport, i)).ToList() };
     return new Points {Data = dataset.Data.Where(i => MathTool.IsInside(viewport, i)).ToList()};
 }
 public static void SaveDataSetToFile(IPoints dataset, string filename = null)
 {
     if(filename==null) SaveDataSetToFile(dataset, DatasetSerializeName);
                     
     var objectToSerialize = new DatasetToSerialize { Dataset = dataset };
     new Serializer().SerializeObject(FolderPath + filename, objectToSerialize);
 }
Пример #42
0
        internal void MeasurePoints(IPoints points, GridRange newViewport, IGrid<string> data, GridUpdateType updateType) {
            CreateGrid(newViewport, data, updateType);
            _visualChildren.Clear();

            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    visual.Draw();
                    points.Width[c] = visual.Size.Width + (visual.Margin * 2) + GridLineThickness;
                    points.Height[r] = visual.Size.Height + (visual.Margin * 2) + GridLineThickness;

                    _visualChildren.Add(_visualGrid[r, c]);
                }
            }

            _dataViewport = newViewport;
        }
Пример #43
0
        internal void ArrangeVisuals(IPoints points) {
            foreach (int c in _dataViewport.Columns.GetEnumerable()) {
                foreach (int r in _dataViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    Debug.Assert(r == visual.Row && c == visual.Column);
                    Debug.Assert(points.Width[c] >= visual.Size.Width && points.Height[r] >= visual.Size.Height);

                    double cellX = points.xPosition[c];
                    double cellY = points.yPosition[r];
                    double cellW = points.Width[c];
                    double cellH = points.Height[r];
                    visual.CellBounds = new Rect(cellX, cellY, cellW, cellH);

                    bool alignRight = visual.TextAlignment == TextAlignment.Right;
                    double x = cellX + (alignRight ? (cellW - visual.Size.Width - visual.Margin - GridLineThickness) : visual.Margin);
                    double y = cellY + visual.Margin;

                    var transform = visual.Transform as TranslateTransform;
                    if (transform == null) {
                        visual.Transform = new TranslateTransform(x, y);
                    } else {
                        transform.X = x;
                        transform.Y = y;
                    }

                    visual.X = x;
                    visual.Y = y;
                    visual.Draw();
                }
            }

            // special handling for Row/Column header's size: this will layout system (measure/arrange) to know the size of component properly.
            if (ScrollDirection == ScrollDirection.Horizontal) {
                Height = points.Height[0];
            } else if (ScrollDirection == ScrollDirection.Vertical) {
                Width = points.Width[0];
            }

            _gridLine?.Draw(_dataViewport, points);
        }
 public DatasetToSerialize(SerializationInfo info, StreamingContext ctxt)
 {
     this.Dataset = (IPoints)info.GetValue(Name, typeof(IPoints));
 }