Пример #1
0
        public Text()
        {
            _symbol = new SimpleTextSymbol();
            _symbol.Font = Current.Engine.CreateFont("Arial", 20);
            _symbol.Text = _text;
            _symbol.TextSymbolAlignment = TextSymbolAlignment.leftAlignOver;
            //this.Symbol = _symbol;

            AggregateGeometry aGeometry = new AggregateGeometry();
            Polygon polygon = new Polygon();
            Ring ring = new Ring();
            ring.AddPoint(new Point(0, 0));
            ring.AddPoint(new Point(1, 0));
            ring.AddPoint(new Point(1, 1));
            ring.AddPoint(new Point(0, 1));
            polygon.AddRing(ring);

            aGeometry.AddGeometry(polygon);
            aGeometry.AddGeometry(new Point(0, 0));

            this.Template = aGeometry;

            RemoveAllGrabbers();
            AddGrabber(GrabberIDs.rotation);
            AddGrabber(GrabberIDs.move);
        }
Пример #2
0
        public IGeometry Build(Vector3 c1, int xStories, int yStories, int zStories)
        {
            var c2 = new Vector3(
                c1.X + (xStories * this.storyCalculator.StorySize),
                c1.Y + (yStories * this.storyCalculator.StorySize),
                c1.Z + (zStories * this.storyCalculator.StorySize));

            var mod = this.modColor.Pick();

            var storyWidthsX = this.generateColumns(xStories).ToArray();
            var storyWidthsZ = this.generateColumns(zStories).ToArray();

            var front = new ColumnedPanel(c1, yStories, storyWidthsX, Panel.Plane.XY, Panel.Facing.Out, mod, this.storyCalculator);
            var back  = new ColumnedPanel(c2, yStories, storyWidthsX, Panel.Plane.XY, Panel.Facing.In, mod, this.storyCalculator);

            var right = new ColumnedPanel(new Vector3(c2.X, c1.Y, c1.Z), yStories, storyWidthsZ, Panel.Plane.YZ, Panel.Facing.Out, mod, this.storyCalculator);
            var left  = new ColumnedPanel(new Vector3(c1.X, c2.Y, c2.Z), yStories, storyWidthsZ, Panel.Plane.YZ, Panel.Facing.In, mod, this.storyCalculator);

            var tx1 = new Vector2(0, 0);

            var top = new Panel(
                new Vector3(c1.X, c2.Y, c1.Z),
                new Vector2(c2.X - c1.X, c2.Z - c1.Z),
                Panel.Plane.XZ,
                Panel.Facing.Out,
                tx1,
                tx1,
                mod);

            var aggregate = new AggregateGeometry(front, back, right, left, top);

            return(aggregate);
        }
