Esempio n. 1
0
            public void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (this.basePath != null)
                    {
                        this.basePath.Dispose();
                        this.basePath = null;
                    }

                    if (this.continuation != null)
                    {
                        this.continuation.Dispose();
                        this.continuation = null;
                    }

                    if (this.cumulativeTransform != null)
                    {
                        this.cumulativeTransform.Dispose();
                        this.cumulativeTransform = null;
                    }

                    if (this.interimTransform != null)
                    {
                        this.interimTransform.Dispose();
                        this.interimTransform = null;
                    }
                }
            }
Esempio n. 2
0
        // only works if base is empty
        public void SetContinuation(GeometryGraphicsPath path, CombineMode combineMode, bool takeOwnership)
        {
            lock (this.syncRoot)
            {
                if (!this.data.basePath.IsEmpty)
                {
                    throw new InvalidOperationException("base path must be empty to use this overload of SetContinuation");
                }

                OnChanging();

                CommitInterimTransform();
                ResetCumulativeTransform();

                this.data.continuationCombineMode = combineMode;

                if (takeOwnership)
                {
                    this.data.continuation.Dispose();
                    this.data.continuation = path;
                }
                else
                {
                    this.data.continuation.Reset();
                    this.data.continuation.AddPath(path, false);
                }

                OnChanged();
            }
        }
Esempio n. 3
0
 public GeometryRegion CreateRegionRaw()
 {
     using (GeometryGraphicsPath path = CreatePath())
     {
         return(new GeometryRegion(path));
     }
 }
Esempio n. 4
0
        public GeometryGraphicsPath Clone()
        {
            GeometryGraphicsPath path = new GeometryGraphicsPath((GraphicsPath)gdiPath.Clone());

            path.tooComplex = this.tooComplex;
            return(path);
        }
Esempio n. 5
0
 public bool IsVisible(Point pt)
 {
     using (GeometryGraphicsPath path = CreatePath())
     //GeometryGraphicsPath path = GetPathReadOnly();
     {
         return(path.IsVisible(pt));
     }
 }
Esempio n. 6
0
 public RectangleF GetBoundsF(bool applyInterimTransformation)
 {
     using (GeometryGraphicsPath path = this.CreatePath(applyInterimTransformation))
     //GeometryGraphicsPath path = GetPathReadOnly(applyInterimTransformation);
     {
         RectangleF bounds2 = path.GetBounds2();
         return(bounds2);
     }
 }
Esempio n. 7
0
 public Data()
 {
     this.basePath                = new GeometryGraphicsPath();
     this.continuation            = new GeometryGraphicsPath();
     this.continuationCombineMode = CombineMode.Xor;
     this.cumulativeTransform     = new Matrix();
     this.cumulativeTransform.Reset();
     this.interimTransform = new Matrix();
     this.interimTransform.Reset();
 }
Esempio n. 8
0
 public GeometryGraphicsPath CreatePixelatedPath()
 {
     using (GeometryGraphicsPath path = CreatePath())
     //GeometryGraphicsPath path = GetPathReadOnly();
     {
         using (GeometryRegion region = new GeometryRegion(path))
         {
             GeometryGraphicsPath pixellatedPath = GeometryGraphicsPath.FromRegion(region);
             return(pixellatedPath);
         }
     }
 }
Esempio n. 9
0
 public void CommitContinuation()
 {
     lock (this.syncRoot)
     {
         OnChanging();
         this.data.continuation.CloseAllFigures();
         GeometryGraphicsPath newBasePath = CreatePath();
         this.data.basePath.Dispose();
         this.data.basePath = newBasePath;
         this.data.continuation.Reset();
         this.data.continuationCombineMode = CombineMode.Xor;
         OnChanged();
     }
 }
Esempio n. 10
0
        public GeometryGraphicsPath CreatePath(bool applyInterimTransform)
        {
            lock (this.syncRoot)
            {
                GeometryGraphicsPath returnPath = GeometryGraphicsPath.Combine(this.data.basePath,
                                                                               this.data.continuationCombineMode, this.data.continuation);

                if (applyInterimTransform)
                {
                    returnPath.Transform(this.data.interimTransform);
                }

                return(returnPath);
            }
        }
