Exemplo n.º 1
0
        static public void AddRectangle <T>(this SurfaceSelection <T> item, VectorF2 point1, VectorF2 point2)
        {
            VectorF2 lower;
            VectorF2 upper;

            point1.Order(point2, out lower, out upper);
            lower = lower.BindBetween(VectorF2.ZERO, item.GetDimensions());
            upper = upper.BindBetween(VectorF2.ZERO, item.GetDimensions());

            for (float y = lower.y; y <= upper.y; y++)
            {
                for (float x = lower.x; x <= upper.x; x++)
                {
                    item.Add(new VectorF2(x, y));
                }
            }
        }
Exemplo n.º 2
0
        public SurfaceSelection <T> PolygonSelect(Surface <T> surface, IEnumerable <VectorF2> points)
        {
            SurfaceSelection <T> selection = new SurfaceSelection <T>(surface);

            Spectrum <LineSegmentF2> y_spectrum = new Spectrum <LineSegmentF2>(
                points.CloseLoop().ConvertConnections((p1, p2) => new SpectrumBand <LineSegmentF2>(new LineSegmentF2(p1, p2), p1.y, p2.y))
                );

            for (float y = y_spectrum.GetLowerBound(); y < y_spectrum.GetUpperBound(); y++)
            {
                LineF2 scanline = new LineF2(new VectorF2(0.0f, y), new VectorF2(1.0f, 0.0f));

                y_spectrum.LookupData(y)
                .Convert(l => {
                    VectorF2 point;

                    if (scanline.TryGetIntersection(l.GetLine(), out point))
                    {
                        return(point.x);
                    }

                    return(l.p1.x.Min(l.p2.x));
                })
                .Sort(z => z)
                .ConvertConnections((p, c) => Tuple.New(p, c))
                .SkipEvery(1)
                .Process(t =>
                         selection.AddRectangle(
                             new VectorF2(t.item1, y),
                             new VectorF2(t.item2, y)
                             )
                         );
            }

            return(selection);
        }
Exemplo n.º 3
0
 static public VectorF2 GetDimensions <T>(this SurfaceSelection <T> item)
 {
     return(new VectorF2(item.GetWidth(), item.GetHeight()));
 }
Exemplo n.º 4
0
 static public bool Add <T>(this SurfaceSelection <T> item, VectorF2 point)
 {
     return(item.Add(point.GetVectorI2()));
 }