Beispiel #1
0
        public DrawPolygon(int x1, int y1, int x2, int y2) : base()
        {
            pointArray = new PointList();
            pointArray.Add(new Point(x1, y1));
            pointArray.Add(new Point(x2, y2));

            Initialize();
        }
Beispiel #2
0
	public Piece(){
		range = new PointList<RectPoint> ();
		range.Add (new RectPoint (0, 0));
		range.Add (new RectPoint (1, 0));
		range.Add (new RectPoint (2, 0));
		range.Add (new RectPoint (-1, 0));
		range.Add (new RectPoint (-2, 0));
		range.Add (new RectPoint (0, 1));
		range.Add (new RectPoint (0, 2));
		range.Add (new RectPoint (0, -1));
		range.Add (new RectPoint (0, -2));
	}
		public List<LocationOfInterest> GetInterestingLocations(Avatar observer)
		{
			List<LocationOfInterest> locationsOfInterest = new List<LocationOfInterest>();

			MapTile observerTile = _quest.GetAvatarMapTile(observer);
			Point observerLocation = _quest.Map.GetMapTileLocation(observerTile);
			PointList visibleLocations = _quest.Map.GetPointsWithinLineOfSightOf(observerLocation);

			//// Get a list of all actionable map tiles
			PointList interestingLocations = _quest.Map.GetActionableMapPoints(observer.Faction);
			
			// Filter out interesting locations that are not in the visible set
			PointList visibleInterestingLocations = interestingLocations.Intersects(visibleLocations);

			// Create paths to each of these points
			PathfindingNode observerNode = _quest.Map.GetPathfindingNodeForTile(observerTile);
			foreach (Point point in visibleInterestingLocations)
			{
				PathfindingNode pointNode = _quest.Map.GetPathfindingNodeForLocation(point.X, point.Y);
				List<PathfindingNode> path = _quest.Map.PathfindingGraph.FindRoute(observerNode, pointNode);
				if (path != null)
				{
					PointList pathSteps = new PointList();
					for (int i = 1; i < path.Count; i++)
					{ pathSteps.Add(_quest.Map.GetPointForPathfindingNode(path[i])); }

					LocationOfInterest interest = new LocationOfInterest(pathSteps);
					locationsOfInterest.Add(interest);
				}
			}

			return locationsOfInterest;
		}
Beispiel #4
0
 public static IEnumerable<PointList> AllPermutations(PointList inputList)
 {
     if (inputList.Count < 2)
         yield return inputList;
     else
         foreach (Point p in inputList)
         {
             PointList shorterList = new PointList(inputList);
             shorterList.Remove(p);
             foreach (PointList permutation in AllPermutations(shorterList))
             {
                 PointList newPermutation = new PointList(permutation);
                 newPermutation.Add(p);
                 yield return newPermutation;
             }
         }
 }
Beispiel #5
0
        /**
         *      Generates a maze using a randomized version of Prim's algorithm.
         *
         *      @returns a IEnumerable of passages
         */
        //For some reason, the generic version gives a TypeLoadException in Unity (but not when run from visual studio).

        /*
         * public static IEnumerable<TEdge> GenerateMazeWalls<TGrid, TPoint, TEdge>(TGrid grid)
         * where TEdge : IGridPoint<TEdge>, IEdge<TPoint>
         * where TPoint : IGridPoint<TPoint>, ISupportsEdges<TEdge>
         * where TGrid : ISupportsEdgeGrid<TEdge>, IGridSpace<TPoint>
         * {
         * IGrid<bool, TEdge> walls = grid.MakeEdgeGrid<bool>(); //true indicates passable
         * var wallList = new List<TEdge>();
         *
         * TPoint newMaizePoint = grid.RandomItem<TPoint>();
         * var inMaze = new List<TPoint>();
         * inMaze.Add(newMaizePoint);
         *
         * var edges = newMaizePoint.GetEdges();
         * wallList.AddRange(edges);
         *
         * while (wallList.Any())
         * {
         *      var randomWall = wallList.RandomItem();
         *      IEnumerable<TPoint> faces = (randomWall as IEdge<TPoint>).GetEdgeFaces().Where(x => grid.Contains(x));
         *
         *      //At least one of the two faces must be in the maze
         *      if (faces.Any(point => !inMaze.Contains(point)))
         *      {
         *              newMaizePoint = faces.First(point => !inMaze.Contains(point));
         *              inMaze.Add(newMaizePoint);
         *              walls[randomWall] = true;
         *
         *              yield return randomWall;
         *
         *              // Add all edges that are not passages
         *              edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
         *              wallList.AddRange(edges);
         *      }
         *      else
         *      {
         *              wallList.Remove(randomWall);
         *      }
         * }
         * yield return (TEdge)(object) g.First();
         * yield break;
         * }
         */

        /**
         *      Generates a maze using a randomized version of Prim's algorithm.
         *
         *      @returns a IEnumerable of passages
         */
        public static IEnumerable <PointyRhombPoint> GenerateMazeWalls <TCell>(FlatTriGrid <TCell> grid)
        {
            var walls    = grid.MakeEdgeGrid <bool>();         //true indicates passable
            var wallList = new PointList <PointyRhombPoint>();

            var newMaizePoint = grid.RandomItem();
            var inMaze        = new PointList <FlatTriPoint> {
                newMaizePoint
            };

            var edges = newMaizePoint.GetEdges();

            wallList.AddRange(edges);

            while (wallList.Any())
            {
                var randomWall = wallList.RandomItem();
                var faces      = (randomWall as IEdge <FlatTriPoint>).GetEdgeFaces().Where(x => grid.Contains(x));

                //At least one of the two faces must be in the maze
                if (faces.Any(point => !inMaze.Contains(point)))
                {
                    newMaizePoint = faces.First(point => !inMaze.Contains(point));
                    inMaze.Add(newMaizePoint);
                    walls[randomWall] = true;

                    yield return(randomWall);

                    // Add all edges that are not passages
                    edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
                    wallList.AddRange(edges);
                }
                else
                {
                    wallList.Remove(randomWall);
                }
            }
        }
Beispiel #6
0
        private void Board_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            var position = e.GetPosition(this);

            DrawEllipse(position);

            PointList.Add(position);

            var polygon = new Polygon()
            {
                Points = new PointCollection(PointList),
                Stroke = Brushes.Red,
            };

            AddElement(nameof(polygon), polygon);

            if (e.RightButton == MouseButtonState.Pressed)
            {
                CleanBoard();

                PointList.Clear();
            }
        }
		public List<AbstractTileAction> GetActionsAtObserverLocation(Avatar observer)
		{
			MapTile observerTile = _quest.GetAvatarMapTile(observer);
			Point observerLocation = _quest.Map.GetMapTileLocation(observerTile);

			//// Get a list of all actionable map tiles
			PointList interestingLocations = _quest.Map.GetActionableMapPoints(observer.Faction);

			// Filter out interesting locations that are not in the visible set
			PointList observerLocations = new PointList();
			observerLocations.Add(observerLocation);
			PointList visibleInterestingLocations = interestingLocations.Intersects(observerLocations);

			List<AbstractTileAction> actions = new List<AbstractTileAction>();
			for (int i = 0; i < visibleInterestingLocations.Count; i++)
			{
				List<AbstractTileAction> actionsAtInterestingLocation = _quest.Map.GetActionsForPoint(observerLocation);
				foreach (AbstractTileAction actionAtInterestingLocation in actionsAtInterestingLocation)
				{ actions.Add(actionAtInterestingLocation); }
			}

			return actions;
		}
        /// <summary>
        /// 绘制支撑板及牛腿上的螺钉在Y方向的标注;
        /// </summary>
        private void DrawSupportPlateBoltDimY()
        {
            CCylinderTopViewSetting cylinderTopViewSetting = CCylinderDimSetting.GetInstance().mTopViewSetting;

            if (!cylinderTopViewSetting.FindDimValueByName(CCylinderTopViewSetting.mstrSupportPlate))
            {
                return;
            }

            //移除主梁;
            mMrPartList.Remove(mMainBeam);

            foreach (CMrPart mrPart in mMrPartList)
            {
                CMrDimSet mrDimSet = mrPart.GetCylinderTopViewInfo().GetSupportPlateBoltYDimSet();

                if (mrDimSet == null || mrDimSet.Count <= 1)
                {
                    continue;
                }

                List <Point> dimPointList = mrDimSet.GetDimPointList();

                PointList pointList = new PointList();

                foreach (Point point in dimPointList)
                {
                    pointList.Add(point);
                }

                double dimDistance = mrDimSet.mDimDistance;
                Vector dimVector   = mrDimSet.mDimVector;
                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, dimVector, dimDistance, CCommonPara.mSizeDimPath);
            }

            mMrPartList.Add(mMainBeam);
        }
        /// <summary>
        /// 绘制主梁左侧Y方向上的标注;
        /// </summary>
        private void DrawYMainLeftDim()
        {
            List <Point> leftDimPointList = new List <Point>();

            foreach (CMrPart mrPart in mMrPartList)
            {
                CMrDimSet partDimSet = mrPart.GetCylinderDoorFrontViewInfo().GetYPartMainLeftDimSet();

                if (partDimSet != null && partDimSet.Count > 0)
                {
                    leftDimPointList.AddRange(partDimSet.GetDimPointList());
                }
            }

            //1.得到顶部需要进行标注的零部件;
            CMrDimSet mrTopPartDimSet = GetTopPartDimSet(1);

            leftDimPointList.AddRange(mrTopPartDimSet.GetDimPointList());

            Comparison <Point> sorterY = new Comparison <Point>(CDimTools.ComparePointY);

            leftDimPointList.Sort(sorterY);

            PointList pointList = new PointList();

            foreach (Point point in leftDimPointList)
            {
                pointList.Add(point);
            }

            Point  MinXPoint      = leftDimPointList[0];
            double dimDistance    = Math.Abs(CCommonPara.mViewMinX - MinXPoint.X) + 2 * CCommonPara.mDefaultDimDistance;
            Vector rightDimVector = new Vector(-1, 0, 0);

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, rightDimVector, dimDistance, CCommonPara.mSizeDimPath);
        }
