public static List<List<IntPoint>> CreatePolygons(IVertexSource sourcePath, double scaling = 1000)
		{
			List<List<IntPoint>> allPolys = new List<List<IntPoint>>();
			List<IntPoint> currentPoly = null;
			VertexData last = new VertexData();
			VertexData first = new VertexData();
			bool addedFirst = false;
			foreach (VertexData vertexData in sourcePath.Vertices())
			{
				if (vertexData.IsLineTo)
				{
					if (!addedFirst)
					{
						currentPoly.Add(new IntPoint((long)(last.position.x * scaling), (long)(last.position.y * scaling)));
						addedFirst = true;
						first = last;
					}
					currentPoly.Add(new IntPoint((long)(vertexData.position.x * scaling), (long)(vertexData.position.y * scaling)));
					last = vertexData;
				}
				else
				{
					addedFirst = false;
					currentPoly = new List<IntPoint>();
					allPolys.Add(currentPoly);
					if (vertexData.IsMoveTo)
					{
						last = vertexData;
					}
					else
					{
						last = first;
					}
				}
			}

			return allPolys;
		}
示例#2
0
        public IEnumerable <VertexData> Vertices()
        {
            VertexData vertexData = new VertexData();

            vertexData.command    = FlagsAndCommand.CommandMoveTo;
            vertexData.position.x = originX + radiusX;
            vertexData.position.y = originY;
            yield return(vertexData);

            double anglePerStep = MathHelper.Tau / (double)numSteps;
            double angle        = 0;

            vertexData.command = FlagsAndCommand.CommandLineTo;
            for (int i = 1; i < numSteps; i++)
            {
                angle += anglePerStep;

                if (m_cw)
                {
                    vertexData.position.x = originX + Math.Cos(MathHelper.Tau - angle) * radiusX;
                    vertexData.position.y = originY + Math.Sin(MathHelper.Tau - angle) * radiusY;
                    yield return(vertexData);
                }
                else
                {
                    vertexData.position.x = originX + Math.Cos(angle) * radiusX;
                    vertexData.position.y = originY + Math.Sin(angle) * radiusY;
                    yield return(vertexData);
                }
            }

            vertexData.position = new Vector2();
            vertexData.command  = FlagsAndCommand.CommandEndPoly | FlagsAndCommand.FlagClose | FlagsAndCommand.FlagCCW;
            yield return(vertexData);

            vertexData.command = FlagsAndCommand.CommandStop;
            yield return(vertexData);
        }
示例#3
0
		public IEnumerable<VertexData> Vertices()
		{
			VertexData vertexData = new VertexData();
			vertexData.command = FlagsAndCommand.CommandMoveTo;
			vertexData.position.x = originX + radiusX;
			vertexData.position.y = originY;
			yield return vertexData;

			double anglePerStep = MathHelper.Tau / (double)numSteps;
			double angle = 0;
			vertexData.command = FlagsAndCommand.CommandLineTo;
			for (int i = 1; i < numSteps; i++)
			{
				angle += anglePerStep;

				if (m_cw)
				{
					vertexData.position.x = originX + Math.Cos(MathHelper.Tau - angle) * radiusX;
					vertexData.position.y = originY + Math.Sin(MathHelper.Tau - angle) * radiusY;
					yield return vertexData;
				}
				else
				{
					vertexData.position.x = originX + Math.Cos(angle) * radiusX;
					vertexData.position.y = originY + Math.Sin(angle) * radiusY;
					yield return vertexData;
				}
			}

			vertexData.position = new Vector2();
			vertexData.command = FlagsAndCommand.CommandEndPoly | FlagsAndCommand.FlagClose | FlagsAndCommand.FlagCCW;
			yield return vertexData;
			vertexData.command = FlagsAndCommand.CommandStop;
			yield return vertexData;
		}
