本文整理汇总了C#中Point2D.Subtract方法的典型用法代码示例。如果您正苦于以下问题:C# Point2D.Subtract方法的具体用法?C# Point2D.Subtract怎么用?C# Point2D.Subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2D
的用法示例。
在下文中一共展示了Point2D.Subtract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PolygonsAreSame2D
/// <summary>
/// Check if the polys are similar to within a tolerance (Doesn't include reflections,
/// but allows for the points to be numbered differently, but not reversed).
/// </summary>
/// <param name="poly1"></param>
/// <param name="poly2"></param>
/// <returns></returns>
public static bool PolygonsAreSame2D(IList<Point2D> poly1, IList<Point2D> poly2)
{
int numVerts1 = poly1.Count;
int numVerts2 = poly2.Count;
if (numVerts1 != numVerts2)
{
return false;
}
const double kEpsilon = 0.01;
const double kEpsilonSq = kEpsilon * kEpsilon;
// Bounds the same to within tolerance, are there polys the same?
Point2D vdelta = new Point2D(0.0, 0.0);
for (int k = 0; k < numVerts2; ++k)
{
// Look for a match in verts2 to the first vertex in verts1
vdelta.Set(poly1[0]);
vdelta.Subtract(poly2[k]);
if (vdelta.MagnitudeSquared() < kEpsilonSq)
{
// Found match to the first point, now check the other points continuing round
// if the points don't match in the first direction we check, then it's possible
// that the polygons have a different winding order, so we check going round
// the opposite way as well
int matchedVertIndex = k;
bool bReverseSearch = false;
while (true)
{
bool bMatchFound = true;
for (int i = 1; i < numVerts1; ++i)
{
if (!bReverseSearch)
{
++k;
}
else
{
--k;
if (k < 0)
{
k = numVerts2 - 1;
}
}
vdelta.Set(poly1[i]);
vdelta.Subtract(poly2[k % numVerts2]);
if (vdelta.MagnitudeSquared() >= kEpsilonSq)
{
if (bReverseSearch)
{
// didn't find a match going in either direction, so the polygons are not the same
return false;
}
else
{
// mismatch in the first direction checked, so check the other direction.
k = matchedVertIndex;
bReverseSearch = true;
bMatchFound = false;
break;
}
}
}
if (bMatchFound)
{
return true;
}
}
}
}
return false;
}
示例2: OnPaint
//.........这里部分代码省略.........
Point2D screenScaler = new Point2D((double)ClientSize.Width / (double)w, (double)ClientSize.Height / (double)h);
Point2D zoomPoint = new Point2D(-mZoomPoint.X, mZoomPoint.Y);
zoomPoint.RotateDegrees(t.DisplayRotate);
zoomPoint.Scale(1.0 / screenScaler.X, 1.0 / screenScaler.Y);
float zoom = mZoomLevel * (float)Math.Min(screenScaler.X, screenScaler.Y);
fx.TranslateTransform(ctr.Xf, ctr.Yf);
fx.RotateTransform(t.DisplayRotate);
fx.ScaleTransform(zoom, -zoom);
fx.TranslateTransform((-(xmax + xmin) / 2.0f) - zoomPoint.Xf, (-(ymax + ymin) / 2.0f) - zoomPoint.Yf);
var penConstrained = new Pen(Color.Red, 1.0f / zoom);
//var penDelaunay = new Pen(Color.Blue, 1.0f / zoom);
var penNormal = new Pen(Color.Silver, 1.0f / zoom);
var penErrorCase1 = new Pen(Color.Purple, 1.0f / zoom);
var penErrorCase2 = new Pen(Color.Cyan, 1.0f / zoom);
foreach (var tri in t.Triangles)
{
PointF[] pts = new PointF[]
{
new PointF(tri.Points[0].Xf, tri.Points[0].Yf),
new PointF(tri.Points[1].Xf, tri.Points[1].Yf),
new PointF(tri.Points[2].Xf, tri.Points[2].Yf),
};
for (int i = 0; i < 3; ++i)
{
if (t.DisplayFlipX)
{
pts[i].X = xmax - (pts[i].X - xmin);
}
if (t.DisplayFlipY)
{
pts[i].Y = ymax - (pts[i].Y - ymin);
}
}
for (int i = 0; i < 3; ++i)
{
var curPen = penNormal;
DTSweepConstraint edge = null;
bool isConstrained = tri.GetConstrainedEdgeCCW(tri.Points[i]);
bool hasConstrainedEdge = tri.GetEdgeCCW(tri.Points[i], out edge);
if (isConstrained || hasConstrainedEdge)
{
if (isConstrained && hasConstrainedEdge)
{
curPen = penConstrained;
}
else if (isConstrained && !hasConstrainedEdge)
{
// this will happen when edges are split and is expected
//curPen = penErrorCase1;
curPen = penConstrained;
}
else
{
curPen = penErrorCase2;
}
}
//else if (tri.GetDelaunayEdgeCCW(tri.Points[i]))
//{
// curPen = penDelaunay;
//}
fx.DrawLine(curPen, pts[i], pts[(i + 1) % 3]);
}
}
fx.ResetTransform();
{
Point2D imageMouseCoord = new Point2D(mMouseImageCoord.X, (double)ClientSize.Height - mMouseImageCoord.Y);
imageMouseCoord.Subtract(ctr);
imageMouseCoord.RotateDegrees(t.DisplayRotate);
imageMouseCoord.Scale(1.0 / mZoomLevel);
imageMouseCoord.Scale(1.0 / screenScaler.X, 1.0 / screenScaler.Y);
imageMouseCoord.Translate((w / 2.0) + zoomPoint.X, (h / 2.0) + zoomPoint.Y);
if (t.DisplayFlipX)
{
imageMouseCoord.X = (double)xmax - (imageMouseCoord.X - (double)xmin);
}
if (t.DisplayFlipY)
{
imageMouseCoord.Y = (double)ymax - (imageMouseCoord.Y - (double)ymin);
}
Font textFont = new Font("Times New Roman", 12);
System.Drawing.Brush textBrush = System.Drawing.Brushes.Black;
fx.DrawString("Image X: " + imageMouseCoord.X.ToString(), textFont, textBrush, new PointF(20.0f, ClientSize.Height - 40.0f));
fx.DrawString("Image Y: " + imageMouseCoord.Y.ToString(), textFont, textBrush, new PointF(20.0f, ClientSize.Height - 20.0f));
fx.DrawString("ZoomPoint X: " + zoomPoint.X.ToString(), textFont, textBrush, new PointF(300.0f, ClientSize.Height - 40.0f));
fx.DrawString("ZoomPoint Y: " + zoomPoint.Y.ToString(), textFont, textBrush, new PointF(300.0f, ClientSize.Height - 20.0f));
fx.DrawString("ZoomLevel: " + mZoomLevel.ToString(), textFont, textBrush, new PointF(ClientSize.Width - 150.0f, ClientSize.Height - 20.0f));
//fx.DrawString("MX: " + mMouseImageCoord.X.ToString(), textFont, textBrush, new PointF(600.0f, ClientSize.Height - 40.0f));
//fx.DrawString("MY: " + mMouseImageCoord.Y.ToString(), textFont, textBrush, new PointF(600.0f, ClientSize.Height - 20.0f));
}
}
fx.DrawImage(ExampleData.Logo256x256, ClientSize.Width - kImageWidth - 10, 10, kImageWidth, kImageWidth);
base.OnPaint(e);
}