Beispiel #10
0
    //TODO make another option to use octrees
    void GenerateGrid()
    {
        Vector3 scale = _rootMesh.transform.localScale;

        foreach (var meshBoxCollider in _meshBoxColliderArr)
        {
            Vector3 boxColliderSize = meshBoxCollider.size;
            Vector3 worldSize       = Vector3.Scale(meshBoxCollider.size, scale);
            Vector3 offset          = Vector3.Scale(meshBoxCollider.center, scale) - worldSize * .5f;

            Vector3 cellsPerSide = new Vector3(worldSize.x / _gridCellSize.x, worldSize.y / _gridCellSize.y, worldSize.z / _gridCellSize.z);
            Vector3 halfCellSize = _gridCellSize * .5f;

            for (int x = 0; x <= (int)cellsPerSide.x; x++)
            {
                for (int y = 0; y <= (int)cellsPerSide.y; y++)
                {
                    for (int z = 0; z <= (int)cellsPerSide.z; z++)
                    {
                        Vector3 pos = halfCellSize + (new Vector3(x * _gridCellSize.x, y * _gridCellSize.y, z * _gridCellSize.z));
                        pos += offset;

                        if (IsInsideTest(pos, Vector3.forward))
                        {
                            PointList.Add(pos);
                        }
                    }
                }
            }
        }

        if (_multiDirectionalCheck)
        {
            ReverseCollisionCheck();
        }
    }
Beispiel #11
0
        private void ParsePoints(XmlReader r)
        {
            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                if (r.Name == "Point")
                {
                    Points.Add(new GenericPosturePoint(r));
                }
                else
                {
                    string outerXml = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content in XML: {0}", outerXml);
                }
            }

            r.ReadEndElement();

            foreach (var point in Points)
            {
                PointList.Add(point.Value);
            }
        }
Beispiel #12
0
        private void ParseInitialConfiguration(XmlReader r)
        {
            r.ReadStartElement();
            while (r.NodeType == XmlNodeType.Element)
            {
                if (r.Name == "Point")
                {
                    PointF value = XmlHelper.ParsePointF(r.ReadElementContentAsString());
                    Points.Add(new GenericPosturePoint(value));
                }
                else
                {
                    string outerXml = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content: {0}", outerXml);
                }
            }

            r.ReadEndElement();

            foreach (var point in Points)
            {
                PointList.Add(point.Value);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 绘制主梁中间的零部件标注;
        /// 主梁中间的零部件只有法向与主梁顶部部件平行的才进行标注;
        /// </summary>
        private void DrawMainBeamMiddlePartDimMiddle()
        {
            CMrPart topBeam = CMrBeamDoorManager.GetInstance().mTopBeam;

            Point midMaxPoint   = CMrBeamDoorManager.GetInstance().mMidMaxPoint;
            Point leftTopPoint  = topBeam.mLeftTopPoint;
            Point rightTopPoint = topBeam.mRightTopPoint;

            CMrBeamDoorManager.GetInstance().BuildMostNearPartToPartList(mMrPartList);

            Dictionary <CMrPart, List <CMrPart> > dicPartToPartList = CMrBeamDoorManager.GetInstance().mDicPartToPartList;

            List <CMrDimSet> mrDimSetList = new List <CMrDimSet>();

            foreach (CMrPart mostNearPart in dicPartToPartList.Keys)
            {
                List <CMrPart> mrPartList = dicPartToPartList[mostNearPart];

                if (mrPartList.Count == 0)
                {
                    continue;
                }

                //(1).与顶板平行方向标注螺钉;
                CMrDimSet mrDimSet = new CMrDimSet();

                if (mostNearPart.mLeftTopPoint.X < midMaxPoint.X)
                {
                    mrDimSet.AddPoint(mostNearPart.mRightTopPoint);
                }
                else
                {
                    mrDimSet.AddPoint(mostNearPart.mLeftTopPoint);
                }

                //如果在上翼板的左侧;
                if (mostNearPart.mLeftTopPoint.X < midMaxPoint.X)
                {
                    foreach (CMrPart mrPart in mrPartList)
                    {
                        CMrBoltArray mrBoltArray = mrPart.GetBoltArrayList()[0];
                        Point        boltPoint   = mrBoltArray.GetMaxXPoint();
                        mrDimSet.AddPoint(boltPoint);
                    }
                    mrDimSet.mDimVector   = CMrBeamDoorManager.GetInstance().mLeftTopVector;
                    mrDimSet.mDimDistance = CCommonPara.mDefaultDimDistance;
                    mrDimSetList.Add(mrDimSet);

                    //(2).与顶板竖直方向标注;
                    mrDimSet = new CMrDimSet();
                    mrDimSet.AddPoint(mrPartList[0].mLeftBottomPoint);

                    Point fontPt = CDimTools.GetInstance().ComputeFootPointToLine(mrPartList[0].mLeftBottomPoint, leftTopPoint, midMaxPoint);
                    mrDimSet.AddPoint(fontPt);
                    mrDimSet.mDimDistance = CCommonPara.mDefaultDimDistance;

                    mrDimSet.mDimVector = new Vector(leftTopPoint.X - midMaxPoint.X, leftTopPoint.Y - midMaxPoint.Y, 0);
                    mrDimSetList.Add(mrDimSet);
                }
                //如果在上翼板的右侧;
                else if (mostNearPart.mLeftTopPoint.X > midMaxPoint.X)
                {
                    foreach (CMrPart mrPart in mrPartList)
                    {
                        CMrBoltArray mrBoltArray = mrPart.GetBoltArrayList()[0];
                        Point        boltPoint   = mrBoltArray.GetMaxXPoint();
                        mrDimSet.AddPoint(boltPoint);
                    }

                    mrDimSet.mDimVector   = CMrBeamDoorManager.GetInstance().mRightTopVector;
                    mrDimSet.mDimDistance = CCommonPara.mDefaultDimDistance;
                    mrDimSetList.Add(mrDimSet);

                    //(2).与顶板竖直方向标注;
                    mrDimSet = new CMrDimSet();
                    mrDimSet.AddPoint(mrPartList[0].mRightBottomPoint);

                    Point fontPt = CDimTools.GetInstance().ComputeFootPointToLine(mrPartList[0].mRightBottomPoint, rightTopPoint, midMaxPoint);
                    mrDimSet.AddPoint(fontPt);
                    mrDimSet.mDimDistance = CCommonPara.mDefaultDimDistance;

                    mrDimSet.mDimVector = new Vector(rightTopPoint.X - midMaxPoint.X, rightTopPoint.Y - midMaxPoint.Y, 0);
                    mrDimSetList.Add(mrDimSet);
                }
            }
            foreach (CMrDimSet mrDimSet in mrDimSetList)
            {
                List <Point> dimPointList = mrDimSet.GetDimPointList();

                PointList pointList = new PointList();

                foreach (Point point in dimPointList)
                {
                    pointList.Add(point);
                }

                Vector dimVector = mrDimSet.mDimVector;
                double length    = mrDimSet.mDimDistance;

                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, dimVector, length, CCommonPara.mSizeDimPath);
            }
        }
 public void AddPnt(Point2D point2D)
 {
     PointList.Add(point2D);
 }
Beispiel #15
0
        /// <summary> Process a list of points defining a polygon</summary>
        /// <param name="contour">The list of points describing the polygon
        /// </param>
        /// <param name="result">The list of points describing the triangles. Groups
        /// of 3 describe each triangle 
        /// 
        /// </param>
        /// <returns> True if we succeeded in completing triangulation
        /// </returns>
        private bool Process(PointList contour, PointList result)
        {
            /* allocate and initialize list of Vertices in polygon */

            int n = contour.Size();
            if (n < 3)
                return false;

            int[] V = new int[n];

            /* we want a counter-clockwise polygon in V */

            if (0.0f < Area(contour))
            {
                for (int v = 0; v < n; v++)
                    V[v] = v;
            }
            else
            {
                for (int v = 0; v < n; v++)
                    V[v] = (n - 1) - v;
            }

            int nv = n;

            /*  Remove nv-2 Vertices, creating 1 triangle every time */
            int count = 2 * nv; /* error detection */

            for (int m = 0, v = nv - 1; nv > 2; )
            {
                /* if we loop, it is probably a non-simple polygon */
                if (0 >= (count--))
                {
                    //** Triangulate: ERROR - probable bad polygon!
                    return false;
                }

                /* three consecutive vertices in current polygon, <u,v,w> */
                int u = v;
                if (nv <= u)
                    u = 0; /* previous */
                v = u + 1;
                if (nv <= v)
                    v = 0; /* new v    */
                int w = v + 1;
                if (nv <= w)
                    w = 0; /* Next     */

                if (Snip(contour, u, v, w, nv, V))
                {
                    int a, b, c, s, t;

                    /* true names of the vertices */
                    a = V[u];
                    b = V[v];
                    c = V[w];

                    /* output Triangle */
                    result.Add(contour.Item(a));
                    result.Add(contour.Item(b));
                    result.Add(contour.Item(c));

                    m++;

                    /* Remove v from remaining polygon */
                    for (s = v, t = v + 1; t < nv; s++, t++)
                    {
                        V[s] = V[t];
                    }
                    nv--;

                    /* resest error detection counter */
                    count = 2 * nv;
                }
            }

            return true;
        }
Beispiel #16
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     PointList.Add(null);
     PointList = PointList;
 }
		public List<LocationOfInterest> GetInterestingLocationsCheating(Avatar observer)
		{
			List<LocationOfInterest> locationsOfInterest = new List<LocationOfInterest>();

			MapTile observerTile = _quest.GetAvatarMapTile(observer);
			Point observerLocation = _quest.Map.GetMapTileLocation(observerTile);
			PointList visibleLocations = _quest.Map.GetPointsWithinLineOfSightOf(observerLocation);

			//// Get a list of all actionable map tiles
			PointList interestingLocations = _quest.Map.GetActionableMapPoints(observer.Faction);

			// Find the closest location by straight-line distance.  It was too expensive to calculate Pathfinding distance.
			PathfindingNode observerNode = _quest.Map.GetPathfindingNodeForTile(observerTile);
			Point closestDistanceInterestingLocation = null;
			double closestDistance = float.MaxValue;
			foreach (Point point in interestingLocations)
			{
				double distance = Math.Sqrt(Math.Pow(observerLocation.X - point.X, 2) + Math.Pow(observerLocation.Y - point.Y, 2));
				if (distance < closestDistance)
				{
					closestDistanceInterestingLocation = point;
					closestDistance = distance;
				}
			}

			if (closestDistanceInterestingLocation != null)
			{
				PathfindingNode pointNode = _quest.Map.GetPathfindingNodeForLocation(closestDistanceInterestingLocation.X, closestDistanceInterestingLocation.Y);
				List<PathfindingNode> path = _quest.Map.PathfindingGraph.FindRoute(observerNode, pointNode);
				if (path != null)
				{
					PointList pathSteps = new PointList();
					for (int i = 1; i < path.Count; i++)
					{ pathSteps.Add(_quest.Map.GetPointForPathfindingNode(path[i])); }

					LocationOfInterest interest = new LocationOfInterest(pathSteps);
					locationsOfInterest.Add(interest);
					return locationsOfInterest;
				}
			}

			return locationsOfInterest;
		}
