Exemplo n.º 1
0
		private static bool TestQuadrant(CornerQuadrant quadrant, double x, double y)
		{
			switch (quadrant)
			{
				case CornerQuadrant.UpperRight:
					return x > -VGConstants.FuzzGeneral && y < VGConstants.FuzzGeneral;
				case CornerQuadrant.UpperLeft:
					return x < VGConstants.FuzzGeneral && y < VGConstants.FuzzGeneral;
				case CornerQuadrant.LowerLeft:
					return x < VGConstants.FuzzGeneral && y > -VGConstants.FuzzGeneral;
				//case CornerQuadrant.LowerRight:
				default:
					return x > -VGConstants.FuzzGeneral && y > -VGConstants.FuzzGeneral;
			}
		}
Exemplo n.º 2
0
		private static PointD? FindCornerHit(PointD cornerCenter, PointD samplePoint, double slope, double radius, CornerQuadrant quadrant)
		{
			double ccx = cornerCenter.X;
			double ccy = cornerCenter.Y;
			double px = samplePoint.X - ccx;
			double py = samplePoint.Y - ccy;
			double quadA = 1 + slope * slope;
			double sharedQuadPart = py - slope * px;
			double quadB = (slope + slope) * sharedQuadPart;
			double quadC = sharedQuadPart * sharedQuadPart - radius * radius;
			double discriminant = quadB * quadB - 4 * quadA * quadC;
			double solvedX;
			double solvedY;
			if (VGConstants.FuzzZero(discriminant, VGConstants.FuzzGeneral))
			{
				solvedX = -quadB / (quadA + quadA);
				solvedY = slope * (solvedX - px) + py;
				return TestQuadrant(quadrant, solvedX, solvedY) ? new PointD(solvedX + ccx, solvedY + ccy) : new PointD?();
			}
			else if (discriminant < 0)
			{
				return null;
			}
			else
			{
				discriminant = Math.Sqrt(discriminant);
				solvedX = (-quadB + discriminant) / (quadA + quadA);
				solvedY = slope * (solvedX - px) + py;
				bool solvedInQuadrant = TestQuadrant(quadrant, solvedX, solvedY);
				double solvedXAlternate = (-quadB - discriminant) / (quadA + quadA);
				double solvedYAlternate = slope * (solvedXAlternate - px) + py;
				bool solvedInQuadrantAlternate = TestQuadrant(quadrant, solvedXAlternate, solvedYAlternate);
				if (solvedInQuadrant)
				{
					if (solvedInQuadrantAlternate)
					{
						double xDif = px - solvedX;
						double yDif = py - solvedY;
						double xDifAlternate = px - solvedXAlternate;
						double yDifAlternate = py - solvedYAlternate;
						if ((xDif * xDif + yDif * yDif) > (xDifAlternate * xDifAlternate + yDifAlternate * yDifAlternate))
						{
							solvedX = solvedXAlternate;
							solvedY = solvedYAlternate;
						}
					}
				}
				else if (solvedInQuadrantAlternate)
				{
					solvedX = solvedXAlternate;
					solvedY = solvedYAlternate;
				}
				else
				{
					return null;
				}
			}
			return new PointD(solvedX + ccx, solvedY + ccy);
		}