示例#4
0
		public IEnumerable<VertexData> Vertices()
		{
			VertexData lastPosition = new VertexData();

			IEnumerator<VertexData> vertexDataEnumerator = VertexSource.Vertices().GetEnumerator();
			while (vertexDataEnumerator.MoveNext())
			{
				VertexData vertexData = vertexDataEnumerator.Current;
				switch (vertexData.command)
				{
					case ShapePath.FlagsAndCommand.CommandCurve3:
						{
							vertexDataEnumerator.MoveNext();
							VertexData vertexDataEnd = vertexDataEnumerator.Current;
							m_curve3.init(lastPosition.position.x, lastPosition.position.y, vertexData.position.x, vertexData.position.y, vertexDataEnd.position.x, vertexDataEnd.position.y);
							IEnumerator<VertexData> curveIterator = m_curve3.Vertices().GetEnumerator();
							curveIterator.MoveNext(); // First call returns path_cmd_move_to
							do
							{
								curveIterator.MoveNext();
								if (ShapePath.is_stop(curveIterator.Current.command))
								{
									break;
								}
								vertexData = new VertexData(ShapePath.FlagsAndCommand.CommandLineTo, curveIterator.Current.position);
								yield return vertexData;
								lastPosition = vertexData;
							} while (!ShapePath.is_stop(curveIterator.Current.command));
						}
						break;

					case ShapePath.FlagsAndCommand.CommandCurve4:
						{
							vertexDataEnumerator.MoveNext();
							VertexData vertexDataControl = vertexDataEnumerator.Current;
							vertexDataEnumerator.MoveNext();
							VertexData vertexDataEnd = vertexDataEnumerator.Current;
							m_curve4.init(lastPosition.position.x, lastPosition.position.y, vertexData.position.x, vertexData.position.y, vertexDataControl.position.x, vertexDataControl.position.y, vertexDataEnd.position.x, vertexDataEnd.position.y);
							IEnumerator<VertexData> curveIterator = m_curve4.Vertices().GetEnumerator();
							curveIterator.MoveNext(); // First call returns path_cmd_move_to
							while (!ShapePath.is_stop(vertexData.command))
							{
								curveIterator.MoveNext();
								if (ShapePath.is_stop(curveIterator.Current.command))
								{
									break;
								}
								vertexData = new VertexData(ShapePath.FlagsAndCommand.CommandLineTo, curveIterator.Current.position);
								yield return vertexData;
								lastPosition = vertexData;
							}
						}
						break;

					default:
						yield return vertexData;
						lastPosition = vertexData;
						break;
				}
			}
		}
示例#5
0
		public IEnumerable<VertexData> Vertices()
		{
			if (!m_IsInitialized)
			{
				normalize(startAngle, endAngle, m_Direction);
			}

			// go to the start
			VertexData vertexData = new VertexData();
			vertexData.command = moveToStart ? FlagsAndCommand.CommandMoveTo : FlagsAndCommand.CommandLineTo;
			vertexData.position.x = originX + Math.Cos(startAngle) * radiusX;
			vertexData.position.y = originY + Math.Sin(startAngle) * radiusY;
			yield return vertexData;

			double angle = startAngle;
			vertexData.command = FlagsAndCommand.CommandLineTo;
			while ((angle < endAngle - flatenDeltaAngle / 4) == (((int)EDirection.CounterClockWise) == 1))
			{
				angle += flatenDeltaAngle;

				vertexData.position.x = originX + Math.Cos(angle) * radiusX;
				vertexData.position.y = originY + Math.Sin(angle) * radiusY;
				yield return vertexData;
			}

			vertexData.position.x = originX + Math.Cos(endAngle) * radiusX;
			vertexData.position.y = originY + Math.Sin(endAngle) * radiusY;
			yield return vertexData;

			vertexData.command = FlagsAndCommand.CommandStop;
			yield return vertexData;
		}