Beispiel #18
0
 private PointList<int, int> CalcEnemyShipCountPerSector()
 {
     PointList<int, int> result = new PointList<int, int>();
     foreach (IVisible unit in mComputerView)
         if (unit is ISpaceship && unit.Allegiance == Allegiance.Player)
         {
             Point sector = mUnitSectorManager.GetSector(unit.Position);
             if (result.Contains(sector.X, sector.Y))
                 result.Set(sector.X, sector.Y, result.Get(sector.X, sector.Y)+1);
             else
                 result.Add(sector.X, sector.Y, 1);
         }
     return result;
 }
Beispiel #19
0
        /// <summary>
        /// Creates single h-line at the specified vertical offset.
        /// </summary>
        private PointList BuildLine(float yOff)
        {
            PointF p11 = new PointF(_bounds.Left - 1, 0);
            PointF p12 = new PointF(_bounds.Right + 1, 0);
            PointF p21 = new PointF(_bounds.Left - 1, 0);
            PointF p22 = new PointF(_bounds.Right + 1, 0);

            p11.Y = p12.Y = yOff;
            yOff += _text.Height;
            if (yOff > _bounds.Bottom)
            {
                return(null);
            }
            p21.Y = p22.Y = yOff;

            ArrayList merge  = new ArrayList();
            PointList result = new PointList();
            PointList row1   = PolygonIntersect(p11, p12);
            PointList row2   = PolygonIntersect(p21, p22);

            int i;

            for (i = 0; i < row1.Count; i++)
            {
                merge.Add(new DirPt(row1[i], i % 2 == 1 ? 2 : 0));
            }
            for (i = 0; i < row2.Count; i++)
            {
                merge.Add(new DirPt(row2[i], i % 2 == 1 ? 3 : 1));
            }

            merge.Sort();

            PointF pt    = PointF.Empty;
            int    inter = -1;          // 0 - for first line, 2 for second line, 4 - for both

            for (i = 0; i < merge.Count; i++)
            {
                DirPt temp = merge[i] as DirPt;

                if (temp.Direction == 2 || temp.Direction == 3)                 // out
                {
                    if (inter != 4)
                    {
                        if (inter == 0 && temp.Direction == 2)
                        {
                            inter = -1;
                        }
                        else if (inter == 2 && temp.Direction == 3)
                        {
                            inter = -1;
                        }
                        continue;
                    }

                    pt.Y       = yOff - _text.Height;
                    temp.Point = new PointF(temp.Point.X, yOff);

                    // Make points relative to the upper-left point of the polygon
                    pt.X      -= _bounds.Left;
                    pt.Y      -= _bounds.Top;
                    temp.Point = new PointF(
                        temp.Point.X - _bounds.Left,
                        temp.Point.Y - _bounds.Top);

                    result.Add(pt);
                    result.Add(temp.Point);

                    if (temp.Direction == 2)
                    {
                        inter = 2;
                    }
                    else
                    {
                        inter = 0;
                    }
                }
                else
                {
                    pt = temp.Point;

                    if (temp.Direction == 0)
                    {
                        if (inter == -1)
                        {
                            inter = 0;
                        }
                        else if (inter == 2)
                        {
                            inter = 4;
                        }
                    }
                    else
                    {
                        if (inter == -1)
                        {
                            inter = 2;
                        }
                        else if (inter == 0)
                        {
                            inter = 4;
                        }
                    }
                }
            }

            // Check if the center point of each
            // rectangle lies within the polygon
            for (i = 0; i < result.Count;)
            {
                PointF pt1 = result[i];
                PointF pt2 = result[i + 1];
                PointF ptc = PointF.Empty;

                ptc.X = (pt1.X + pt2.X) / 2 + _bounds.Left;
                ptc.Y = (pt1.Y + pt2.Y) / 2 + _bounds.Top;

                if (!_polygon.Contains(ptc))
                {
                    result.RemoveAt(i);
                    result.RemoveAt(i);
                }
                else
                {
                    i += 2;
                }
            }

            return(result);
        }
Beispiel #20
0
        private void makeOrthogonalPoints()
        {
            bool failed = false;

            if (!IsEditingPoint)
            {
                if (!isSubstituteLine && !IsDragged && !HasComputed && !loaded)
                {
                    List <Node>      nodeList = new List <Node>();
                    FrameworkElement parent   = Model.WorkspaceModel.MyEditor.Presentation;

                    // add start and end. Index will be 0 and 1
                    Node startNode = new Node()
                    {
                        Point = LineUtil.Cheat42(StartPoint, StartPointSource, 1)
                    },
                         endNode = new Node()
                    {
                        Point = LineUtil.Cheat42(EndPoint, EndPointSource, -1)
                    };
                    nodeList.Add(startNode);
                    nodeList.Add(endNode);

                    QuadTreeLib.QuadTree <FakeNode> quadTreePlugins = helper.PluginTree;

                    for (int routPoint = 0; routPoint < 4; ++routPoint)
                    {
                        foreach (var element in Visuals)
                        {
                            if (element is ComponentVisual)
                            {
                                IRouting p1 = element as IRouting;
                                nodeList.Add(new Node()
                                {
                                    Point = p1.GetRoutingPoint(routPoint)
                                });
                            }
                        }
                    }

                    // connect points
                    int       loopCount             = nodeList.Count;
                    const int performanceTradeoffAt = 2;

                    LinkedList <Node> path = null;

                    for (int i = 0; i < loopCount; ++i)
                    {
                        StackFrameDijkstra.Dijkstra <Node> dijkstra = new StackFrameDijkstra.Dijkstra <Node>();
                        path = dijkstra.findPath(nodeList, startNode, endNode);
                        if (path != null)
                        {
                            break;
                        }

                        var p1 = nodeList[i];
                        // TODO: inner loop restriction! n²-n!
                        // is k=i instead of k=0 correct?
                        for (int k = i; k < loopCount; ++k)
                        {
                            var p2 = nodeList[k];
                            if (p1 == p2)
                            {
                                continue;
                            }
                            if (p1.Vertices.Contains(p2))
                            {
                                continue;
                            }

                            // no helping point required?
                            if (p1.Point.X == p2.Point.X ||
                                p1.Point.Y == p2.Point.Y)
                            {
                                LineUtil.PerformOrthogonalPointConnection(p1, p2, quadTreePlugins);
                            }
                            else
                            {
                                Point help = new Point(p1.Point.X, p2.Point.Y);

                                if (!LineUtil.PerformOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins))
                                {
                                    help = new Point(p2.Point.X, p1.Point.Y);
                                    if (!LineUtil.PerformOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins))
                                    {
                                        // optional todo: double edge helping routes
                                    }
                                }
                            }
                        }
                    }

                    if (path == null)
                    {
                        StackFrameDijkstra.Dijkstra <Node> dijkstra = new StackFrameDijkstra.Dijkstra <Node>();
                        path = dijkstra.findPath(nodeList, startNode, endNode);
                    }

                    if (path != null)
                    {
                        var list = path.ToList();
                        PointList.Clear();
                        Point startPoint = StartPoint, curPoint, prevPoint = startPoint;
                        bool  isStart = true;
                        for (int c = 0; c < list.Count; ++c)
                        {
                            var i = list[c];
                            curPoint = i.Point;
                            //this.PointList.Add(new FromTo(prevPoint, curPoint));
                            if ((startPoint.X != curPoint.X && startPoint.Y != curPoint.Y))
                            {
                                if (isStart)
                                {
                                    this.PointList.Add(new FromTo(startPoint, prevPoint, FromToMeta.HasStartPoint));
                                    isStart = false;
                                }
                                else
                                {
                                    this.PointList.Add(new FromTo(startPoint, prevPoint));
                                }

                                startPoint = prevPoint;
                            }
                            if (c == list.Count - 1)
                            {
                                if ((startPoint.X != EndPoint.X && startPoint.Y != EndPoint.Y))
                                {
                                    this.PointList.Add(new FromTo(startPoint, curPoint));
                                    startPoint = curPoint;
                                }
                            }

                            prevPoint = curPoint;
                        }
                        this.PointList.Add(new FromTo(startPoint, EndPoint, FromToMeta.HasEndpoint));
                        HasComputed = true;
                        raiseComputationDone(true);
                        return;
                    }
                    failed = true;
                }
                //Failsafe
                if (IsDragged || failed || isSubstituteLine)
                {
                    if (StartPoint.X < EndPoint.X)
                    {
                        PointList.Clear();
                        PointList.Add(new FromTo(StartPoint, new Point((EndPoint.X + StartPoint.X) / 2, StartPoint.Y)));
                        PointList.Add(new FromTo(new Point((EndPoint.X + StartPoint.X) / 2, StartPoint.Y), new Point((EndPoint.X + StartPoint.X) / 2, EndPoint.Y)));
                        PointList.Add(new FromTo(new Point((EndPoint.X + StartPoint.X) / 2, EndPoint.Y), EndPoint));
                    }
                    else
                    {
                        if (StartPoint.X > EndPoint.X)
                        {
                            PointList.Clear();
                            PointList.Add(new FromTo(StartPoint, new Point((StartPoint.X + EndPoint.X) / 2, StartPoint.Y)));
                            PointList.Add(new FromTo(new Point((StartPoint.X + EndPoint.X) / 2, StartPoint.Y), new Point((StartPoint.X + EndPoint.X) / 2, EndPoint.Y)));
                            PointList.Add(new FromTo(new Point((StartPoint.X + EndPoint.X) / 2, EndPoint.Y), EndPoint));
                        }
                    }
                }
                raiseComputationDone(false);
            }
            raiseComputationDone(true);
        }
