当前位置: 首页>>代码示例>>C#>>正文


C# Vertices.nextIndex方法代码示例

本文整理汇总了C#中Vertices.nextIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.nextIndex方法的具体用法?C# Vertices.nextIndex怎么用?C# Vertices.nextIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vertices的用法示例。


在下文中一共展示了Vertices.nextIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: calculateIntersections

		/// <summary>
		/// Calculates all intersections between two polygons.
		/// </summary>
		/// <param name="polygon1">The first polygon.</param>
		/// <param name="polygon2">The second polygon.</param>
		/// <param name="slicedPoly1">Returns the first polygon with added intersection points.</param>
		/// <param name="slicedPoly2">Returns the second polygon with added intersection points.</param>
		static void calculateIntersections( Vertices polygon1, Vertices polygon2,
												   out Vertices slicedPoly1, out Vertices slicedPoly2 )
		{
			slicedPoly1 = new Vertices( polygon1 );
			slicedPoly2 = new Vertices( polygon2 );

			// Iterate through polygon1's edges
			for( int i = 0; i < polygon1.Count; i++ )
			{
				// Get edge vertices
				Vector2 a = polygon1[i];
				Vector2 b = polygon1[polygon1.nextIndex( i )];

				// Get intersections between this edge and polygon2
				for( int j = 0; j < polygon2.Count; j++ )
				{
					Vector2 c = polygon2[j];
					Vector2 d = polygon2[polygon2.nextIndex( j )];

					Vector2 intersectionPoint;
					// Check if the edges intersect
					if( LineTools.lineIntersect( a, b, c, d, out intersectionPoint ) )
					{
						// calculate alpha values for sorting multiple intersections points on a edge
						float alpha;
						// Insert intersection point into first polygon
						alpha = getAlpha( a, b, intersectionPoint );
						if( alpha > 0f && alpha < 1f )
						{
							int index = slicedPoly1.IndexOf( a ) + 1;
							while( index < slicedPoly1.Count &&
								   getAlpha( a, b, slicedPoly1[index] ) <= alpha )
							{
								++index;
							}
							slicedPoly1.Insert( index, intersectionPoint );
						}
						// Insert intersection point into second polygon
						alpha = getAlpha( c, d, intersectionPoint );
						if( alpha > 0f && alpha < 1f )
						{
							int index = slicedPoly2.IndexOf( c ) + 1;
							while( index < slicedPoly2.Count &&
								   getAlpha( c, d, slicedPoly2[index] ) <= alpha )
							{
								++index;
							}
							slicedPoly2.Insert( index, intersectionPoint );
						}
					}
				}
			}
			// Check for very small edges
			for( int i = 0; i < slicedPoly1.Count; ++i )
			{
				int iNext = slicedPoly1.nextIndex( i );
				//If they are closer than the distance remove vertex
				if( ( slicedPoly1[iNext] - slicedPoly1[i] ).LengthSquared() <= ClipperEpsilonSquared )
				{
					slicedPoly1.RemoveAt( i );
					--i;
				}
			}
			for( int i = 0; i < slicedPoly2.Count; ++i )
			{
				int iNext = slicedPoly2.nextIndex( i );
				//If they are closer than the distance remove vertex
				if( ( slicedPoly2[iNext] - slicedPoly2[i] ).LengthSquared() <= ClipperEpsilonSquared )
				{
					slicedPoly2.RemoveAt( i );
					--i;
				}
			}
		}
开发者ID:prime31,项目名称:Nez,代码行数:81,代码来源:YuPengClipper.cs

示例2: calculateSimplicalChain

		/// <summary>
		/// Calculates the simplical chain corresponding to the input polygon.
		/// </summary>
		/// <remarks>Used by method <c>Execute()</c>.</remarks>
		static void calculateSimplicalChain( Vertices poly, out List<float> coeff,
													out List<Edge> simplicies )
		{
			simplicies = new List<Edge>();
			coeff = new List<float>();
			for( int i = 0; i < poly.Count; ++i )
			{
				simplicies.Add( new Edge( poly[i], poly[poly.nextIndex( i )] ) );
				coeff.Add( calculateSimplexCoefficient( Vector2.Zero, poly[i], poly[poly.nextIndex( i )] ) );
			}
		}
开发者ID:prime31,项目名称:Nez,代码行数:15,代码来源:YuPengClipper.cs

示例3: lineSegmentVerticesIntersect

		/// <summary>
		/// Get all intersections between a line segment and a list of vertices
		/// representing a polygon. The vertices reuse adjacent points, so for example
		/// edges one and two are between the first and second vertices and between the
		/// second and third vertices. The last edge is between vertex vertices.Count - 1
		/// and verts0. (ie, vertices from a Geometry or AABB)
		/// </summary>
		/// <param name="point1">The first point of the line segment to test</param>
		/// <param name="point2">The second point of the line segment to test.</param>
		/// <param name="vertices">The vertices, as described above</param>
		public static Vertices lineSegmentVerticesIntersect( ref Vector2 point1, ref Vector2 point2, Vertices vertices )
		{
			Vertices intersectionPoints = new Vertices();

			for( int i = 0; i < vertices.Count; i++ )
			{
				Vector2 point;
				if( lineIntersect( vertices[i], vertices[vertices.nextIndex( i )], point1, point2, true, true, out point ) )
				{
					intersectionPoints.Add( point );
				}
			}

			return intersectionPoints;
		}
开发者ID:prime31,项目名称:Nez,代码行数:25,代码来源:LineTools.cs


注:本文中的Vertices.nextIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。