示例#6
0
        public IEnumerable <VertexData> Vertices()
        {
            VertexData lastPosition = new VertexData();

            IEnumerator <VertexData> vertexDataEnumerator = VertexSource.Vertices().GetEnumerator();

            while (vertexDataEnumerator.MoveNext())
            {
                VertexData vertexData = vertexDataEnumerator.Current;
                switch (vertexData.command)
                {
                case ShapePath.FlagsAndCommand.CommandCurve3:
                {
                    vertexDataEnumerator.MoveNext();
                    VertexData vertexDataEnd = vertexDataEnumerator.Current;
                    m_curve3.init(lastPosition.position.x, lastPosition.position.y, vertexData.position.x, vertexData.position.y, vertexDataEnd.position.x, vertexDataEnd.position.y);
                    IEnumerator <VertexData> curveIterator = m_curve3.Vertices().GetEnumerator();
                    curveIterator.MoveNext();                                     // First call returns path_cmd_move_to
                    do
                    {
                        curveIterator.MoveNext();
                        if (ShapePath.is_stop(curveIterator.Current.command))
                        {
                            break;
                        }
                        vertexData = new VertexData(ShapePath.FlagsAndCommand.CommandLineTo, curveIterator.Current.position);
                        yield return(vertexData);

                        lastPosition = vertexData;
                    } while (!ShapePath.is_stop(curveIterator.Current.command));
                }
                break;

                case ShapePath.FlagsAndCommand.CommandCurve4:
                {
                    vertexDataEnumerator.MoveNext();
                    VertexData vertexDataControl = vertexDataEnumerator.Current;
                    vertexDataEnumerator.MoveNext();
                    VertexData vertexDataEnd = vertexDataEnumerator.Current;
                    m_curve4.init(lastPosition.position.x, lastPosition.position.y, vertexData.position.x, vertexData.position.y, vertexDataControl.position.x, vertexDataControl.position.y, vertexDataEnd.position.x, vertexDataEnd.position.y);
                    IEnumerator <VertexData> curveIterator = m_curve4.Vertices().GetEnumerator();
                    curveIterator.MoveNext();                                     // First call returns path_cmd_move_to
                    while (!ShapePath.is_stop(vertexData.command))
                    {
                        curveIterator.MoveNext();
                        if (ShapePath.is_stop(curveIterator.Current.command))
                        {
                            break;
                        }
                        vertexData = new VertexData(ShapePath.FlagsAndCommand.CommandLineTo, curveIterator.Current.position);
                        yield return(vertexData);

                        lastPosition = vertexData;
                    }
                }
                break;

                default:
                    yield return(vertexData);

                    lastPosition = vertexData;
                    break;
                }
            }
        }
示例#7
0
		public IEnumerable<VertexData> Vertices()
		{
			if (text != null && text.Length > 0)
			{
				Vector2 currentOffset = new Vector2(0, 0);

				currentOffset = GetBaseline(currentOffset);

				string[] lines = text.Split('\n');
				foreach (string line in lines)
				{
					currentOffset = GetXPositionForLineBasedOnJustification(currentOffset, line);

					for (int currentChar = 0; currentChar < line.Length; currentChar++)
					{
						IVertexSource currentGlyph = TypeFaceStyle.GetGlyphForCharacter(line[currentChar]);

						if (currentGlyph != null)
						{
							foreach (VertexData vertexData in currentGlyph.Vertices())
							{
								if (vertexData.command != ShapePath.FlagsAndCommand.CommandStop)
								{
									VertexData offsetVertex = new VertexData(vertexData.command, vertexData.position + currentOffset + Origin);
									yield return offsetVertex;
								}
							}
						}

						// get the advance for the next character
						if (currentChar < line.Length - 1)
						{
							// pass the next char so the typeFaceStyle can do kerning if it needs to.
							currentOffset.x += TypeFaceStyle.GetAdvanceForCharacter(line[currentChar], line[currentChar + 1]);
						}
						else
						{
							currentOffset.x += TypeFaceStyle.GetAdvanceForCharacter(line[currentChar]);
						}
					}

					// before we go onto the next line we need to move down a line
					currentOffset.x = 0;
					currentOffset.y -= TypeFaceStyle.EmSizeInPixels;
				}
			}

			VertexData endVertex = new VertexData(ShapePath.FlagsAndCommand.CommandStop, Vector2.Zero);
			yield return endVertex;
		}