Beispiel #21
0
        /// <summary>
        /// 绘制所有零件向下的分尺寸;
        /// </summary>
        public void DrawAllPartDownFenSizeDimX()
        {
            //移除主梁;
            mMrPartList.Remove(mMainBeam);

            bool         bNeedHorizontalConnectPlateDim = false;
            bool         bNeedOtherPartDim = false;
            List <Point> horizontalConnectPlateDimPointList = new List <Point>();
            List <Point> otherPartDimPointList = new List <Point>();

            //1.遍历获得所有零件的向上标注的点;
            foreach (CMrPart mrPart in mMrPartList)
            {
                Vector    normal     = mrPart.mNormal;
                CMrDimSet partDimSet = mrPart.GetBeamTopViewInfo().GetPartDownDimSet();

                if (partDimSet != null && partDimSet.Count > 0)
                {
                    //如果是水平连接板及支撑板、H型钢等;
                    if (CDimTools.GetInstance().IsPartTheSupportPlate(mrPart))
                    {
                        bNeedHorizontalConnectPlateDim = true;
                        horizontalConnectPlateDimPointList.AddRange(partDimSet.GetDimPointList());
                    }
                    else
                    {
                        bNeedOtherPartDim = true;
                        otherPartDimPointList.AddRange(partDimSet.GetDimPointList());
                    }
                }
            }

            Point minXPoint = mMainBeam.GetMinXMinYPoint();
            Point maxXPoint = mMainBeam.GetMaxXMinYPoint();

            //1.如果其他剩下的零件需要标注;
            if (bNeedOtherPartDim)
            {
                PointList pointList = new PointList();

                foreach (Point pt in otherPartDimPointList)
                {
                    pointList.Add(pt);
                }

                pointList.Add(minXPoint);
                pointList.Add(maxXPoint);

                Vector upDimVector = new Vector(0, -1, 0);
                mDownDimDistance = GetDownDimDistance(pointList[0]);
                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, upDimVector, mDownDimDistance, CCommonPara.mSizeDimPath);
            }
            //2.如果水平连接板及支撑需要标注;
            if (bNeedHorizontalConnectPlateDim)
            {
                PointList pointList = new PointList();

                foreach (Point pt in horizontalConnectPlateDimPointList)
                {
                    pointList.Add(pt);
                }

                pointList.Add(minXPoint);
                pointList.Add(maxXPoint);

                Vector upDimVector = new Vector(0, -1, 0);
                mDownDimDistance = GetDownDimDistance(pointList[0]);
                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, upDimVector, mDownDimDistance, CCommonPara.mSizeDimPath);
            }

            mMrPartList.Add(mMainBeam);
        }
Beispiel #22
0
		/// <summary>
		/// Creates single h-line at the specified vertical offset.
		/// </summary>
		private PointList BuildLine(float yOff)
		{
			PointF p11 = new PointF(_bounds.Left - 1, 0);
			PointF p12 = new PointF(_bounds.Right + 1, 0);
			PointF p21 = new PointF(_bounds.Left - 1, 0);
			PointF p22 = new PointF(_bounds.Right + 1, 0);

			p11.Y = p12.Y = yOff;
			yOff += _text.Height;
			if (yOff > _bounds.Bottom)
				return null;
			p21.Y = p22.Y = yOff;

			ArrayList merge = new ArrayList();
			PointList result = new PointList();
			PointList row1 = PolygonIntersect(p11, p12);
			PointList row2 = PolygonIntersect(p21, p22);

			int i;
			for (i = 0; i < row1.Count; i++)
				merge.Add(new DirPt(row1[i], i % 2 == 1 ? 2 : 0));
			for (i = 0; i < row2.Count; i++)
				merge.Add(new DirPt(row2[i], i % 2 == 1 ? 3 : 1));

			merge.Sort();

			PointF pt = PointF.Empty;
			int inter = -1; // 0 - for first line, 2 for second line, 4 - for both
			for (i = 0; i < merge.Count; i++)
			{
				DirPt temp = merge[i] as DirPt;

				if (temp.Direction == 2 || temp.Direction == 3) // out
				{
					if (inter != 4)
					{
						if (inter == 0 && temp.Direction == 2)
							inter = -1;
						else if (inter == 2 && temp.Direction == 3)
							inter = -1;
						continue;
					}

					pt.Y = yOff - _text.Height;
					temp.Point = new PointF(temp.Point.X, yOff);

					// Make points relative to the upper-left point of the polygon
					pt.X -= _bounds.Left;
					pt.Y -= _bounds.Top;
					temp.Point = new PointF(
						temp.Point.X - _bounds.Left,
						temp.Point.Y - _bounds.Top);

					result.Add(pt);
					result.Add(temp.Point);

					if (temp.Direction == 2)
						inter = 2;
					else
						inter = 0;
				}
				else
				{
					pt = temp.Point;

					if (temp.Direction == 0)
					{
						if (inter == -1)
							inter = 0;
						else if (inter == 2)
							inter = 4;
					}
					else
					{
						if (inter == -1)
							inter = 2;
						else if (inter == 0)
							inter = 4;
					}
				}
			}

			// Check if the center point of each
			// rectangle lies within the polygon
			for (i = 0; i < result.Count; )
			{
				PointF pt1 = result[i];
				PointF pt2 = result[i + 1];
				PointF ptc = PointF.Empty;
		
				ptc.X = (pt1.X + pt2.X) / 2 + _bounds.Left;
				ptc.Y = (pt1.Y + pt2.Y) / 2 + _bounds.Top;

				if (!_polygon.Contains(ptc))
				{
					result.RemoveAt(i);
					result.RemoveAt(i);
				}
				else
				{
					i += 2;
				}
			}

			return result;
		}
