Exemple #1
0
        /// <summary>
        /// Calculates the intersection of this extent and the other extent.  A result
        /// with a min greater than the max in either direction is considered invalid
        /// and represents no intersection.
        /// </summary>
        /// <param name="other">The other extent to intersect with.</param>
        public override Extent Intersection(Extent other)
        {
            IExtentZ zOther = other as IExtentZ;
            IExtentM mOther = other as IExtentM;
            Extent   result = null;

            if (HasZ && zOther != null && other.HasZ)
            {
                ExtentMZ zResult = new ExtentMZ
                {
                    MinZ = (MinZ > zOther.MinZ) ? MinZ : zOther.MinZ,
                    MaxZ = (MaxZ < zOther.MaxZ) ? MaxZ : zOther.MaxZ
                };

                result = zResult;
            }
            if (HasM && mOther != null && other.HasM)
            {
                ExtentM mResult = result as ExtentM ?? new ExtentM();
                mResult.MinM = (MinM > mOther.MinM) ? MinM : mOther.MinM;
                mResult.MaxM = (MaxM < mOther.MaxM) ? MaxM : mOther.MaxM;
                result       = mResult;
            }
            else
            {
                result = new Extent();
            }

            result.MinX = (MinX > other.MinX) ? MinX : other.MinX;
            result.MaxX = (MaxX < other.MaxX) ? MaxX : other.MaxX;
            result.MinY = (MinY > other.MinY) ? MinY : other.MinY;
            result.MaxY = (MaxY < other.MaxY) ? MaxY : other.MaxY;
            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Considers the ShapeType and upgrades the extent class to accommodate M and Z.
 /// This is automatically called form the setter of ShapeType.
 /// </summary>
 public void UpgradeExtent()
 {
     if (_shapeType == ShapeType.MultiPointZ || _shapeType == ShapeType.PointZ ||
         _shapeType == ShapeType.PolygonZ || _shapeType == ShapeType.PolyLineZ)
     {
         IExtentZ zTest = Extent as IExtentZ;
         if (zTest == null)
         {
             Extent ext = new ExtentMZ();
             if (_extent != null)
             {
                 ext.CopyFrom(_extent);
             }
             _extent = ext;
         }
         // Already implements M and Z
     }
     else if (_shapeType == ShapeType.MultiPointM || _shapeType == ShapeType.PointM ||
              _shapeType == ShapeType.PolygonM || _shapeType == ShapeType.PolyLineM)
     {
         IExtentM mTest = Extent as IExtentM;
         if (mTest == null)
         {
             Extent ext = new ExtentMZ();
             if (_extent != null)
             {
                 ext.CopyFrom(_extent);
             }
             _extent = ext;
         }
         // already at least implements M
     }
     // No upgrade necessary
 }
Exemple #3
0
        public void ExtentSizeCheck()
        {
            int count = 100000;
            double w = 0;
            // Measure starting point memory use
            long start = GC.GetTotalMemory(true);

            // Allocate a new array of count Extent classes.
            // If methods don't count, should be about 3,200,000 bytes.
            ExtentMZ[] memhog = new ExtentMZ[count];

            for (int i = 0; i < count; i++)
            {
                memhog[i] = new ExtentMZ();
                if (!memhog[i].IsEmpty()) w = memhog[i].Width;
            }

            // Obtain measurements after creating the new byte[]
            long end = GC.GetTotalMemory(true);
            Debug.WriteLine("width: " + w);
            long size = (end - start) / count;

            // Ensure that the Array stays in memory and doesn't get optimized away
            Debug.WriteLine("Memory size of Extent = " + size);

            // Size of Extent is 44.
            // Size of ExtentM is 60
            // Size of ExtentMZ is 76
        }
Exemple #4
0
        /// <summary>
        /// This reads the string and attempts to derive values from the text.
        /// </summary>
        public static bool TryParse(string text, out Extent result, out string nameFailed)
        {
            double xmin, xmax, ymin, ymax, mmin, mmax;

            result = null;
            if (text.Contains("Z"))
            {
                double zmin, zmax;
                nameFailed = "Z";
                ExtentMZ mz = new ExtentMZ();
                if (TryExtract(text, "Z", out zmin, out zmax) == false)
                {
                    return(false);
                }
                mz.MinZ    = zmin;
                mz.MaxZ    = zmax;
                nameFailed = "M";
                if (TryExtract(text, "M", out mmin, out mmax) == false)
                {
                    return(false);
                }
                mz.MinM = mmin;
                mz.MaxM = mmax;
                result  = mz;
            }
            else if (text.Contains("M"))
            {
                nameFailed = "M";
                ExtentM me = new ExtentM();
                if (TryExtract(text, "M", out mmin, out mmax) == false)
                {
                    return(false);
                }
                me.MinM = mmin;
                me.MaxM = mmax;
                result  = me;
            }
            else
            {
                result = new Extent();
            }
            nameFailed = "X";
            if (TryExtract(text, "X", out xmin, out xmax) == false)
            {
                return(false);
            }
            result.MinX = xmin;
            result.MaxX = xmax;
            nameFailed  = "Y";
            if (TryExtract(text, "Y", out ymin, out ymax) == false)
            {
                return(false);
            }
            result.MinY = ymin;
            result.MaxY = ymax;
            return(true);
        }
Exemple #5
0
 /// <summary>
 /// Produces a clone, rather than using this same object.
 /// </summary>
 /// <returns>Returns a copy of this object.</returns>
 public override object Clone()
 {
     ExtentMZ copy = new ExtentMZ(MinX, MinY, MinM, MinZ, MaxX, MaxY, MaxM, MinZ);
     return copy;
 }
Exemple #6
0
        /// <summary>
        /// Calculates the intersection of this extent and the other extent.  A result
        /// with a min greater than the max in either direction is considered invalid
        /// and represents no intersection.
        /// </summary>
        /// <param name="other">The other extent to intersect with.</param>
        public override Extent Intersection(Extent other)
        {
            IExtentZ zOther = other as IExtentZ;
            IExtentM mOther = other as IExtentM;
            Extent result = null;

            if (HasZ && zOther != null && other.HasZ)
            {
                ExtentMZ zResult = new ExtentMZ
                                   {
                                       MinZ = (MinZ > zOther.MinZ) ? MinZ : zOther.MinZ,
                                       MaxZ = (MaxZ < zOther.MaxZ) ? MaxZ : zOther.MaxZ
                                   };

                result = zResult;
            }
            if (HasM && mOther != null && other.HasM)
            {
                ExtentM mResult = result as ExtentM ?? new ExtentM();
                mResult.MinM = (MinM > mOther.MinM) ? MinM : mOther.MinM;
                mResult.MaxM = (MaxM < mOther.MaxM) ? MaxM : mOther.MaxM;
                result = mResult;
            }
            else
            {
                result = new Extent();
            }

            result.MinX = (MinX > other.MinX) ? MinX : other.MinX;
            result.MaxX = (MaxX < other.MaxX) ? MaxX : other.MaxX;
            result.MinY = (MinY > other.MinY) ? MinY : other.MinY;
            result.MaxY = (MaxY < other.MaxY) ? MaxY : other.MaxY;
            return result;
        }
Exemple #7
0
        /// <summary>
        /// Produces a clone, rather than using this same object.
        /// </summary>
        /// <returns>Returns a copy of this object.</returns>
        public override object Clone()
        {
            ExtentMZ copy = new ExtentMZ(MinX, MinY, MinM, MinZ, MaxX, MaxY, MaxM, MinZ);

            return(copy);
        }
Exemple #8
0
 /// <summary>
 /// Considers the ShapeType and upgrades the extent class to accommodate M and Z.
 /// This is automatically called form the setter of ShapeType.
 /// </summary>
 public void UpgradeExtent()
 {
     if (_shapeType == ShapeType.MultiPointZ || _shapeType == ShapeType.PointZ ||
         _shapeType == ShapeType.PolygonZ || _shapeType == ShapeType.PolyLineZ)
     {
         IExtentZ zTest = Extent as IExtentZ;
         if (zTest == null)
         {
             Extent ext = new ExtentMZ();
             if (_extent != null) ext.CopyFrom(_extent);
             _extent = ext;
         }
         // Already implements M and Z
     }
     else if (_shapeType == ShapeType.MultiPointM || _shapeType == ShapeType.PointM ||
              _shapeType == ShapeType.PolygonM || _shapeType == ShapeType.PolyLineM)
     {
         IExtentM mTest = Extent as IExtentM;
         if (mTest == null)
         {
             Extent ext = new ExtentMZ();
             if (_extent != null) ext.CopyFrom(_extent);
             _extent = ext;
         }
         // already at least implements M
     }
     // No upgrade necessary
 }
Exemple #9
0
 /// <summary>
 /// This reads the string and attempts to derive values from the text.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="result"></param>
 /// <param name="nameFailed"></param>
 /// <returns></returns>
 public static bool TryParse(string text, out Extent result, out string nameFailed)
 {
     double xmin, xmax, ymin, ymax, mmin, mmax;
     result = null;
     if (text.Contains("Z"))
     {
         double zmin, zmax;
         nameFailed = "Z";
         ExtentMZ mz = new ExtentMZ();
         if (TryExtract(text, "Z", out zmin, out zmax) == false) return false;
         mz.MinZ = zmin;
         mz.MaxZ = zmax;
         nameFailed = "M";
         if (TryExtract(text, "M", out mmin, out mmax) == false) return false;
         mz.MinM = mmin;
         mz.MaxM = mmax;
         result = mz;
     }
     else if (text.Contains("M"))
     {
         nameFailed = "M";
         ExtentM me = new ExtentM();
         if (TryExtract(text, "M", out mmin, out mmax) == false) return false;
         me.MinM = mmin;
         me.MaxM = mmax;
         result = me;
     }
     else
     {
         result = new Extent();
     }
     nameFailed = "X";
     if (TryExtract(text, "X", out xmin, out xmax) == false) return false;
     result.MinX = xmin;
     result.MaxX = xmax;
     nameFailed = "Y";
     if (TryExtract(text, "Y", out ymin, out ymax) == false) return false;
     result.MinY = ymin;
     result.MaxY = ymax;
     return true;
 }