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


C# Point.Max方法代码示例

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


在下文中一共展示了Point.Max方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
        }
开发者ID:fathib,项目名称:akkaNet,代码行数:25,代码来源:NetworkCabling.cs

示例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;
        }
开发者ID:r2miao,项目名称:CodinGame-Solutions,代码行数:7,代码来源:Network+Cabling.cs

示例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);
     }
 }
开发者ID:alexbikfalvi,项目名称:DotNetApi,代码行数:17,代码来源:Polygon.cs

示例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;
        }
开发者ID:tapans,项目名称:Kinect-and-Machine-Learning,代码行数:38,代码来源:Sequence.cs

示例5: _addSeriesAsPolyline

        private IEnumerable<Shape> _addSeriesAsPolyline(Point[] points, Brush color, double storkeThickness,
            bool animate = true)
        {
            if (points.Length < 2) return Enumerable.Empty<Shape>();
            var addedFigures = new List<Shape>();

            var l = 0d;
            for (var i = 1; i < points.Length; i++)
            {
                var p1 = points[i - 1];
                var p2 = points[i];
                l += Math.Sqrt(
                    Math.Pow(Math.Abs(p1.X - p2.X), 2) +
                    Math.Pow(Math.Abs(p1.Y - p2.Y), 2)
                    );
            }

            var f = points.First();
            var p = points.Where(x => x != f);
            var g = new PathGeometry
            {
                Figures = new PathFigureCollection(new List<PathFigure>
                {
                    new PathFigure
                    {
                        StartPoint = f,
                        Segments = new PathSegmentCollection(
                            p.Select(x => new LineSegment {Point = new Point(x.X, x.Y)}))
                    }
                })
            };

            var path = new Path
            {
                Stroke = color,
                StrokeThickness = storkeThickness,
                Data = g,
                StrokeEndLineCap = PenLineCap.Round,
                StrokeStartLineCap = PenLineCap.Round,
                StrokeDashOffset = l,
                StrokeDashArray = new DoubleCollection { l, l },
                ClipToBounds = true
            };

            var sp = points.ToList();
            sp.Add(new Point(points.Max(x => x.X), ToPlotArea(Chart.Min.Y, AxisTags.Y)));

            Chart.Canvas.Children.Add(path);
            addedFigures.Add(path);

            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;
        }
开发者ID:gitter-badger,项目名称:Live-Charts,代码行数:83,代码来源:ScatterSeries.cs

示例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));
				//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;
		}
开发者ID:RightCrowd,项目名称:Live-Charts,代码行数:91,代码来源:LineSeries.cs

示例7: _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;
        }
开发者ID:zali-fd,项目名称:Live-Charts,代码行数:90,代码来源:LineSeries.cs

示例8: BuildTerrainSprtRadius

        private static double BuildTerrainSprtRadius(Point[] points)
        {
            // Get the average min distance between the points
            List<Tuple<int, int, double>> distances = new List<Tuple<int, int, double>>();

            for (int outer = 0; outer < points.Length - 1; outer++)
            {
                for (int inner = outer + 1; inner < points.Length; inner++)
                {
                    double distance = (points[outer] - points[inner]).LengthSquared;

                    distances.Add(Tuple.Create(outer, inner, distance));
                }
            }

            double avgDist;
            if (distances.Count == 0)
            {
                avgDist = points[0].ToVector().Length;
                if (Math1D.IsNearZero(avgDist))
                {
                    avgDist = .1;
                }
            }
            else
            {
                avgDist = Enumerable.Range(0, points.Length).
                    Select(o => distances.
                        Where(p => p.Item1 == o || p.Item2 == o).       // get the disances that mention this index
                        Min(p => p.Item3)).     // only keep the smallest of those distances
                    Average();      // get the average of all the mins

                avgDist = Math.Sqrt(avgDist);
            }

            // Get the distance of the farthest out neuron
            double maxDist = points.Max(o => o.ToVector().LengthSquared);
            maxDist = Math.Sqrt(maxDist);

            // Radius of the extra points will be the avg distance beyond that max
            return maxDist + avgDist;
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:42,代码来源:MotionController.cs

示例9: SetSelectionCenter

        public void SetSelectionCenter(Point e)
        {
            var r = new Rectangle();
            var s = this.CurrentSelectionLocation;
            var w = s.Width / 2;
            var h = s.Height / 2;
            var p = e.Max(new Point(w, h)).Min(new Point(this.CurrentCanvasSize.X - w, this.CurrentCanvasSize.Y - h));

            r.Left = p.X - w;
            r.Top = p.Y - h;
            r.Width = s.Width;
            r.Height = s.Height;

            SetSelectionLocation(r);

            if (SelectionCenterChanged != null)
                SelectionCenterChanged(p);
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:18,代码来源:ArenaControl.cs


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