Beispiel #23
0
        /// <summary>
        /// 绘制下侧的零部件标注;
        /// </summary>
        private void DrawYVectorDownDim()
        {
            List <Point> pointList = new List <Point>();

            bool bNeedAddLeftPart  = true;
            bool bNeedAddRightPart = true;

            foreach (CMrPart mrPart in mMrPartList)
            {
                double maxY = mrPart.GetMaxYPoint().Y;
                double minY = mrPart.GetMinYPoint().Y;

                if (minY > 0 && maxY > 0)
                {
                    continue;
                }

                Vector normal = mrPart.mNormal;

                //1.如果法向与Z轴平行并且有螺钉;
                List <CMrBoltArray> mrBoltArrayList = mrPart.GetBoltArrayList();

                foreach (CMrBoltArray mrBoltArray in mrBoltArrayList)
                {
                    if (!CDimTools.GetInstance().IsTwoVectorParallel(mrBoltArray.mNormal, new Vector(0, 0, 1)))
                    {
                        continue;
                    }
                    if (mDicBoltArrayToUpDim.ContainsKey(mrBoltArray))
                    {
                        continue;
                    }

                    List <Point> minYPointList = mrBoltArray.GetMinYPointList();
                    pointList.AddRange(minYPointList);
                }

                //2.如果法向与Y轴平行;
                if (CDimTools.GetInstance().IsTwoVectorParallel(normal, new Vector(1, 0, 0)))
                {
                    if (mrPart.GetMaxXPoint().X < mLeftPart.GetMaxXPoint().X || mrPart.GetMinXPoint().X > mRightPart.GetMinXPoint().X)
                    {
                        continue;
                    }

                    if (!IsLeftPartNeedDim(mrPart))
                    {
                        bNeedAddLeftPart = false;
                        pointList.Add(mrPart.GetMinYMaxXPoint());
                    }
                    else if (!IsRightPartNeedDim(mrPart))
                    {
                        bNeedAddRightPart = false;
                        pointList.Add(mrPart.GetMinYMinXPoint());
                    }
                    else
                    {
                        pointList.Add(mrPart.GetMinYMinXPoint());
                    }
                }
                if (IsMidPlate(mrPart))
                {
                    pointList.Add(mrPart.GetMinYMinXPoint());
                    pointList.Add(mrPart.GetMinYMaxXPoint());
                }
            }
            if (pointList.Count == 0)
            {
                return;
            }

            if (mLeftPart != null && bNeedAddLeftPart)
            {
                pointList.Add(mLeftPart.GetMinYMinXPoint());
            }
            if (mRightPart != null && bNeedAddRightPart)
            {
                pointList.Add(mRightPart.GetMinYMaxXPoint());
            }

            Comparison <Point> sorterX = new Comparison <Point>(CDimTools.ComparePointX);

            pointList.Sort(sorterX);

            PointList dimPointList = new PointList();

            foreach (Point pt in pointList)
            {
                dimPointList.Add(pt);
            }

            Vector dimVector   = new Vector(0, -1, 0);
            double dimDistance = Math.Abs(CCommonPara.mViewMinY - pointList[0].Y) + 0.6 * CCommonPara.mDefaultDimDistance;

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, dimPointList, dimVector, dimDistance, CCommonPara.mSizeDimPath);
        }
Beispiel #24
0
        /// <summary>
        /// 绘制左侧零部件的标注;
        /// </summary>
        private void DrawYVectorLeftDim()
        {
            List <Point> pointList = new List <Point>();

            foreach (CMrPart mrPart in mMrPartList)
            {
                if (mrPart.GetMinXPoint().X > mRightPart.GetMinXPoint().X)
                {
                    continue;
                }
                if (!mrPart.IsHaveBolt())
                {
                    continue;
                }

                bool bFlag = false;

                List <CMrBoltArray> mrBoltArrayList = mrPart.GetBoltArrayList();

                foreach (CMrBoltArray mrBoltArray in mrBoltArrayList)
                {
                    if (!CDimTools.GetInstance().IsTwoVectorParallel(mrBoltArray.mNormal, new Vector(0, 0, 1)))
                    {
                        continue;
                    }
                    if (mDicBoltArrayToRightDim.ContainsKey(mrBoltArray))
                    {
                        continue;
                    }

                    List <Point> minXPointList = mrBoltArray.GetMinXPointList();

                    pointList.AddRange(minXPointList);

                    bFlag = true;
                }
                if (bFlag)
                {
                    pointList.Add(new Point(mrPart.GetMinXPoint().X, 0, 0));

                    if (IsMidPlate(mrPart))
                    {
                        pointList.Add(mrPart.GetMaxYMinXPoint());
                        pointList.Add(mrPart.GetMinYMinXPoint());
                    }
                }
            }

            if (pointList.Count == 0 || pointList.Count == 1)
            {
                return;
            }

            PointList dimPointList = new PointList();

            foreach (Point pt in pointList)
            {
                dimPointList.Add(pt);
            }

            Vector dimVector   = new Vector(-1, 0, 0);
            double dimDistance = Math.Abs(CCommonPara.mViewMinX - pointList[0].X) + 0.6 * CCommonPara.mDefaultDimDistance;

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, dimPointList, dimVector, dimDistance, CCommonPara.mSizeDimPath);
        }
Beispiel #25
0
        /// <summary>
        /// 绘制主梁法向朝X方向的剖面标注;
        /// </summary>
        private void DrawXVectorSectionDim()
        {
            List <Point> upPointList    = new List <Point>();
            List <Point> rightPointList = new List <Point>();

            foreach (CMrPart mrPart in mMrPartList)
            {
                Vector normal = mrPart.mNormal;

                if (!CDimTools.GetInstance().IsTwoVectorParallel(normal, new Vector(0, 0, 1)) || !mrPart.IsHaveBolt())
                {
                    continue;
                }

                List <CMrBoltArray> mrBoltArrayList = mrPart.GetBoltArrayList();

                foreach (CMrBoltArray mrBoltArray in mrBoltArrayList)
                {
                    if (!CDimTools.GetInstance().IsTwoVectorParallel(normal, new Vector(0, 0, 1)))
                    {
                        continue;
                    }

                    List <Point> maxYPointList = mrBoltArray.GetMaxYPointList();
                    upPointList.AddRange(maxYPointList);

                    List <Point> maxXPointList = mrBoltArray.GetMaxXPointList();
                    rightPointList.AddRange(maxXPointList);
                }

                upPointList.Add(mrPart.GetMaxYMinXPoint());
                upPointList.Add(mrPart.GetMaxYMaxXPoint());

                rightPointList.Add(mrPart.GetMaxYMaxXPoint());
                rightPointList.Add(mrPart.GetMinYMaxXPoint());
            }

            //顶部标注;
            PointList upDimPointList = new PointList();
            Vector    dimVector      = new Vector(0, 1, 0);
            double    dimDistance    = Math.Abs(CCommonPara.mViewMaxY - upPointList[0].Y) + 0.6 * CCommonPara.mDefaultDimDistance;

            foreach (Point pt in upPointList)
            {
                upDimPointList.Add(pt);
            }
            CDimTools.GetInstance().DrawDimensionSet(mViewBase, upDimPointList, dimVector, dimDistance, CCommonPara.mSizeDimPath);

            //右侧标注;
            PointList rightDimPointList = new PointList();

            dimVector   = new Vector(1, 0, 0);
            dimDistance = Math.Abs(CCommonPara.mViewMaxX - upPointList[0].X) + 0.6 * CCommonPara.mDefaultDimDistance;

            foreach (Point pt in rightPointList)
            {
                rightDimPointList.Add(pt);
            }

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, rightDimPointList, dimVector, dimDistance, CCommonPara.mSizeDimPath);
        }
		public PointList GetActionableMapPoints(Faction faction)
		{
			PointList actionableLocations = new PointList();

			for (int y = 0; y < MAP_HEIGHT_IN_TILES; y++)
			{
				for (int x = 0; x < MAP_WIDTH_IN_TILES; x++)
				{
					MapTileList locationTiles = GetMapTilesForLocation(x, y);
					foreach (MapTile tile in locationTiles)
					{
						if (tile.HasActionsFor(faction))
						{ actionableLocations.Add(new Point(x, y)); }
					}
				}
			}

			return actionableLocations;
		}
		public PointList GetPointsWithinLineOfSightOf(Point origin)
		{
			PointList lineOfSight = new PointList();
			lineOfSight.Add(origin);

			// Start with the origin point, and check adjacent nodes that are "within line of sight". Probably need to modify the MapTile class to include a "blocks line of sight" property?
			PointList visitedPoints = new PointList();
			visitedPoints.Add(origin);
			PointList pointsLeftToVisit = GetVisibleAdjacentPoints(origin, visitedPoints);
			while (pointsLeftToVisit.Count > 0)
			{
				Point currentPoint = pointsLeftToVisit[0];
				pointsLeftToVisit.RemoveAt(0);
				visitedPoints.Add(currentPoint);
				if (CanSeePointFromPoint(origin, currentPoint))
				{
					lineOfSight.Add(currentPoint);

					// Check each adjacent node.  If they are within line of sight, add their adjacent nodes.  
					// Always check the line of sight from the origin, however.  Use the GetStraightPathBetweenTwoPoints method to generate the line.
					// Given the line, 
					pointsLeftToVisit.AddDistinctPointsOnly(GetVisibleAdjacentPoints(currentPoint, visitedPoints));
				}
			}

			return lineOfSight;
		}