示例#8
0
        override public IEnumerable <VertexData> Vertices()
        {
            double averageRadius = (Math.Abs(radius.x) + Math.Abs(radius.y)) / 2;

            flatenDeltaAngle = Math.Acos(averageRadius / (averageRadius + 0.125 / scale)) * 2;
            while (endAngle < startAngle)
            {
                endAngle += Math.PI * 2.0;
            }

            VertexData vertexData = new VertexData();

            vertexData.command = FlagsAndCommand.CommandMoveTo;
            if (direction == Direction.CounterClockWise)
            {
                vertexData.position.x = origin.x + Math.Cos(startAngle) * radius.x;
                vertexData.position.y = origin.y + Math.Sin(startAngle) * radius.y;
                yield return(vertexData);

                vertexData.command = FlagsAndCommand.CommandLineTo;
                double angle    = startAngle;
                int    numSteps = (int)((endAngle - startAngle) / flatenDeltaAngle);
                for (int i = 0; i <= numSteps; i++)
                {
                    vertexData.position.x = origin.x + Math.Cos(angle) * radius.x;
                    vertexData.position.y = origin.y + Math.Sin(angle) * radius.y;
                    yield return(vertexData);

                    angle += flatenDeltaAngle;
                }

                vertexData.position.x = origin.x + Math.Cos(endAngle) * radius.x;
                vertexData.position.y = origin.y + Math.Sin(endAngle) * radius.y;
                yield return(vertexData);
            }
            else
            {
                vertexData.position.x = origin.x + Math.Cos(endAngle) * radius.x;
                vertexData.position.y = origin.y + Math.Sin(endAngle) * radius.y;
                yield return(vertexData);

                vertexData.command = FlagsAndCommand.CommandLineTo;
                double angle    = endAngle;
                int    numSteps = (int)((endAngle - startAngle) / flatenDeltaAngle);
                for (int i = 0; i <= numSteps; i++)
                {
                    vertexData.position.x = origin.x + Math.Cos(angle) * radius.x;
                    vertexData.position.y = origin.y + Math.Sin(angle) * radius.y;
                    yield return(vertexData);

                    angle -= flatenDeltaAngle;
                }

                vertexData.position.x = origin.x + Math.Cos(startAngle) * radius.x;
                vertexData.position.y = origin.y + Math.Sin(startAngle) * radius.y;
                yield return(vertexData);
            }

            vertexData.command = FlagsAndCommand.CommandStop;
            yield return(vertexData);
        }
示例#9
0
		private void AddVertex(VertexData vertexData)
		{
			if (ShapePath.is_move_to(vertexData.command))
			{
				move_to_d(vertexData.position.x, vertexData.position.y);
			}
			else
			{
				if (ShapePath.is_vertex(vertexData.command))
				{
					line_to_d(vertexData.position.x, vertexData.position.y);
				}
				else
				{
					if (ShapePath.is_close(vertexData.command))
					{
						close_polygon();
					}
				}
			}
		}
示例#10
0
		public IEnumerable<VertexData> Vertices()
		{
			VertexData vertexData = new VertexData();
			vertexData.command = FlagsAndCommand.CommandMoveTo;
			vertexData.position = m_points[0];
			yield return vertexData;

			vertexData.command = FlagsAndCommand.CommandLineTo;
			for (int i = 1; i < m_points.size(); i++)
			{
				vertexData.position = m_points[i];
				yield return vertexData;
			}

			vertexData.command = FlagsAndCommand.CommandStop;
			vertexData.position = new Vector2();
			yield return vertexData;
		}