本文整理汇总了C#中Point.Min方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Min方法的具体用法?C# Point.Min怎么用?C# Point.Min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.Min方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethod1
public void TestMethod1()
{
int nBuildings = 3;
Point[] buildings = new Point[nBuildings];
//buildings[0] = new Point(-5,-3);
//buildings[1] = new Point(-9, 2);
//buildings[2] = new Point(3, -4);
buildings[0] = new Point(1, 2);
buildings[1] = new Point(0, 0);
buildings[2] = new Point(2, 2);
int widthDistance = buildings.Max(_ => _.X) - buildings.Min(_ => _.X);
var average = buildings.Average(_ => _.Y);
var yPos = (long) buildings.Select(p => new Tuple<int, double>(p.Y, Math.Abs(p.Y - average))).OrderBy(_ => _.Item2).First().Item1;
var dist = buildings.Select(p => Math.Abs((p.Y - yPos))).Sum();
var totalDistance = (long)widthDistance + dist;
Assert.AreEqual(4,totalDistance);
}
示例2: calculateMainCableLength
private static long calculateMainCableLength(Point[] locations)
{
long largestXCoordinate = locations.Max(location => location.X);
long smallestXCoordinate = locations.Min(location => location.X);
return largestXCoordinate - smallestXCoordinate;
}
示例3: Polygon
/// <summary>
/// Creates a polygon shape from the specified points.
/// </summary>
/// <param name="points">The points.</param>
public Polygon(Point[] points)
{
// Set the location.
this.location = points.Min();
// Set the size.
this.size = new Size(points.Max().Subtract(this.location));
// Set the points.
this.points = new Point[points.Length];
for (int index = 0; index < points.Length; index++)
{
this.points[index] = points[index].Subtract(this.location);
}
}
示例4: ToBitmap
public static Bitmap ToBitmap(Point[] sequence)
{
if (sequence.Length == 0)
return null;
int xmax = (int)sequence.Max(x => x.X);
int xmin = (int)sequence.Min(x => x.X);
int ymax = (int)sequence.Max(x => x.Y);
int ymin = (int)sequence.Min(x => x.Y);
int width = xmax - xmin;
int height = ymax - ymin;
Bitmap bmp = new Bitmap(width + 16, height + 16);
Graphics g = Graphics.FromImage(bmp);
for (int i = 1; i < sequence.Length; i++)
{
int x = (int)sequence[i].X - xmin;
int y = (int)sequence[i].Y - ymin;
int p = (int)Accord.Math.Tools.Scale(0, sequence.Length, 0, 255, i);
int prevX = (int)sequence[i - 1].X - xmin;
int prevY = (int)sequence[i - 1].Y - ymin;
using (Brush brush = new SolidBrush(Color.FromArgb(255 - p, 0, p)))
using (Pen pen = new Pen(brush, 16))
{
pen.StartCap = LineCap.Round;
pen.EndCap = LineCap.Round;
g.DrawLine(pen, prevX, prevY, x, y);
}
}
return bmp;
}
示例5: _addSerieAsBezier
private IEnumerable<Shape> _addSerieAsBezier(Point[] points, bool animate = true)
{
if (points.Length < 2) return Enumerable.Empty<Shape>();
var addedFigures = new List<Shape>();
Point[] cp1, cp2;
BezierSpline.GetCurveControlPoints(points, out cp1, out cp2);
var lines = new PathSegmentCollection();
var areaLines = new PathSegmentCollection {new LineSegment(points[0], true)};
var l = 0d;
for (var i = 0; i < cp1.Length; ++i)
{
lines.Add(new BezierSegment(cp1[i], cp2[i], points[i + 1], true));
areaLines.Add(new BezierSegment(cp1[i], cp2[i], points[i + 1], true));
//it would be awesome to use a better formula to calculate bezier lenght
l += Math.Sqrt(
Math.Pow(Math.Abs(cp1[i].X - cp2[i].X), 2) +
Math.Pow(Math.Abs(cp1[i].Y - cp2[i].Y), 2));
l += Math.Sqrt(
Math.Pow(Math.Abs(cp2[i].X - points[i + 1].X), 2) +
Math.Pow(Math.Abs(cp2[i].Y - points[i + 1].Y), 2));
}
//aprox factor, it was calculated by aproximation.
//the more line is curved, the more it fails.
l = l * .65;
areaLines.Add(new LineSegment(new Point(points.Max(x => x.X), ToPlotArea(Chart.Min.Y, AxisTags.Y)), true));
var f = new PathFigure(points[0], lines, false);
var fa = new PathFigure(new Point(points.Min(x => x.X), ToPlotArea(Chart.Min.Y, AxisTags.Y)), areaLines, false);
var g = new PathGeometry(new[] {f});
var ga = new PathGeometry(new[] {fa});
var path = new Path
{
Stroke = Stroke,
StrokeThickness = StrokeThickness,
Data = g,
StrokeEndLineCap = PenLineCap.Round,
StrokeStartLineCap = PenLineCap.Round,
StrokeDashOffset = l,
StrokeDashArray = new DoubleCollection {l, l},
ClipToBounds = true
};
var patha = new Path
{
StrokeThickness = 0,
Data = ga,
Fill = Fill,
ClipToBounds = true
};
Chart.Canvas.Children.Add(path);
addedFigures.Add(path);
Chart.Canvas.Children.Add(patha);
addedFigures.Add(patha);
var draw = new DoubleAnimationUsingKeyFrames
{
BeginTime = TimeSpan.FromSeconds(0),
KeyFrames = new DoubleKeyFrameCollection
{
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = l
},
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(750),
Value = 0
}
}
};
Storyboard.SetTarget(draw, path);
Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
var sbDraw = new Storyboard();
sbDraw.Children.Add(draw);
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
sbDraw.Begin();
animated = true;
}
}
if (!animated) path.StrokeDashOffset = 0;
return addedFigures;
}
示例6: _addSerieAsBezier
private IEnumerable<Shape> _addSerieAsBezier(Point[] points, bool animate = true)
{
if (points.Length < 2) return Enumerable.Empty<Shape>();
var addedFigures = new List<Shape>();
Point[] cp1, cp2;
BezierSpline.GetCurveControlPoints(points, out cp1, out cp2);
var lines = new PathSegmentCollection();
var areaLines = new PathSegmentCollection { new LineSegment(points[0], true) };
var l = 0d;
for (var i = 0; i < cp1.Length; ++i)
{
lines.Add(new BezierSegment(cp1[i], cp2[i], points[i + 1], true));
areaLines.Add(new BezierSegment(cp1[i], cp2[i], points[i + 1], true));
l += GetBezierLength(new [] { points[i], cp1[i], cp2[i], points[i + 1] });
}
l *= 1.05;
l /= StrokeThickness;
var lastP = Chart.Invert
? new Point(ToDrawMargin(Chart.Min.X, AxisTags.X), points.Min(x => x.Y))
: new Point(points.Max(x => x.X), ToDrawMargin(Chart.Min.Y, AxisTags.Y));
areaLines.Add(new LineSegment(lastP, true));
var f = new PathFigure(points[0], lines, false);
var aOrigin = Chart.Invert
? new Point(ToDrawMargin(Chart.Min.X, AxisTags.X), points.Max(x => x.Y))
: new Point(points.Min(x => x.X), ToDrawMargin(Chart.Min.Y, AxisTags.Y));
var fa = new PathFigure(aOrigin, areaLines, false);
var g = new PathGeometry(new[] { f });
var ga = new PathGeometry(new[] { fa });
var path = new Path
{
Stroke = Stroke,
StrokeThickness = StrokeThickness,
Data = g,
StrokeEndLineCap = PenLineCap.Round,
StrokeStartLineCap = PenLineCap.Round,
StrokeDashOffset = l,
StrokeDashArray = new DoubleCollection { l, l },
ClipToBounds = true
};
var patha = new Path
{
StrokeThickness = 0,
Data = ga,
Fill = Fill,
ClipToBounds = true
};
Chart.DrawMargin.Children.Add(path);
addedFigures.Add(path);
Chart.DrawMargin.Children.Add(patha);
addedFigures.Add(patha);
var draw = new DoubleAnimationUsingKeyFrames
{
BeginTime = TimeSpan.FromSeconds(0),
KeyFrames = new DoubleKeyFrameCollection
{
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = l
},
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(750),
Value = 0
}
}
};
Storyboard.SetTarget(draw, path);
Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
var sbDraw = new Storyboard();
sbDraw.Children.Add(draw);
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
sbDraw.Begin();
animated = true;
}
}
if (!animated) path.StrokeDashOffset = 0;
return addedFigures;
}
示例7: ConvexHull
public static Point[] ConvexHull(Point[] points)
{
if (points.Length < 3)
{
throw new ArgumentException("At least 3 points reqired", "points");
}
List<Point> hull = new List<Point>();
// get leftmost point
Point vPointOnHull = points.Where(p => p.X == points.Min(min => min.X)).First();
Point vEndpoint;
do
{
hull.Add(vPointOnHull);
vEndpoint = points[0];
for (int i = 1; i < points.Length; i++)
{
if ((vPointOnHull == vEndpoint)
|| (Orientation(vPointOnHull, vEndpoint, points[i]) == -1))
{
vEndpoint = points[i];
}
}
vPointOnHull = vEndpoint;
}
while (vEndpoint != hull[0]);
return hull.ToArray();
}