Beispiel #28
0
        public override void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (World.Settings.CurrentWwTool != this.drawTool)
            {
                return;
            }

            if (!isOn)
            {
                return;
            }

            // Test if mouse was clicked and dragged
            if (mouseDragged())
            {
                return;
            }

            //multiline = new MeasureMultiLine();

            //  MouseButtons.Right
            if (e.Button == MouseButtons.Right)
            {
                State = DrawState.Idle;

                this.Dispose();

                return;
            }

            //  MouseButtons.Other mouse buttons clicked
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // MouseButtons.Left
            #region state

            if (State == DrawState.Idle)
            {
                if (!this.Initialized)
                {
                    this.Initialize(this.drawArgs);
                }
                State = DrawState.Drawing;
            }

            #endregion
            if ((State == DrawState.Drawing && PointList.Count < 1) && this.Initialized)
            {
                Angle lat;
                Angle lon;

                //get Point
                this.drawArgs.WorldCamera.PickingRayIntersection(
                    e.X,
                    e.Y,
                    out lat,
                    out lon);

                if (Angle.IsNaN(lat))
                {
                    return;
                }

                Point3d pickPt = new Point3d();
                pickPt.X = lon.Degrees;
                pickPt.Y = lat.Degrees;
                pickPt.Z = (useTerrain) ? getElevation(lat.Degrees, lon.Degrees) : defaultElev;

                if (PointList.Count > 0)
                {
                    List <CustomVertex.PositionColored> newVertexes = getCurveFromPoints(PointList[PointList.Count - 1], pickPt, lineColor);
                    VertexList.AddRange(newVertexes.GetRange(1, newVertexes.Count - 1));
                }
                else
                {
                    VertexList.Add(Point3d2PositionColored(pickPt, lineColor));
                }

                PointList.Add(pickPt);

                //UpdatePolygenFeature();
            }
        }
Beispiel #29
0
        /// <summary>
        /// 绘制中间主梁类型为3时向上的标注;
        /// </summary>
        private void DrawTypeMiddle3XUpDim()
        {
            //1.绘制左侧上方的标注;
            bool bNeedUpDim = false;

            List <Point> upDimPointList = new List <Point>();

            foreach (CMrPart mrPart in mMrPartList)
            {
                CMrDimSet partDimSet = mrPart.GetBeamDoorFrontViewInfo().GetTypeMiddle3XUpDimSetMiddle();

                if (partDimSet != null && partDimSet.Count > 0)
                {
                    bNeedUpDim = true;
                    upDimPointList.AddRange(partDimSet.GetDimPointList());
                }
            }
            if (bNeedUpDim == false)
            {
                return;
            }

            CMrPart topBeam = CMrBeamDoorManager.GetInstance().mTopBeam;

            Point leftTopPt  = topBeam.mLeftTopPoint;
            Point rightTopPt = topBeam.mRightTopPoint;

            upDimPointList.Add(leftTopPt);
            upDimPointList.Add(rightTopPt);

            Comparison <Point> sorterX = new Comparison <Point>(CDimTools.ComparePointX);

            upDimPointList.Sort(sorterX);

            PointList pointList = new PointList();

            foreach (Point point in upDimPointList)
            {
                pointList.Add(point);
            }

            double dimDistance = Math.Abs(CCommonPara.mViewMaxY - upDimPointList[0].Y) + 2 * CCommonPara.mDefaultDimDistance;

            //计算标注向量;
            Vector directVector = new Vector(rightTopPt.X - leftTopPt.X, rightTopPt.Y - leftTopPt.Y, 0);

            directVector.Normalize();
            Vector upDimVector = new Vector(directVector.Y, -directVector.X, 0);

            MrSlopeType mrSlopeType = CDimTools.GetInstance().JudgeLineSlope(directVector, new Point(0, 0, 0));

            if (mrSlopeType == MrSlopeType.LESSTHAN_ZERO)
            {
                upDimVector = new Vector(Math.Abs(upDimVector.X), Math.Abs(upDimVector.Y), 0);
            }
            else if (mrSlopeType == MrSlopeType.MORETHAN_ZERO)
            {
                upDimVector = new Vector(-Math.Abs(upDimVector.X), Math.Abs(upDimVector.Y), 0);
            }

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, upDimVector, dimDistance, CCommonPara.mSizeDimPath);

            //2.再标注一个总长度;
            pointList.Clear();
            pointList.Add(leftTopPt);
            pointList.Add(rightTopPt);

            dimDistance = Math.Abs(CCommonPara.mViewMaxY - leftTopPt.Y) + 4 * CCommonPara.mDefaultDimDistance;

            CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, upDimVector, dimDistance, CCommonPara.mSizeDimPath);
        }
Beispiel #30
0
        protected int MakePath(int x, int y, List <uint> areas, bool MoveThrough)
        {
            uint dwCount = 0;
            var  aPath   = new Point[255];

            var g_collisionMap = game.MapHandler.GetCollisionData(areas.ToArray());

            if (!g_collisionMap.m_map.IsCreated())
            {
                return(0);
            }

            UnitAny unit;

            if (!game.GetPlayerUnit(out unit) || unit.pPath == 0)
            {
                return(0);
            }

            var path = game.Debugger.Read <Path>(unit.pPath);

            var ptStart = new Point(path.xPos, path.yPos);
            var ptEnd   = new Point(x, y);

            if (!g_collisionMap.IsValidAbsLocation(ptStart.X, ptStart.Y))
            {
                return(0);
            }

            if (!g_collisionMap.IsValidAbsLocation(ptEnd.X, ptEnd.Y))
            {
                return(0);
            }

            g_collisionMap.AbsToRelative(ref ptStart);
            g_collisionMap.AbsToRelative(ref ptEnd);

            var matrix = new CMatrix <ushort>();

            if (!g_collisionMap.CopyMapData(matrix))
            {
                return(0);
            }

            var tf = new TeleportPath(matrix.GetData(), matrix.CX, matrix.CY);

            dwCount = tf.FindTeleportPath(ptStart, ptEnd, aPath, 255);
            if (dwCount == 0)
            {
                return(0);
            }

            for (var i = 0; i < dwCount; ++i)
            {
                g_collisionMap.RelativeToAbs(ref aPath[i]);
            }

            if (MoveThrough)
            {
                if (aPath[dwCount - 1].X > aPath[dwCount - 2].X)
                {
                    aPath[dwCount].X = aPath[dwCount - 1].X + 2;
                }
                else
                {
                    aPath[dwCount].X = aPath[dwCount - 1].X - 2;
                }
                if (aPath[dwCount - 1].Y > aPath[dwCount - 2].Y)
                {
                    aPath[dwCount].Y = aPath[dwCount - 1].Y + 2;
                }
                else
                {
                    aPath[dwCount].Y = aPath[dwCount - 1].Y - 2;
                }

                ++dwCount;

                if (TeleportPath.CalculateDistance(aPath[dwCount - 1].X, aPath[dwCount - 1].Y, aPath[dwCount - 3].X, aPath[dwCount - 3].Y) <= (uint)Range.TpRange)
                {
                    aPath[dwCount - 2]   = aPath[dwCount - 1];
                    aPath[dwCount - 1].X = 0;
                    aPath[dwCount - 1].Y = 0;
                    --dwCount;
                }
            }

            TPath.Clear();
            for (var i = 0; i < dwCount; ++i)
            {
                TPath.Add(aPath[i]);
            }

            return((int)dwCount);
        }
 public ColorGradient(Color staticColor)
     : this()
 {
     _colors.Clear();
     _colors.Add(new ColorPoint(staticColor, 0));
 }
Beispiel #32
0
        /// <summary>
        /// 鼠标弹起事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (World.Settings.CurrentWwTool != this.drawPlugin)
            {
                return;
            }

            if (!isOn)
            {
                return;
            }

            // Test if mouse was clicked and dragged  测试鼠标是单击还是拖动
            if (mouseDragged())
            {
                return;
            }

            //  鼠标右键单击,清除绘制图形
            if (e.Button == MouseButtons.Right)
            {
                State = DrawState.Idle;
                this.Dispose();
                return;
            }

            //  其他鼠标单击弹起,直接退出
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // 鼠标左键弹起事件
            if (State == DrawState.Idle)
            {
                if (!this.Initialized)
                {
                    this.Initialize(this.drawArgs);
                }
                State = DrawState.Drawing;
            }
            //处于绘制状态、点列表的数目<1、初始化完毕
            if ((State == DrawState.Drawing && PointList.Count < 1) && this.Initialized)
            {
                Angle lat;
                Angle lon;

                //获取点的经纬度信息
                this.drawArgs.WorldCamera.PickingRayIntersection(
                    e.X,
                    e.Y,
                    out lat,
                    out lon);

                if (Angle.IsNaN(lat))
                {
                    return;
                }

                Point3d pickPt = new Point3d();
                pickPt.X = lon.Degrees;
                pickPt.Y = lat.Degrees;
                pickPt.Z = (useTerrain) ? getElevation(lat.Degrees, lon.Degrees) : defaultElev;

                if (PointList.Count > 0)
                {
                    List <CustomVertex.PositionColored> newVertexes = getCurveFromPoints(PointList[PointList.Count - 1], pickPt, lineColor);
                    VertexList.AddRange(newVertexes.GetRange(1, newVertexes.Count - 1));
                }
                else
                {
                    VertexList.Add(Point3d2PositionColored(pickPt, lineColor));
                }

                PointList.Add(pickPt);
            }
        }
Beispiel #33
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     PointList.Add(new Point(11.2, 1.6));
     PointList = PointList;
 }
Beispiel #34
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            PointList points = new PointList();
            var input = (args[0] as Value.List).Item;

            foreach (Value v in input)
            {
                Point p = ((Value.Container)v).Item as Point;
                points.Add(p);
            }

            _polygon = Polygon.by_vertices(points);

            return Value.NewContainer(_polygon);
        }
Beispiel #35
0
 public override void AddPointInCreating(DrawContext dc, CadVertex p)
 {
     PointList.Add(p);
 }
Beispiel #36
0
 public void AddPoint(Point3 pt)
 {
     PointList.Add(pt);
 }
