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


C# PointD.Offset方法代码示例

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


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

示例1: DoFoldToShape

		/// <summary>
		/// Provide custom shape folding for rectangular fact types
		/// </summary>
		/// <param name="geometryHost">The host view</param>
		/// <param name="potentialPoint">A point on the rectangular boundary of the shape</param>
		/// <param name="vectorEndPoint">A point on the opposite end of the connecting line</param>
		/// <returns>A point on the rectangle edge border</returns>
		public override PointD DoFoldToShape(IGeometryHost geometryHost, PointD potentialPoint, PointD vectorEndPoint)
		{
			NodeShape oppositeShape;
			vectorEndPoint = GeometryUtility.AdjustVectorEndPoint(geometryHost, vectorEndPoint, out oppositeShape);
			PointD? customPoint = GeometryUtility.DoCustomFoldShape(geometryHost, vectorEndPoint, oppositeShape);
			if (customPoint.HasValue)
			{
				return customPoint.Value;
			}
			vectorEndPoint = GeometryUtility.ResolveProxyConnectorVectorEndPoint(vectorEndPoint, oppositeShape);

			// Fold to the shape
			// This is used for center to center routing, so the potential point is the
			// center of the shape. We need to see where a line through the center intersects
			// the rectangle border and return relative coordinates.
			RectangleD bounds = geometryHost.TranslateGeometryToAbsoluteBounds(geometryHost.GeometryBoundingBox);
			PointD center = bounds.Center;
			vectorEndPoint.Offset(-center.X, -center.Y);
			bool negativeX = vectorEndPoint.X < 0;
			bool negativeY = vectorEndPoint.Y < 0;
			if (VGConstants.FuzzZero(vectorEndPoint.X, VGConstants.FuzzDistance))
			{
				// Vertical line, skip slope calculations
				return new PointD(bounds.Width / 2, negativeY ? 0 : bounds.Height);
			}
			else if (VGConstants.FuzzZero(vectorEndPoint.Y, VGConstants.FuzzDistance))
			{
				// Horizontal line, skip slope calculations
				return new PointD(negativeX ? 0 : bounds.Width, bounds.Height / 2);
			}
			else
			{
				double slope = vectorEndPoint.Y / vectorEndPoint.X;
				// The intersecting line equation is y = mx. We can tell
				// whether to use the vertical or horizontal lines by
				// comparing the relative sizes of the rectangle sides
				// with the slope
				double x;
				double y;
				if (Math.Abs(slope) < (bounds.Height / bounds.Width))
				{
					// Attach to left/right edges
					// Intersect with line x = +/- bounds.Width / 2
					x = bounds.Width / 2;
					if (negativeX)
					{
						x = -x;
					}
					y = x * slope;
				}
				else
				{
					// Attach to top/bottom edges
					// Intersect with line y = +/- bounds.Height / 2
					y = bounds.Height / 2;
					if (negativeY)
					{
						y = -y;
					}
					x = y / slope;
				}
				return new PointD(x + bounds.Width / 2, y + bounds.Height / 2);
			}
		}
开发者ID:cjheath,项目名称:NORMA,代码行数:71,代码来源:CustomFoldShapeGeometries.cs

示例2: OffsetBorderPoint

		/// <summary>
		/// Implements <see cref="IOffsetBorderPoint.OffsetBorderPoint"/>
		/// </summary>
		protected PointD? OffsetBorderPoint(IGeometryHost geometryHost, PointD borderPoint, PointD outsidePoint, double offset, bool parallelVector)
		{
			double angle = GeometryUtility.CalculateRadiansRotationAngle(outsidePoint, borderPoint);

			// Get the sample point
			PointD samplePoint = borderPoint;
			samplePoint.Offset(-offset * Math.Sin(angle), offset * Math.Cos(angle));

			// Figure out the slope, either parallel to the incoming line, or pointed at the outside point
			PointD slopeThrough = parallelVector ? borderPoint : samplePoint;

			// Translate the rectangle to the origin
			RectangleD bounds = geometryHost.GeometryBoundingBox;
			PointD hostCenter = bounds.Center;
			double hcx = hostCenter.X;
			double hcy = hostCenter.Y;
			samplePoint.Offset(-hcx, -hcy);
			borderPoint.Offset(-hcx, -hcy);

			double px = samplePoint.X;
			double py = samplePoint.Y;
			double solvedX;
			double solvedY;

			double halfWidth = bounds.Width / 2;
			double halfHeight = bounds.Height / 2;
			double r = Radius;
			if (VGConstants.FuzzEqual(slopeThrough.X, outsidePoint.X, VGConstants.FuzzDistance))
			{
				double absX = Math.Abs(px);
				// Vertical line, hit the same edge as the border point
				if (absX > (halfWidth + VGConstants.FuzzDistance))
				{
					// Line hits outside rectangle
					return null;
				}

				solvedX = px;
				solvedY = halfHeight;
				absX = halfWidth - absX;
				if (absX < r)
				{
					// We're on the rounded corner. Figure out how far down the circle we need to go.
					solvedY -= r - Math.Sqrt(absX * (r + r - absX));
				}
				if (borderPoint.Y < 0)
				{
					solvedY = -solvedY;
				}
			}
			else if (VGConstants.FuzzEqual(slopeThrough.Y, outsidePoint.Y, VGConstants.FuzzDistance))
			{
				double absY = Math.Abs(py);
				// Horizontal line, hit the same edge as the border point
				if (absY > (halfHeight + VGConstants.FuzzDistance))
				{
					// Line hits outside rectangle
					return null;
				}
				solvedY = py;
				solvedX = halfWidth;
				absY = halfHeight - absY;
				if (absY < r)
				{
					// We're on the rounded corner. Figure out how far down the circle we need to go.
					solvedX -= r - Math.Sqrt(absY * (r + r - absY));
				}
				if (borderPoint.X < 0)
				{
					solvedX = -solvedX;
				}
			}
			else
			{
				int hitCount = 0;
				solvedX = 0;
				solvedY = 0;
				double solvedXAlternate = 0;
				double solvedYAlternate = 0;
				PointD? corner; // Use for corner tracking (both the center and the hit points)
				CornerQuadrant quadrant = 0;

				// We've already checked vertical and horizontal lines, so we know the lines will intersect either
				// zero or two sides of the rectangle. Find the two sides.
				// The intersecting line equation is y = m(x - px) + py (solved for y) or x = 1/m(y-py) + px (solved for x)
				// The rectangle borders are y = halfHeight, y = -halfHeight, x = halfWidth, x = -halfWidth
				double slope = (outsidePoint.Y - slopeThrough.Y) / (outsidePoint.X - slopeThrough.X);
				double inverseSlope = 1 / slope;

				double testIntersect;

				// Bottom edge
				testIntersect = inverseSlope * (halfHeight - py) + px;
				if (Math.Abs(testIntersect) < (halfWidth + VGConstants.FuzzDistance))
				{
					solvedX = testIntersect;
					solvedY = halfHeight;
//.........这里部分代码省略.........
开发者ID:cjheath,项目名称:NORMA,代码行数:101,代码来源:CustomFoldShapeGeometries.cs


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