Esempio n. 11
0
        public static GeometryGraphicsPath FromRegion(GeometryRegion region)
        {
            Rectangle[] scans = region.GetRegionScansReadOnlyInt();

            if (scans.Length == 1)
            {
                var path = new GeometryGraphicsPath();
                path.AddRectangle(scans[0]);
                path.CloseFigure();
                return(path);
            }
            else
            {
                Rectangle bounds  = region.GetBoundsInt();
                var       stencil = new BitVector2D(bounds.Width, bounds.Height);

                for (int i = 0; i < scans.Length; ++i)
                {
                    Rectangle rect = scans[i];
                    rect.X -= bounds.X;
                    rect.Y -= bounds.Y;

                    stencil.UnsafeSet(rect, true);
                }

                GeometryGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height));

                using (Matrix matrix = new Matrix())
                {
                    matrix.Reset();
                    matrix.Translate(bounds.X, bounds.Y);
                    path.Transform(matrix);
                }

                return(path);
            }
        }
Esempio n. 12
0
 public GeometryRegion(GeometryGraphicsPath pdnPath)
     : this(pdnPath.GetRegionCache())
 {
 }
Esempio n. 13
0
        public static GeometryGraphicsPath Combine(GeometryGraphicsPath subjectPath, CombineMode combineMode, GeometryGraphicsPath clipPath)
        {
            switch (combineMode)
            {
            case CombineMode.Complement:
                return(Combine(clipPath, CombineMode.Exclude, subjectPath));

            case CombineMode.Replace:
                return(clipPath.Clone());

            case CombineMode.Xor:
            case CombineMode.Intersect:
            case CombineMode.Union:
            case CombineMode.Exclude:
                if (subjectPath.IsEmpty && clipPath.IsEmpty)
                {
                    return(new GeometryGraphicsPath());    // empty path
                }

                if (subjectPath.IsEmpty)
                {
                    switch (combineMode)
                    {
                    case CombineMode.Xor:
                    case CombineMode.Union:
                        return(clipPath.Clone());

                    case CombineMode.Intersect:
                    case CombineMode.Exclude:
                        return(new GeometryGraphicsPath());

                    default:
                        throw new InvalidEnumArgumentException();
                    }
                }

                if (clipPath.IsEmpty)
                {
                    switch (combineMode)
                    {
                    case CombineMode.Exclude:
                    case CombineMode.Xor:
                    case CombineMode.Union:
                        return(subjectPath.Clone());

                    case CombineMode.Intersect:
                        return(new GeometryGraphicsPath());

                    default:
                        throw new InvalidEnumArgumentException();
                    }
                }
                else
                {
                    return(null);
                    //                        GraphicsPath resultPath = PtnGraphics.ClipPath(subjectPath, combineMode, clipPath);
                    //                        return new GeometryGraphicsPath(resultPath);
                }

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a graphics path from the given stencil buffer. It should be filled with 'true' values
        /// to indicate the areas that should be outlined.
        /// </summary>
        /// <param name="stencil">The stencil buffer to read from. NOTE: The contents of this will be destroyed when this method returns.</param>
        /// <param name="bounds">The bounding box within the stencil buffer to limit discovery to.</param>
        /// <returns>A GeometryGraphicsPath with traces that outline the various areas from the given stencil buffer.</returns>
        public unsafe static GeometryGraphicsPath PathFromStencil(IBitVector2D stencil, Rectangle bounds)
        {
            if (stencil.IsEmpty)
            {
                return(new GeometryGraphicsPath());
            }

            var   ret   = new GeometryGraphicsPath();
            Point start = bounds.Location;
            var   pts   = new Vector <Point>();
            int   count = 0;

            // find all islands
            while (true)
            {
                bool startFound = false;

                while (true)
                {
                    if (stencil[start])
                    {
                        startFound = true;
                        break;
                    }

                    ++start.X;

                    if (start.X >= bounds.Right)
                    {
                        ++start.Y;
                        start.X = bounds.Left;

                        if (start.Y >= bounds.Bottom)
                        {
                            break;
                        }
                    }
                }

                if (!startFound)
                {
                    break;
                }

                pts.Clear();
                Point last  = new Point(start.X, start.Y + 1);
                Point curr  = new Point(start.X, start.Y);
                Point next  = curr;
                Point left  = Point.Empty;
                Point right = Point.Empty;

                // trace island outline
                while (true)
                {
                    left.X = ((curr.X - last.X) + (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                    left.Y = ((curr.Y - last.Y) - (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                    right.X = ((curr.X - last.X) - (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                    right.Y = ((curr.Y - last.Y) + (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                    if (bounds.Contains(left) && stencil[left])
                    {
                        // go left
                        next.X += curr.Y - last.Y;
                        next.Y -= curr.X - last.X;
                    }
                    else if (bounds.Contains(right) && stencil[right])
                    {
                        // go straight
                        next.X += curr.X - last.X;
                        next.Y += curr.Y - last.Y;
                    }
                    else
                    {
                        // turn right
                        next.X -= curr.Y - last.Y;
                        next.Y += curr.X - last.X;
                    }

                    if (Math.Sign(next.X - curr.X) != Math.Sign(curr.X - last.X) ||
                        Math.Sign(next.Y - curr.Y) != Math.Sign(curr.Y - last.Y))
                    {
                        pts.Add(curr);
                        ++count;
                    }

                    last = curr;
                    curr = next;

                    if (next.X == start.X && next.Y == start.Y)
                    {
                        break;
                    }
                }

                Point[]    points = pts.ToArray();
                Scanline[] scans  = Utility.GetScans(points);

                foreach (Scanline scan in scans)
                {
                    stencil.Invert(scan);
                }

                ret.AddLines(points);
                ret.CloseFigure();
            }

            return(ret);
        }
Esempio n. 15
0
        public static GeometryGraphicsPath FromRegions(GeometryRegion lhs, CombineMode combineMode, GeometryRegion rhs)
        {
            Rectangle   lhsBounds = lhs.GetBoundsInt();
            Rectangle   rhsBounds = rhs.GetBoundsInt();
            int         left      = Math.Min(lhsBounds.Left, rhsBounds.Left);
            int         top       = Math.Min(lhsBounds.Top, rhsBounds.Top);
            int         right     = Math.Max(lhsBounds.Right, rhsBounds.Right);
            int         bottom    = Math.Max(lhsBounds.Bottom, rhsBounds.Bottom);
            Rectangle   bounds    = Rectangle.FromLTRB(left, top, right, bottom);
            BitVector2D stencil   = new BitVector2D(bounds.Width, bounds.Height);

            Rectangle[] lhsScans = lhs.GetRegionScansReadOnlyInt();
            Rectangle[] rhsScans = rhs.GetRegionScansReadOnlyInt();

            switch (combineMode)
            {
            case CombineMode.Complement:
            case CombineMode.Intersect:
            case CombineMode.Replace:
                throw new ArgumentException("combineMode can't be Complement, Intersect, or Replace");
            }

            for (int i = 0; i < lhsScans.Length; ++i)
            {
                Rectangle rect = lhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                stencil.UnsafeSet(rect, true);
            }

            for (int i = 0; i < rhsScans.Length; ++i)
            {
                Rectangle rect = rhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                switch (combineMode)
                {
                case CombineMode.Xor:
                    stencil.UnsafeInvert(rect);
                    break;

                case CombineMode.Union:
                    stencil.UnsafeSet(rect, true);
                    break;

                case CombineMode.Exclude:
                    stencil.UnsafeSet(rect, false);
                    break;
                }
            }

            GeometryGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height));

            using (var matrix = new Matrix())
            {
                matrix.Reset();
                matrix.Translate(bounds.X, bounds.Y);
                path.Transform(matrix);
            }

            return(path);
        }