Beispiel #37
0
        public override bool Run(List <InputDefinition> inputs)
        {
            try
            {
                ViewBase  view   = InputDefinitionFactory.GetView(inputs[0]);
                PointList points = InputDefinitionFactory.GetPoints(inputs[0]);

                tsg.Point p1 = points[0] as tsg.Point;
                tsg.Point p2 = points[1] as tsg.Point;

                // default data
                #region Default data

                if (!IsDefaultValue(data.height))
                {
                    height = data.height;
                }
                if (!IsDefaultValue(data.shop))
                {
                    height = data.shop;
                }
                if (!IsDefaultValue(data.tw))
                {
                    try
                    {
                        tw = (TypeWeld)Enum.Parse(typeof(TypeWeld), data.tw);
                    }
                    catch { }
                }

                #endregion

                #region Drawing

                double dx = (shop == 1 ? 5 : 8);


                Line lineArrow = RLine(view, p1, p2, true);
                lineArrow.Insert();
                Line lineCen = RLine(view, p2, new tsg.Point((p2).X + dx, (p2).Y));
                lineCen.Insert();

                Line lineTop = RLine(view, new tsg.Point((p2).X + dx, (p2).Y), new tsg.Point((p2).X + dx + height, (p2).Y + height));
                lineTop.Insert();
                Line lineBottom = RLine(view, new tsg.Point((p2).X + dx, (p2).Y), new tsg.Point((p2).X + dx + height, (p2).Y - height));
                lineBottom.Insert();

                Text t = new Text(view, new tsg.Point((p2).X + dx + 5, (p2).Y), tw.ToString());
                t.Attributes.Alignment               = TextAlignment.Left;
                t.Attributes.ArrowHead.Head          = ArrowheadTypes.NoArrow;
                t.Attributes.ArrowHead.ArrowPosition = ArrowheadPositions.None;
                t.Attributes.ArrowHead.Height        = 0;
                t.Attributes.ArrowHead.Width         = 0;
                t.Placing = PlacingTypes.PointPlacing();
                t.Attributes.Frame.Type  = FrameTypes.None;
                t.Attributes.Font.Color  = col;
                t.Attributes.Font.Height = height;
                t.Insert();

                if (shop != 0)
                {
                    Line LineErection = RLine(view, p2, new tsg.Point((p2).X, (p2).Y + 5));
                    LineErection.Insert();
                    PointList pl = new PointList();
                    pl.Add(LineErection.EndPoint);
                    pl.Add(new tsg.Point(LineErection.EndPoint.X + height, LineErection.EndPoint.Y - 0.5));
                    pl.Add(new tsg.Point(LineErection.EndPoint.X, LineErection.EndPoint.Y - 1));
                    Polygon Erection = GetTriangle(view, pl, true);
                    Erection.Insert();
                }

                #region Type Weld
                Polygon triangle_top    = GetTriangle(view, new tsg.Point(lineCen.StartPoint.X + (dx - 4), lineCen.StartPoint.Y));
                Polygon triangle_bottom = GetTriangle(view, new tsg.Point(lineCen.StartPoint.X + (dx - 4), lineCen.StartPoint.Y), true);

                Line doule_line_1 = RLine(view,
                                          new tsg.Point(lineCen.StartPoint.X + (dx - 4), lineCen.StartPoint.Y),
                                          new tsg.Point(lineCen.StartPoint.X + (dx - 4), lineCen.StartPoint.Y + height));

                Line doule_line_2 = RLine(view,
                                          new tsg.Point(lineCen.StartPoint.X + (dx - 4) + 1.5, lineCen.StartPoint.Y),
                                          new tsg.Point(lineCen.StartPoint.X + (dx - 4) + 1.5, lineCen.StartPoint.Y + height));

                Line dl_line_45 = RLine(view,
                                        new tsg.Point(lineCen.StartPoint.X + (dx - 4), lineCen.StartPoint.Y),
                                        new tsg.Point(lineCen.StartPoint.X + (dx - 4) + height, lineCen.StartPoint.Y + height));

                Arc arc = new Arc(view, new tsg.Point(lineCen.StartPoint.X + height, lineCen.StartPoint.Y), lineCen.StartPoint, height * 0.5);
                arc.Attributes.Line.Color = col;
                arc.Attributes.Arrowhead.ArrowPosition = ArrowheadPositions.None;
                arc.Attributes.Line.Type = LineTypes.SolidLine;

                if (tw == TypeWeld.T1 || tw == TypeWeld.U4 || tw == TypeWeld.H1)
                {
                    triangle_top.Insert();
                }
                else if (tw == TypeWeld.T3 || tw == TypeWeld.H2)
                {
                    triangle_top.Insert();
                    triangle_bottom.Insert();
                }
                else if (tw == TypeWeld.C2)
                {
                    doule_line_1.Insert();
                    doule_line_2.Insert();
                }
                else if (tw == TypeWeld.T6 || tw == TypeWeld.U6)
                {
                    doule_line_1.Insert();
                    dl_line_45.Insert();
                }
                else if (tw == TypeWeld.T7 || tw == TypeWeld.U7)
                {
                    doule_line_1.Insert();
                    dl_line_45.Insert();
                    arc.Insert();
                }

                #endregion
                #endregion
            }
            catch (Exception Exc)
            {
                MessageBox.Show(Exc.ToString());
            }

            return(true);
        }
Beispiel #38
0
		private bool Process(PointList contour, PointList result) {
			result.Clear();
	
			int n = contour.Size();
			if (n < 3) {
				return false;
			}
			int[] sV = new int[n];
	
			if (0.0f < Area(contour)) {
				for (int v = 0; v < n; v++) {
					sV[v] = v;
				}
			} else {
				for (int v_0 = 0; v_0 < n; v_0++) {
					sV[v_0] = (n - 1) - v_0;
				}
			}
	
			int nv = n;
	
			int count = 2 * nv;
	
			for (int v_1 = nv - 1; nv > 2;) {
	
				if (0 >= (count--)) {
					return false;
				}
	
				int u = v_1;
				if (nv <= u) {
					u = 0;
				}
				v_1 = u + 1;
				if (nv <= v_1) {
					v_1 = 0;
				}
				int w = v_1 + 1;
				if (nv <= w) {
					w = 0;
				}
				if (Snip(contour, u, v_1, w, nv, sV)) {
					int a, b, c, s, t;
	
					a = sV[u];
					b = sV[v_1];
					c = sV[w];
	
					result.Add(contour.Get(a));
					result.Add(contour.Get(b));
					result.Add(contour.Get(c));
	
					for (s = v_1, t = v_1 + 1; t < nv; s++, t++) {
						sV[s] = sV[t];
					}
					nv--;
	
					count = 2 * nv;
				}
			}
	
			return true;
		}
Beispiel #39
0
 private void ToggleCellAt(PointyHexPoint point)
 {
     dirtyCells.Add(point);
     logicalGrid[point] = !logicalGrid[point];
 }
Beispiel #40
0
        public static PointList RadialScan(PointList inputList)
        {
            PointList result = new PointList(inputList);
            Point origin = result[(new Random()).Next(result.Count)];

            result.Sort((p, q) => Point.Distance(origin, p).CompareTo(Point.Distance(origin, q)));
            result.Add(result[0]);

            return result;
        }
Beispiel #41
0
        /// <summary>
        /// 鼠标双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (World.Settings.CurrentWwTool != this.drawPlugin)
            {
                return;
            }


            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (State == DrawState.Drawing)
            {
                Angle lat;
                Angle lon;

                //get Point
                this.drawArgs.WorldCamera.PickingRayIntersection(
                    e.X,
                    e.Y,
                    out lat,
                    out lon);

                if (Angle.IsNaN(lat))
                {
                    return;
                }

                Point3d pickPt = new Point3d();
                pickPt.X = lon.Degrees;
                pickPt.Y = lat.Degrees;
                pickPt.Z = (useTerrain) ? getElevation(lat.Degrees, lon.Degrees) : defaultElev;

                if (PointList.Count > 0)
                {
                    List <CustomVertex.PositionColored> newVertexes = getCurveFromPoints(PointList[PointList.Count - 1], pickPt, lineColor);
                    VertexList.AddRange(newVertexes.GetRange(1, newVertexes.Count - 1));
                }
                else
                {
                    VertexList.Add(Point3d2PositionColored(pickPt, lineColor));
                }

                PointList.Add(pickPt);
            }

            State = DrawState.Complete;
            Point3d[] Pts = new Point3d[4];
            Pts[0] = PointList[0];
            Pts[1] = new Point3d(Pts[0].X, movingPt.Y, Pts[0].Z);
            Pts[2] = movingPt;
            Pts[3] = new Point3d(movingPt.X, Pts[0].Y, Pts[0].Z);

            PointList.Clear();
            PointList.Add(Pts[0]);
            PointList.Add(Pts[1]);
            PointList.Add(Pts[2]);
            PointList.Add(Pts[3]);

            if (OnCompleted != null)
            {
                OnCompleted(this, new EventArgs());
            }
        }
Beispiel #42
0
        public static PointList RandomPath(PointList inputList)
        {
            PointList pointsLeft = new PointList(inputList);
            PointList result = new PointList();
            Random rnd = new Random();

            while (pointsLeft.Count > 0)
            {
                Point p = pointsLeft[rnd.Next(pointsLeft.Count)];
                result.Add(p);
                pointsLeft.Remove(p);
            }

            result.Add(result[0]);

            return result;
        }
