コード例 #1
0
ファイル: Polygon.cs プロジェクト: kingofcrabs/NetDesigner
        private static bool IsInPolygon(PointF[] poly, PointF point)
        {
            var coef = poly.Skip(1).Select((p, i) =>
                                            (point.Y - poly[i].Y) * (p.X - poly[i].X)
                                          - (point.X - poly[i].X) * (p.Y - poly[i].Y))
                                    .ToList();

            if (coef.Any(p => p == 0))
                return true;

            for (int i = 1; i < coef.Count(); i++)
            {
                if (coef[i] * coef[i - 1] < 0)
                    return false;
            }
            return true;
        }
コード例 #2
0
ファイル: Surface.cs プロジェクト: floatas/highsign
        public void DrawSegments(PointF[] Stroke)
        {
            if (RenderMethod == RenderMode.Standard)
            {
                // Ensure that surface is visible
                if (!this.Visible)
                {
                    this.TopMost = true;
                    this.Show();
                }

                // Create list of points that are new this draw
                List<PointF> NewPoints = new List<PointF>();

                // Get number of points added since last draw including last point of last stroke and add new points to new points list
                int iDelta = Stroke.Count() - LastStroke.Count() + 1;
                NewPoints.AddRange(Stroke.Skip(Stroke.Count() - iDelta).Take(iDelta));

                // Draw new line segments to main drawing surface
                SurfaceGraphics.DrawLines(DrawingPen, NewPoints.Select(p => TranslatePoint(p)).ToArray());

                // Set last stroke to copy of current stroke
                // ToList method creates value copy of stroke list and assigns it to last stroke
                LastStroke = Stroke.ToList();
            }
            else
            {
                foreach (CompatibilitySurface surface in CompatibilitySurfaces)
                    surface.SurfaceGraphics.DrawLines(DrawingPen, surface.OffsetPoints(Stroke));
            }
        }
コード例 #3
0
 public static PointF[] Properize(PointF[] points, Size pattern)
 {
     var res = new PointF[points.Length];
     var hs = new int[pattern.Height];
     for (var i = 0; i < pattern.Height; i++) hs[i] = i;
     var heighted = hs.Select(h => points.Skip(h * pattern.Width).Take(pattern.Width).OrderBy(p => p.X).ToArray())
         .OrderBy(r => r.OrderBy(p => p.X).Select(p => p.Y).First()).ToArray();
     for (var y = 0; y < pattern.Height; y++)
     {
         for (var x = 0; x < pattern.Width; x++)
             res[x + y * pattern.Width] = heighted[y][x];
     }
     return res;
 }