Пример #3
0
        static public IGeometry SqlBytesToGeometry(SqlBytes sqlbytes)
        {
            try
            {
                GeometryDef geomDef = new GeometryDef();
                geomDef.HasZ = geomDef.HasM = false;


                using (BinaryReader r = new BinaryReader(new MemoryStream()))
                {
                    r.BaseStream.Write(sqlbytes.Buffer, 0, sqlbytes.Buffer.Length);
                    r.BaseStream.Position = 0;

                    switch ((geometryType)r.ReadInt32())
                    {
                    case geometryType.Aggregate:
                        AggregateGeometry ageom = new AggregateGeometry();
                        ageom.Deserialize(r, geomDef);
                        return(ageom);

                    case geometryType.Envelope:
                        Envelope env = new Envelope();
                        env.Deserialize(r, geomDef);
                        return(env);

                    case geometryType.Multipoint:
                        MultiPoint mp = new MultiPoint();
                        mp.Deserialize(r, geomDef);
                        return(mp);

                    case geometryType.Point:
                        Point p = new Point();
                        p.Deserialize(r, geomDef);
                        return(p);

                    case geometryType.Polygon:
                        Polygon polygon = new Polygon();
                        polygon.Deserialize(r, geomDef);
                        return(polygon);

                    case geometryType.Polyline:
                        Polyline line = new Polyline();
                        line.Deserialize(r, geomDef);
                        return(line);

                    default:
                        return(null);
                    }
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
        private static IAggregateGeometry CreateGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM)
        {
            // Get the Number of Geometries in this Collection.
            int numGeometries = (int)ReadUInt32(reader, byteOrder);

            AggregateGeometry aGeometry = new AggregateGeometry();

            for (int g = 0; g < numGeometries; g++)
            {
                IGeometry geometry = WKBToGeometry(reader, byteOrder);
                if (geometry != null)
                {
                    aGeometry.AddGeometry(geometry);
                }
            }

            return(aGeometry);
        }
Пример #5
0
        public static IGeometry GML2Geometry(string gml, GmlVersion gmlVersion)
        {
            try
            {
                gml = gml.Replace("<gml:", "<").Replace("</gml:", "</");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(gml);

                XmlNode geomNode = doc.ChildNodes[0];

                ISpatialReference sRef = null;
                if ((int)gmlVersion > 2 && geomNode.Attributes["srsName"] != null)
                {
                    sRef = SpatialReference.FromID(geomNode.Attributes["srsName"].Value);
                }

                switch (geomNode.Name)
                {
                case "Point":
                    return(GML2Point(geomNode, sRef));

                case "pointProperty":
                    return(GML2Point(geomNode.SelectSingleNode("Point"), sRef));

                case "Box":
                case "Envelope":
                    return(GML2Envelope(geomNode, sRef));

                case "LineString":
                    IPath path = GML2Path(geomNode, sRef);
                    if (path == null)
                    {
                        return(null);
                    }

                    Polyline polyline = new Polyline();
                    polyline.AddPath(path);
                    return(polyline);

                case "MultiLineString":
                    return(GML2Polyline(geomNode, sRef));

                case "curveProperty":
                    return(GML2Polyline(geomNode, sRef));

                case "Polygon":
                    return(GML2Polygon(geomNode, sRef));

                case "MultiPolygon":
                    AggregateGeometry aGeom1 = new AggregateGeometry();
                    foreach (XmlNode polygonNode in geomNode.SelectNodes("polygonMember/Polygon"))
                    {
                        IPolygon polygon = GML2Polygon(polygonNode, sRef);
                        if (polygon != null)
                        {
                            aGeom1.AddGeometry(polygon);
                        }
                    }
                    if (aGeom1.GeometryCount == 0)
                    {
                        return(null);
                    }

                    IPolygon mpolygon1 = (IPolygon)aGeom1[0];
                    for (int i = 1; i < aGeom1.GeometryCount; i++)
                    {
                        IPolygon p = (IPolygon)aGeom1[i];
                        for (int r = 0; r < p.RingCount; r++)
                        {
                            mpolygon1.AddRing(p[r]);
                        }
                    }
                    return(mpolygon1);

                case "surfaceProperty":
                    AggregateGeometry aGeom2 = new AggregateGeometry();
                    foreach (XmlNode polygonNode in geomNode.SelectNodes("Surface/patches/PolygonPatch"))
                    {
                        IPolygon polygon = GML2Polygon(polygonNode, sRef);
                        if (polygon != null)
                        {
                            aGeom2.AddGeometry(polygon);
                        }
                    }
                    if (aGeom2.GeometryCount == 0)
                    {
                        return(null);
                    }

                    IPolygon mpolygon2 = (IPolygon)aGeom2[0];
                    for (int i = 1; i < aGeom2.GeometryCount; i++)
                    {
                        IPolygon p = (IPolygon)aGeom2[i];
                        for (int r = 0; r < p.RingCount; r++)
                        {
                            mpolygon2.AddRing(p[r]);
                        }
                    }
                    return(mpolygon2);

                default:
                    return(null);
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                return(null);
            }
        }
        private object Transform2D_(object geometry, bool inverse)
        {
            if (_projectionPipeline == null)
            {
                return(geometry);
            }

            CoordinateReferenceSystem from = _fromSrs, to = _toSrs;
            bool fromProjective = _fromProjective, toProjektive = _toProjective;

            if (geometry == null)
            {
                return(null);
            }

            if (from == null || to == null)
            {
                return(geometry);
            }

            if (geometry is PointCollection)
            {
                IPointCollection pColl = (IPointCollection)geometry;
                int pointCount         = pColl.PointCount;
                if (pointCount == 0)
                {
                    return(geometry);
                }

                IPointCollection target = null;

                var basicTransformations = BasicTransformations(inverse);
                for (int b = 0, b_to = basicTransformations.Length; b < b_to; b++)
                {
                    BasicCoordinateTransform t = basicTransformations[b];

                    if (pColl is IRing)
                    {
                        target = new Ring();
                    }
                    else if (pColl is IPath)
                    {
                        target = new Path();
                    }
                    else if (pColl is IMultiPoint)
                    {
                        target = new MultiPoint();
                    }
                    else
                    {
                        target = new PointCollection();
                    }

                    for (int i = 0; i < pointCount; i++)
                    {
                        ProjCoordinate cFrom = new ProjCoordinate(pColl[i].X, pColl[i].Y);
                        var            cTo   = new ProjCoordinate();
                        t.Transform(cFrom, cTo);
                        target.AddPoint(new Point(cTo.X, cTo.Y));
                    }

                    pColl = target;
                }
                return(target);
            }
            if (geometry is IPoint)
            {
                IPoint target = null;

                var basicTransformations = BasicTransformations(inverse);
                for (int b = 0, b_to = basicTransformations.Length; b < b_to; b++)
                {
                    BasicCoordinateTransform t = basicTransformations[b];

                    ProjCoordinate cFrom = new ProjCoordinate(((IPoint)geometry).X, ((IPoint)geometry).Y), cTo = new ProjCoordinate();
                    t.Transform(cFrom, cTo);
                    target = new Point(cTo.X, cTo.Y);

                    geometry = target;
                }
                return(target);
            }
            if (geometry is IEnvelope)
            {
                return(Transform2D_(((IEnvelope)geometry).ToPolygon(10), inverse));
            }
            if (geometry is IPolyline)
            {
                int       count    = ((IPolyline)geometry).PathCount;
                IPolyline polyline = new Polyline();
                for (int i = 0; i < count; i++)
                {
                    polyline.AddPath((IPath)Transform2D_(((IPolyline)geometry)[i], inverse));
                }
                return(polyline);
            }
            if (geometry is IPolygon)
            {
                int      count   = ((IPolygon)geometry).RingCount;
                IPolygon polygon = new Polygon();
                for (int i = 0; i < count; i++)
                {
                    polygon.AddRing((IRing)Transform2D_(((IPolygon)geometry)[i], inverse));
                }
                return(polygon);
            }

            if (geometry is IAggregateGeometry)
            {
                int count = ((IAggregateGeometry)geometry).GeometryCount;
                IAggregateGeometry aGeom = new AggregateGeometry();
                for (int i = 0; i < count; i++)
                {
                    aGeom.AddGeometry((IGeometry)Transform2D_(((IAggregateGeometry)geometry)[i], inverse));
                }
                return(aGeom);
            }

            return(null);
        }
Пример #7
0
        static public IGeometry AXL2Geometry(string axl, bool ignoreBuffer)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<g>" + axl + "</g>");

                AggregateGeometry aGeom = new AggregateGeometry();
                IPoint            point;

                XmlNode bufferNode = null;
                foreach (XmlNode node in doc.ChildNodes[0].ChildNodes)
                {
                    switch (node.Name)
                    {
                    case "BUFFER":
                        if (!ignoreBuffer)
                        {
                            bufferNode = node;
                        }
                        break;

                    case "POINT":
                        point = PointFromAxl(node);
                        AddSrs(node, point);
                        aGeom.AddGeometry(point);
                        break;

                    case "MULTIPOINT":
                        IMultiPoint mpoint = new MultiPoint();
                        AddSrs(node, mpoint);
                        foreach (XmlNode pointnode in node.SelectNodes("POINT"))
                        {
                            point = PointFromAxl(pointnode);
                            mpoint.AddPoint(point);
                        }
                        if (mpoint.PointCount == 0)
                        {
                            PointsFromCoords(mpoint, node.SelectSingleNode("COORDS"));
                        }
                        aGeom.AddGeometry(mpoint);
                        break;

                    case "ENVELOPE":
                        IEnvelope envelope = new Envelope(
                            Convert.ToDouble(node.Attributes["minx"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["miny"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["maxx"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["maxy"].Value.Replace(".", ",")));
                        AddSrs(node, envelope);
                        aGeom.AddGeometry(envelope);
                        break;

                    case "POLYLINE":
                        IPolyline pline = new Polyline();
                        AddSrs(node, pline);
                        foreach (XmlNode pathnode in node.SelectNodes("PATH"))
                        {
                            IPath path = new gView.Framework.Geometry.Path();
                            foreach (XmlNode pointnode in pathnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                path.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in pathnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(path, coordnode);
                            }
                            pline.AddPath(path);
                        }
                        aGeom.AddGeometry(pline);
                        break;

                    case "POLYGON":
                        IPolygon pgon = new Polygon();
                        AddSrs(node, pgon);
                        foreach (XmlNode ringnode in node.SelectNodes("RING"))
                        {
                            IRing ring = new gView.Framework.Geometry.Ring();
                            foreach (XmlNode pointnode in ringnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                ring.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(ring, coordnode);
                            }
                            pgon.AddRing(ring);
                            foreach (XmlNode holenode in ringnode.SelectNodes("HOLE"))
                            {
                                IRing hole = new gView.Framework.Geometry.Ring();
                                foreach (XmlNode pointnode in holenode.SelectNodes("POINT"))
                                {
                                    point = PointFromAxl(pointnode);
                                    hole.AddPoint(point);
                                }
                                foreach (XmlNode coordnode in holenode.SelectNodes("COORDS"))
                                {
                                    PointsFromCoords(hole, coordnode);
                                }
                                pgon.AddRing(hole);
                            }
                        }
                        foreach (XmlNode ringnode in node.SelectNodes("HOLE"))
                        {
                            IRing ring = new gView.Framework.Geometry.Ring();
                            foreach (XmlNode pointnode in ringnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                ring.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(ring, coordnode);
                            }
                            pgon.AddRing(ring);
                        }
                        aGeom.AddGeometry(pgon);
                        break;
                    }
                }

                if (aGeom.GeometryCount == 0)
                {
                    return(null);
                }

                if (!ignoreBuffer &&
                    bufferNode != null && bufferNode.Attributes["distance"] != null)
                {
                    try
                    {
                        double   dist    = Convert.ToDouble(bufferNode.Attributes["distance"].Value);
                        IPolygon polygon = aGeom.Buffer(dist);
                        return(polygon);
                    }
                    catch { }
                }

                if (aGeom.GeometryCount == 1)
                {
                    return(aGeom[0]);
                }

                return(aGeom);
            }
            catch
            {
                return(null);
            }
        }
Пример #8
0
        public IGeometry Build(Vector3 c1, int xStories, int yStories, int zStories)
        {
            var c2 = new Vector3(
                c1.X + (xStories * this.storyCalculator.StorySize),
                c1.Y + (yStories * this.storyCalculator.StorySize),
                c1.Z + (zStories * this.storyCalculator.StorySize));

            var mod = this.modColor.Pick();

            var tx1 = this.storyCalculator.RandomPosition();
            var tx2 = new Vector2(tx1.X + xStories, tx1.Y + yStories);

            var front = new Panel(
                c1,
                new Vector2(c2.X - c1.X, c2.Y - c1.Y),
                Panel.Plane.XY,
                Panel.Facing.Out,
                this.storyCalculator.ToTexture(tx1),
                this.storyCalculator.ToTexture(tx2),
                mod);

            tx1 = this.storyCalculator.RandomPosition();
            tx2 = new Vector2(tx1.X + xStories, tx1.Y - yStories); // The corner coordinates get flipped for back/left

            var back = new Panel(
                c2,
                new Vector2(c1.X - c2.X, c1.Y - c2.Y),
                Panel.Plane.XY,
                Panel.Facing.In,
                this.storyCalculator.ToTexture(tx1),
                this.storyCalculator.ToTexture(tx2),
                mod);

            tx1 = this.storyCalculator.RandomPosition();
            tx2 = new Vector2(tx1.X + zStories, tx1.Y + yStories);

            var right = new Panel(
                new Vector3(c2.X, c1.Y, c1.Z),
                new Vector2(c2.Z - c1.Z, c2.Y - c1.Y),
                Panel.Plane.YZ,
                Panel.Facing.Out,
                this.storyCalculator.ToTexture(tx1),
                this.storyCalculator.ToTexture(tx2),
                mod);

            tx1 = this.storyCalculator.RandomPosition();
            tx2 = new Vector2(tx1.X + zStories, tx1.Y - yStories);

            var left = new Panel(
                new Vector3(c1.X, c2.Y, c2.Z),
                new Vector2(c1.Z - c2.Z, c1.Y - c2.Y),
                Panel.Plane.YZ,
                Panel.Facing.In,
                this.storyCalculator.ToTexture(tx1),
                this.storyCalculator.ToTexture(tx2),
                mod);

            tx1 = new Vector2(0, 0);

            var top = new Panel(
                new Vector3(c1.X, c2.Y, c1.Z),
                new Vector2(c2.X - c1.X, c2.Z - c1.Z),
                Panel.Plane.XZ,
                Panel.Facing.Out,
                tx1,
                tx1,
                mod);

            var aggregate = new AggregateGeometry(front, back, right, left, top);

            return(aggregate);
        }
        private object Transform2D_(object geometry, IntPtr from, IntPtr to, bool fromProjective, bool toProjektive)
        {
            if (geometry == null)
            {
                return(null);
            }

            if (from == IntPtr.Zero || to == IntPtr.Zero)
            {
                return(geometry);
            }
            if (geometry is PointCollection)
            {
                PointCollection pColl      = (PointCollection)geometry;
                int             pointCount = pColl.PointCount;
                if (pointCount == 0)
                {
                    return(geometry);
                }

                IntPtr buffer = Marshal.AllocHGlobal(pointCount * 2 * sizeof(double));

                lock (LockThis1)
                {
                    try
                    {
                        IntPtr xPtr = IntPtr.Zero, yPtr = IntPtr.Zero;
                        unsafe
                        {
                            double *b = (double *)buffer;

                            for (int i = 0; i < pointCount; i++)
                            {
                                b[i] = pColl[i].X;
                                b[pointCount + i] = pColl[i].Y;
                            }

                            if (!fromProjective)
                            {
                                ToRad(buffer, pointCount * 2);
                            }

                            xPtr = (IntPtr)(&b[0]);
                            yPtr = (IntPtr)(&b[pointCount]);
                        }
                        if (from != IntPtr.Zero && to != IntPtr.Zero)
                        {
                            //if (preTo > 0)
                            //{
                            //    Proj4Wrapper.pj_transform(from, preTo, pointCount, 0, xPtr, yPtr, (IntPtr)0);
                            //    Proj4Wrapper.pj_transform(preTo, to, pointCount, 0, xPtr, yPtr, (IntPtr)0);
                            //}
                            //else
                            //{
                            Proj4Wrapper.pj_transform(from, to, pointCount, 0, xPtr, yPtr, IntPtr.Zero);
                            //}
                        }
                        if (!toProjektive)
                        {
                            ToDeg(buffer, pointCount * 2);
                        }

                        IPointCollection target = null;
                        if (pColl is IRing)
                        {
                            target = new Ring();
                        }
                        else if (pColl is IPath)
                        {
                            target = new Path();
                        }
                        else if (pColl is IMultiPoint)
                        {
                            target = new MultiPoint();
                        }
                        else
                        {
                            target = new PointCollection();
                        }

                        unsafe
                        {
                            double *b = (double *)buffer;
                            for (int i = 0; i < pointCount; i++)
                            {
                                target.AddPoint(new Point(b[i], b[pointCount + i]));
                            }

                            return(target);
                        }
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(buffer);
                    }
                }
                //double [] x;
                //double [] y;
                //((PointCollection)geometry).getXY(out x,out y);
                //if (!fromProjective) ToRad(x, y);

                //if(from>0 && to>0)
                //    Proj4Wrapper.pj_transform(from,to,x.Length,0,x,y,null);
                //if (!toProjektive) ToDeg(x, y);

                //if(geometry is Ring)
                //{
                //    Ring ring=new Ring();
                //    ring.setXYZ(x,y,null);
                //    return ring;
                //}
                //if(geometry is Path)
                //{
                //    Path path=new Path();
                //    path.setXYZ(x,y,null);
                //    return path;
                //}
                //if (geometry is MultiPoint)
                //{
                //    MultiPoint multiPoint = new MultiPoint();
                //    multiPoint.setXYZ(x, y, null);
                //    return multiPoint;
                //}
                //return new PointCollection(x,y,null);
            }
            if (geometry is IPoint)
            {
                double[] x = { ((IPoint)geometry).X };
                double[] y = { ((IPoint)geometry).Y };
                if (!fromProjective)
                {
                    ToRad(x, y);
                }

                lock (LockThis1)
                {
                    if (from != IntPtr.Zero && to != IntPtr.Zero)
                    {
                        unsafe
                        {
                            fixed(double *xx = x)
                            fixed(double *yy = y)
                            {
                                IntPtr xPtr = (IntPtr)(xx);
                                IntPtr yPtr = (IntPtr)(yy);

                                //if (preTo > 0)
                                //{
                                //    Proj4Wrapper.pj_transform(from, preTo, x.Length, 0, xPtr, yPtr, (IntPtr)0);
                                //    Proj4Wrapper.pj_transform(preTo, to, x.Length, 0, xPtr, yPtr, (IntPtr)0);
                                //}
                                //else
                                //{
                                Proj4Wrapper.pj_transform(from, to, x.Length, 0, xPtr, yPtr, IntPtr.Zero);
                                //}
                            }
                        }
                    }
                }
                if (!toProjektive)
                {
                    ToDeg(x, y);
                }

                return(new Point(x[0], y[0]));
            }
            if (geometry is IEnvelope)
            {
                return(Transform2D_(((IEnvelope)geometry).ToPolygon(10), from, to, fromProjective, toProjektive));
            }
            if (geometry is IPolyline)
            {
                int       count    = ((IPolyline)geometry).PathCount;
                IPolyline polyline = new Polyline();
                for (int i = 0; i < count; i++)
                {
                    polyline.AddPath((IPath)Transform2D_(((IPolyline)geometry)[i], from, to, fromProjective, toProjektive));
                }
                return(polyline);
            }
            if (geometry is IPolygon)
            {
                int      count   = ((IPolygon)geometry).RingCount;
                IPolygon polygon = new Polygon();
                for (int i = 0; i < count; i++)
                {
                    polygon.AddRing((IRing)Transform2D_(((IPolygon)geometry)[i], from, to, fromProjective, toProjektive));
                }
                return(polygon);
            }

            if (geometry is IAggregateGeometry)
            {
                int count = ((IAggregateGeometry)geometry).GeometryCount;
                IAggregateGeometry aGeom = new AggregateGeometry();
                for (int i = 0; i < count; i++)
                {
                    aGeom.AddGeometry((IGeometry)Transform2D_(((IAggregateGeometry)geometry)[i], from, to, fromProjective, toProjektive));
                }
                return(aGeom);
            }

            return(null);
        }
Пример #10
0
        public ClassicBuilding(Vector3 corner, int widthStories, int heightStories, int depthStories, StoryCalculator storyCalc)
        {
            var builder = new ColumnedBuildingBlockBuilder(storyCalc);

            var random      = new Random();
            int totalHeight = 0;

            var geometry = new List <IGeometry>();

            var oppCorner = new Vector3(
                corner.X + (widthStories * storyCalc.StorySize),
                corner.Y - 0.5f,
                corner.Z + (depthStories * storyCalc.StorySize));

            Vector3 center = (oppCorner + corner) / 2;

            center.Y = 0.0f;

            // Base of the building
            geometry.Add(new Box(corner, oppCorner));

            var tierScale = 0.6 + (random.NextDouble() * 0.4);

            widthStories -= 1;
            depthStories -= 1;
            while (totalHeight < heightStories)
            {
                corner.X = center.X - ((widthStories / 2.0f) * storyCalc.StorySize);
                corner.Z = center.Z - ((depthStories / 2.0f) * storyCalc.StorySize);
                corner.Y = center.Y + (totalHeight * storyCalc.StorySize);

                int tierHeight;
                if (heightStories - totalHeight < 5)
                {
                    tierHeight = heightStories - totalHeight;
                }
                else
                {
                    tierHeight = heightStories * 2;

                    while (totalHeight + tierHeight > heightStories && tierHeight != 0)
                    {
                        tierHeight = heightStories - totalHeight > totalHeight / 3
                            ? random.Next((heightStories * 5) / 6) + (heightStories / 6)
                            : heightStories - totalHeight;
                    }
                }

                geometry.Add(builder.Build(corner, widthStories, tierHeight, depthStories));

                totalHeight += tierHeight;

                widthStories = (int)(tierScale * widthStories);
                depthStories = (int)(tierScale * depthStories);
                if (widthStories < 1)
                {
                    widthStories = 1;
                }

                if (depthStories < 1)
                {
                    depthStories = 1;
                }
            }

            this.aggregateGeometry = new AggregateGeometry(geometry);
        }