Beispiel #43
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            PointList points = new PointList();
            var input = (args[0] as Value.List).Item;

            foreach (Value v in input)
            {
                Point p = ((Value.Container)v).Item as Point;
                points.Add(p);
            }

            _bsplinecurve = BSplineCurve.by_points(points);

            return Value.NewContainer(_bsplinecurve);
        }
Beispiel #44
0
 public void AddPoint(Point point)
 {
     pointArray.Add(point);
 }
        /// <summary>
        /// 绘制右侧所有零部件在Y向的标注,主要是区分支撑板和剩下的零部件标注;
        /// </summary>
        private void DrawAllPartRightFenSizeDimY()
        {
            //移除主梁;
            mMrPartList.Remove(mMainBeam);

            CCylinderTopViewSetting cylinderTopViewSetting = CCylinderDimSetting.GetInstance().mTopViewSetting;

            bool bNeedHorizontalConnectPlateDim = false;
            bool bNeedOtherPartDim = false;

            List <Point> horizontalConnectPlateDimPointList = new List <Point>();
            List <Point> otherPartDimPointList = new List <Point>();

            //1.遍历获得所有零件的向上标注的点;
            foreach (CMrPart mrPart in mMrPartList)
            {
                Vector normal = mrPart.mNormal;

                CMrDimSet partDimSet = mrPart.GetCylinderTopViewInfo().GetPartRightDimSet();

                if (partDimSet != null && partDimSet.Count > 0)
                {
                    //如果是水平连接板及支撑板、H型钢等;
                    if (CDimTools.GetInstance().IsPartTheSupportPlate(mrPart))
                    {
                        bNeedHorizontalConnectPlateDim = true;
                        horizontalConnectPlateDimPointList.AddRange(partDimSet.GetDimPointList());
                    }
                    else
                    {
                        bNeedOtherPartDim = true;
                        otherPartDimPointList.AddRange(partDimSet.GetDimPointList());
                    }
                }
            }

            Point minYPoint = mMainBeam.GetMinYMaxXPoint();
            Point maxYPoint = mMainBeam.GetMaxYMaxXPoint();

            //1.如果其他剩下的零件需要标注;
            if (bNeedOtherPartDim)
            {
                PointList pointList = new PointList();

                foreach (Point pt in otherPartDimPointList)
                {
                    pointList.Add(pt);
                }

                //如果需要标注轴线;
                if (cylinderTopViewSetting.FindDimValueByName(CCylinderTopViewSetting.mstrAixLine))
                {
                    foreach (Point pt in mIntersectionPointList)
                    {
                        pointList.Add(pt);
                    }
                }

                pointList.Add(minYPoint);
                pointList.Add(maxYPoint);

                Vector rightDimVector = new Vector(1, 0, 0);
                mRightDimDistance = GetRightDimDistance(pointList[0]);
                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, rightDimVector, mRightDimDistance, CCommonPara.mSizeDimPath);
            }
            //2.如果水平连接板及支撑需要标注;
            if (bNeedHorizontalConnectPlateDim)
            {
                PointList pointList = new PointList();

                foreach (Point pt in horizontalConnectPlateDimPointList)
                {
                    pointList.Add(pt);
                }

                //如果需要标注轴线;
                if (cylinderTopViewSetting.FindDimValueByName(CCylinderTopViewSetting.mstrAixLine))
                {
                    foreach (Point pt in mIntersectionPointList)
                    {
                        pointList.Add(pt);
                    }
                }
                pointList.Add(minYPoint);
                pointList.Add(maxYPoint);

                Vector rightDimVector = new Vector(1, 0, 0);
                mRightDimDistance = GetRightDimDistance(pointList[0]);
                CDimTools.GetInstance().DrawDimensionSet(mViewBase, pointList, rightDimVector, mRightDimDistance, CCommonPara.mSizeDimPath);
            }
            mMrPartList.Add(mMainBeam);
        }
Beispiel #46
0
        private static PointList nearestNeighbor(PointList inputList, Point startingPoint)
        {
            Point last = startingPoint;
            PointList visited = new PointList() { last };
            PointList unvisited = inputList.Clone();
            unvisited.Remove(last);

            while (unvisited.Count > 0)
            {
                Point next = findClosestPair(unvisited.ConvertAll(p => new PairOfPoints(last, p))).B;
                visited.Add(next);
                unvisited.Remove(next);
                last = next;
            }

            visited.Add(visited[0]);

            return visited;
        }
Beispiel #47
0
        public static PointList RoughScan(PointList inputList)
        {
            int rowCount = (int)Math.Round(Math.Sqrt(inputList.Count) / 2f) * 2;

            decimal lowestY = inputList.Min(p => p.Y);
            decimal highestY = inputList.Max(p => p.Y);
            decimal rowHeight = (highestY - lowestY) / rowCount;

            List<int> rowIndices = new List<int>();
            for (int i = 0; i < rowCount; i++)
                rowIndices.Add(i);

            List<List<Point>> rows = rowIndices.ConvertAll(rowIndex => inputList.FindAll(point => point.Y >= (lowestY + rowHeight * rowIndex) &&
                                                                                                  point.Y < (lowestY + rowHeight * (rowIndex + 1))));
            rows[rows.Count - 1].AddRange(inputList.FindAll(point => point.Y == highestY));
            rows = rows.Where(r => r.Count > 0).ToList();

            PointList path = new PointList();
            for (int i = 0; i < rows.Count; i++)
            {
                PointList rowPath = new PointList(rows[i].OrderBy(point => point.X * (decimal)Math.Pow(-1f, i)));
                rowPath = nearestNeighbor(rowPath, rowPath[0]);
                rowPath.RemoveAt(rowPath.Count - 1);
                path.AddRange(rowPath);
            }

            path.Add(path[0]);
            return path;
        }
		public PointList GetVisibleAdjacentPoints(Point origin, PointList skipPoints)
		{
			PointList adjacentPoints = new PointList();

			MapTileList originTiles = GetMapTilesForPoint(origin);
			Boolean originBlocksLineOfSightNorth = false;
			Boolean originBlocksLineOfSightEast = false;
			Boolean originBlocksLineOfSightSouth = false;
			Boolean originBlocksLineOfSightWest = false;
			if (originTiles.BlocksLineOfSight)
			{ return adjacentPoints; } // If the tile itself blocks all line of sight, then nothing is visible
			if (originTiles.BlocksLineOfSightNorth)
			{ originBlocksLineOfSightNorth = true; }
			if (originTiles.BlocksLineOfSightEast)
			{ originBlocksLineOfSightEast = true; }
			if (originTiles.BlocksLineOfSightSouth)
			{ originBlocksLineOfSightSouth = true; }
			if (originTiles.BlocksLineOfSightWest)
			{ originBlocksLineOfSightWest = true; }

			if (origin.X > 0 &&  !originBlocksLineOfSightWest && !skipPoints.ContainsLocation(origin.X - 1, origin.Y))
			{ adjacentPoints.Add(new Point(origin.X - 1, origin.Y)); }
			if (origin.X < MAP_WIDTH_IN_TILES - 1 && !originBlocksLineOfSightEast && !skipPoints.ContainsLocation(origin.X + 1, origin.Y))
			{ adjacentPoints.Add(new Point(origin.X + 1, origin.Y)); }
			if (origin.Y > 0 && !originBlocksLineOfSightNorth && !skipPoints.ContainsLocation(origin.X, origin.Y - 1))
			{ adjacentPoints.Add(new Point(origin.X, origin.Y - 1)); }
			if (origin.Y < MAP_HEIGHT_IN_TILES - 1 && !originBlocksLineOfSightSouth && !skipPoints.ContainsLocation(origin.X, origin.Y+1))
			{ adjacentPoints.Add(new Point(origin.X, origin.Y + 1)); }

			return adjacentPoints;
		}
Beispiel #49
0
        private bool Process(PointList contour, PointList result)
        {
            result.Clear();

            int n = contour.Size();

            if (n < 3)
            {
                return(false);
            }
            int[] sV = new int[n];

            if (0.0f < Area(contour))
            {
                for (int v = 0; v < n; v++)
                {
                    sV[v] = v;
                }
            }
            else
            {
                for (int v_0 = 0; v_0 < n; v_0++)
                {
                    sV[v_0] = (n - 1) - v_0;
                }
            }

            int nv = n;

            int count = 2 * nv;

            for (int v_1 = nv - 1; nv > 2;)
            {
                if (0 >= (count--))
                {
                    return(false);
                }

                int u = v_1;
                if (nv <= u)
                {
                    u = 0;
                }
                v_1 = u + 1;
                if (nv <= v_1)
                {
                    v_1 = 0;
                }
                int w = v_1 + 1;
                if (nv <= w)
                {
                    w = 0;
                }
                if (Snip(contour, u, v_1, w, nv, sV))
                {
                    int a, b, c, s, t;

                    a = sV[u];
                    b = sV[v_1];
                    c = sV[w];

                    result.Add(contour.Get(a));
                    result.Add(contour.Get(b));
                    result.Add(contour.Get(c));

                    for (s = v_1, t = v_1 + 1; t < nv; s++, t++)
                    {
                        sV[s] = sV[t];
                    }
                    nv--;

                    count = 2 * nv;
                }
            }

            return(true);
        }
Beispiel #50
0
        public static PointList Scan(PointList inputList)
        {
            PointList result = new PointList(inputList);
            result.Sort((p, q) => p.Y.CompareTo(q.Y) != 0 ? p.Y.CompareTo(q.Y) : p.X.CompareTo(q.X));
            result.Add(result[0]);

            return result;
        }