Пример #1
0
    public void ConvertsToAlignedVector2()
    {
        Vector2 result = GenerationUtility.ToAlignedVector2(Vector3.up);

        Assert.AreEqual(result.x, 0f);
        Assert.AreEqual(result.y, 0f);
    }
Пример #2
0
    public void ChecksPointInPolygon()
    {
        Vector2[] polygon = new Vector2[] { Vector2.up, Vector2.right, Vector2.down, Vector2.left };

        Assert.IsFalse(GenerationUtility.IsPointInPolygon(Vector2.up * 2, ref polygon));
        Assert.IsTrue(GenerationUtility.IsPointInPolygon(Vector2.zero, ref polygon));
    }
Пример #3
0
    public void GetsMostCommonVertex()
    {
        District d = new District(Vector3.zero, new Vector3[] { Vector3.up, Vector3.zero, Vector3.right }, new DistrictConfiguration());
        District e = new District(Vector3.zero, new Vector3[] { Vector3.left, Vector3.right, Vector3.back }, new DistrictConfiguration());

        Assert.AreEqual(Vector3.right, GenerationUtility.GetMostCommonVertex(new District[] { d, e }));
    }
Пример #4
0
    public void ConvertsToAlignedVector3()
    {
        Vector3 result = GenerationUtility.ToAlignedVector3(Vector2.right);

        Assert.AreEqual(result.x, 1f);
        Assert.AreEqual(result.y, 0f);
        Assert.AreEqual(result.z, 0f);
    }
Пример #5
0
        private GenerationUtility InitGenerationAction()
        {
            var generationUtility           = new GenerationUtility();
            Mock <IBuildEngine> buildEngine = new Mock <IBuildEngine>();

            generationUtility.BuildEngine = buildEngine.Object;
            return(generationUtility);
        }
Пример #6
0
    public void GetsMidpoint()
    {
        Vector2[] verts = new Vector2[] { Vector2.up, Vector2.right, Vector2.down, Vector2.left };

        Vector2 result = GenerationUtility.GetMidpoint(new List <Vector2>(verts));

        Assert.AreEqual(result, Vector2.zero);
    }
Пример #7
0
        public static List <string> GenerateOrderedRepeatedForeignKey(int numberOfRowsToGenerate, Dictionary <string, List <string> > valuesGeneratedForDatabase, DatabaseColumn column, DatabaseTable table)
        {
            string columnName        = column.Name;
            string foreignTableName  = column.ForeignTableName;
            string foreignColumnName = column.ForeignColumnName;
            bool   isNullable        = column.IsNullable == 1;



            int           n;
            List <string> tempListOfValuesOfForeignColumn = new List <string>();

            // If no values are to be referenced assume key is nullable, and return list of null values.
            if (foreignTableName == null ||
                foreignColumnName == null ||
                !valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn))
            {
                if (isNullable == false)
                {
                    throw new GenerationException($"Values for column '{columnName}' referencing {foreignTableName}:{foreignColumnName} not found, and {columnName} is not nullable");
                }

                return(GenerationUtility.GenerateListOfNullValues(numberOfRowsToGenerate));
            }


            // problemi sa stranim kljucevima
            //if (columnName.ToLower().Contains("id") && !foreignColumnName.ToLower().Contains("id"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}
            //else if (columnName.ToLower().Contains("name") && !foreignColumnName.ToLower().Contains("name"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}

            n = tempListOfValuesOfForeignColumn.Count();

            int           counter    = 0;
            List <string> resultList = new List <string>();

            while (numberOfRowsToGenerate > 0)
            {
                resultList.Add(tempListOfValuesOfForeignColumn[counter]);

                counter++;
                if (counter >= n)
                {
                    counter = 0;
                }

                numberOfRowsToGenerate--;
            }

            return(resultList);
        }
Пример #8
0
        public override bool IsIntersectingBox(Vector3 tl, Vector3 tr, Vector3 bl, Vector3 br)
        {
            bool top    = GenerationUtility.CheckCircleLineIntersection(tl, tr, this.Position, this.Radius);
            bool bottom = GenerationUtility.CheckCircleLineIntersection(bl, br, this.Position, this.Radius);
            bool left   = GenerationUtility.CheckCircleLineIntersection(tl, bl, this.Position, this.Radius);
            bool right  = GenerationUtility.CheckCircleLineIntersection(tr, br, this.Position, this.Radius);
            bool inside = GenerationUtility.PointInBox(this.Position, tl, tr, bl, br);

            return(top || bottom || left || right || inside);
        }
Пример #9
0
        public override bool IsIntersectingLine(Vector3 begin, Vector3 end)
        {
            if (GenerationUtility.PointInCircle(begin, this.Position, this.Radius) ||
                GenerationUtility.PointInCircle(end, this.Position, this.Radius))
            {
                return(true);
            }

            return(GenerationUtility.CheckCircleLineIntersection(begin, end, this.Position, this.Radius));
        }
Пример #10
0
        public override bool IsIntersectingLine(Vector3 begin, Vector3 end)
        {
            Vector3 tl, tr, bl, br;

            BoxBounds(out tl, out tr, out bl, out br);
            if (GenerationUtility.PointInBox(begin, tl, tr, bl, br) || GenerationUtility.PointInBox(end, tl, tr, bl, br))
            {
                return(true);
            }

            return(GenerationUtility.CheckBoxLineIntersection(begin, end, tl, tr, bl, br));
        }
Пример #11
0
    public void AddsNonDuplicateVertex()
    {
        List <Vector2> verts = new List <Vector2>();

        verts = GenerationUtility.AddNonDuplicateVertex(verts, Vector2.up);

        Assert.AreEqual(verts.Count, 1);

        verts = GenerationUtility.AddNonDuplicateVertex(verts, Vector2.up);

        Assert.AreEqual(verts.Count, 1);
    }
Пример #12
0
        public void SetZHeight(Vector3 startHeight, Vector3 endHeight)
        {
            float percent;

            if (this.TopLeft.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, TopLeft.Position);
                TopLeft.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.TopRight.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, TopRight.Position);
                TopRight.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.BottomLeft.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, BottomLeft.Position);
                BottomLeft.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.BottomRight.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, BottomRight.Position);
                BottomRight.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.Top.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, Top.Position);
                Top.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.Left.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, Left.Position);
                Left.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.Right.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, Right.Position);
                Right.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }

            if (this.Bottom.Filled)
            {
                percent = GenerationUtility.PercentBetween(startHeight, endHeight, Bottom.Position);
                Bottom.SetZ(Vector3.Lerp(startHeight, endHeight, percent).z);
            }
        }
Пример #13
0
        public bool IsIntersectingLine(Vector3 begin, Vector3 end)
        {
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(this.Start.Position, this.End.Position, this.Width, out tl, out tr, out bl, out br);

            if (GenerationUtility.PointInBox(begin, tl, tr, bl, br) || GenerationUtility.PointInBox(end, tl, tr, bl, br))
            {
                return(true);
            }

            return(GenerationUtility.CheckBoxLineIntersection(begin, end, tl, tr, bl, br));
        }
        public IEnumerator RasterizeLayer(MiddleLayer l, Floor upper, Floor lower)
        {
            Square[,,,] squares = l.Squares;
            Vector3 tl, tr, bl, br;

            foreach (LayerPath p in l.Paths)
            {
                //if (p.Start is CircleRoom)
                //{
                //    CircleRoom circle = (CircleRoom)p.Start;
                //    RasterizeCircle(squares, l.rasterizationGrid, circle.Position, circle.Radius);
                //}
                //else
                //{
                //    RectangleRoom rect = (RectangleRoom)p.Start;
                //    rect.BoxBounds(out tl, out tr, out bl, out br);
                //    RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br);
                //}

                //if (p.End is CircleRoom)
                //{
                //    CircleRoom circle = (CircleRoom)p.End;
                //    RasterizeCircle(squares, l.rasterizationGrid, circle.Position, circle.Radius);
                //}
                //else
                //{
                //    RectangleRoom rect = (RectangleRoom)p.End;
                //    rect.BoxBounds(out tl, out tr, out bl, out br);
                //    RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br);
                //}

                GenerationUtility.BoxBounds(p.Start.Position, p.End.Position, p.Width, out tl, out tr, out bl, out br);
                RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br);
                yield return(null);
            }

            foreach (LayerPath p in l.Paths)
            {
                Vector3 start = GetRoomEdgePoint(p.Start, p);
                Vector3 end   = GetRoomEdgePoint(p.End, p);
                MarkForKeeping(squares, l.rasterizationGrid, start, end, p.Width);
                ReserveGridSquares(upper, start, Vector3.Lerp(start, end, .02f), p.Width);
                ReserveGridSquares(lower, Vector3.Lerp(start, end, .98f), end, p.Width);
                Vector3 startHeight = l.transform.InverseTransformPoint(p.Start.WorldPosition);
                Vector3 endHeight   = l.transform.InverseTransformPoint(p.End.WorldPosition);
                RaiseMesh(squares, l.rasterizationGrid, start, end, p.Width, startHeight, endHeight);
                yield return(null);
            }

            l.Squares = squares;
        }
 private Vector3 GetRoomEdgePoint(Room room, LayerPath p)
 {
     if (room is CircleRoom)
     {
         CircleRoom c = (CircleRoom)room;
         return(GenerationUtility.CircleLineIntersection(p.Start.Position, p.End.Position, c.Position, c.Radius));
     }
     else
     {
         Vector3       tl, tr, bl, br;
         RectangleRoom rect = (RectangleRoom)room;
         rect.BoxBounds(out tl, out tr, out bl, out br);
         return(GenerationUtility.BoxLineIntersection(p.Start.Position, p.End.Position, tl, tr, bl, br));
     }
 }
Пример #16
0
    public void SortsClockwise()
    {
        Vector2[] verts = new Vector2[] { Vector2.down, Vector2.up, Vector2.left, Vector2.right };

        List <Vector2> result = GenerationUtility.SortVerticies(new List <Vector2>(verts), Vector2.zero);

        Assert.AreEqual(result[0].x, 0.0);
        Assert.AreEqual(result[0].y, -1.0);
        Assert.AreEqual(result[1].x, 1.0);
        Assert.AreEqual(result[1].y, 0.0);
        Assert.AreEqual(result[2].x, 0.0);
        Assert.AreEqual(result[2].y, 1.0);
        Assert.AreEqual(result[3].x, -1.0);
        Assert.AreEqual(result[3].y, 0.0);
    }
Пример #17
0
        public static List <string> GenerateOrderedUniqueValuesForForeignKey(int numberOfRowsToGenerate, Dictionary <string, List <string> > valuesGeneratedForDatabase, DatabaseColumn column, DatabaseTable table)
        {
            string columnName        = column.Name;
            string foreignTableName  = column.ForeignTableName;
            string foreignColumnName = column.ForeignColumnName;
            bool   isNullable        = column.IsNullable == 1;

            List <string> tempListOfValuesOfForeignColumn = new List <string>();

            // If no values are to be referenced assume key is nullable, and return list of null values.
            if (foreignTableName == null ||
                foreignColumnName == null ||
                !valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn))
            {
                if (isNullable == false)
                {
                    throw new GenerationException($"Values for column '{columnName}' referencing {foreignTableName}:{foreignColumnName} not found, and {columnName} is not nullable");
                }

                return(GenerationUtility.GenerateListOfNullValues(numberOfRowsToGenerate));
            }

            // problemi sa stranim kljucevima
            //if (columnName.ToLower().Contains("id") && !foreignColumnName.ToLower().Contains("id"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}
            //else if (columnName.ToLower().Contains("name") && !foreignColumnName.ToLower().Contains("name"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}

            if (tempListOfValuesOfForeignColumn.Count() < numberOfRowsToGenerate)
            {
                throw new GenerationException($"Too many rows for foreign key relation. Max for configuration is {tempListOfValuesOfForeignColumn.Count()}");
            }

            List <string> resultList = new List <string>();

            for (int i = 0; i < numberOfRowsToGenerate; i++)
            {
                resultList.Add(tempListOfValuesOfForeignColumn[i]);
            }

            return(resultList);
        }
Пример #18
0
        public bool IsIntersectingCircle(Vector3 center, float radius)
        {
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(this.Start.Position, this.End.Position, this.Width, out tl, out tr, out bl, out br);
            if (GenerationUtility.PointInCircle(tl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(tr, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(bl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(br, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tl, tr, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(bl, br, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tl, bl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tr, br, center, radius))
            {
                return(true);
            }

            return(GenerationUtility.PointInBox(center, tl, tr, bl, br));
        }
Пример #19
0
        public override bool IsIntersectingBox(Vector3 tl, Vector3 tr, Vector3 bl, Vector3 br)
        {
            Vector3 ourTl, ourTr, ourBl, ourBr;

            BoxBounds(out ourTl, out ourTr, out ourBl, out ourBr);
            if (GenerationUtility.PointInBox(ourTl, tl, tr, bl, br))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(ourTr, tl, tr, bl, br))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(ourBl, tl, tr, bl, br))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(ourBr, tl, tr, bl, br))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(tl, ourTl, ourTr, ourBl, ourBr))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(tr, ourTl, ourTr, ourBl, ourBr))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(bl, ourTl, ourTr, ourBl, ourBr))
            {
                return(true);
            }

            if (GenerationUtility.PointInBox(br, ourTl, ourTr, ourBl, ourBr))
            {
                return(true);
            }

            return(false);
        }
Пример #20
0
        public override bool IsIntersectingCircle(Vector3 center, float radius)
        {
            Vector3 tl, tr, bl, br;

            BoxBounds(out tl, out tr, out bl, out br);
            if (GenerationUtility.PointInCircle(tl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(tr, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(bl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.PointInCircle(br, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tl, tr, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(bl, br, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tl, bl, center, radius))
            {
                return(true);
            }

            if (GenerationUtility.CheckCircleLineIntersection(tr, br, center, radius))
            {
                return(true);
            }

            return(GenerationUtility.PointInBox(center, tl, tr, bl, br));
        }
        private void ReserveGridSquares(Floor floor, Vector3 start, Vector3 end, float width)
        {
            RasterizationGrid rast = floor.rasterizationGrid;

            Square[,,,] squares = floor.Squares;
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br);
            float   left         = Mathf.Min(tl.x, tr.x, bl.x, br.x);
            float   right        = Mathf.Max(tl.x, tr.x, bl.x, br.x);
            float   up           = Mathf.Max(tl.y, tr.y, bl.y, br.y);
            float   down         = Mathf.Min(tl.y, tr.y, bl.y, br.y);
            Vector2 topLeft      = new Vector2(left, up);
            Vector2 bottomRight  = new Vector2(right, down);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            bool a = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopLeft.Position, tl, tr, bl, br);
                            bool b = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopRight.Position, tl, tr, bl, br);
                            bool c = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomLeft.Position, tl, tr, bl, br);
                            bool d = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomRight.Position, tl, tr, bl, br);
                            if (a || b || c || d)
                            {
                                squares[sr, sc, gr, gc].Reserved = true;
                            }
                        }
                    }
                }
            }
        }
        private bool IsInRoom(Vector3 pos, Room r1, Room r2)
        {
            Vector3 tl, tr, bl, br;

            if (r1 is CircleRoom)
            {
                if (GenerationUtility.PointInCircle(pos, r1.Position, ((CircleRoom)r1).Radius))
                {
                    return(true);
                }
            }
            else
            {
                RectangleRoom rect = (RectangleRoom)r1;
                rect.BoxBounds(out tl, out tr, out bl, out br);
                if (GenerationUtility.PointInBox(pos, tl, tr, bl, br))
                {
                    return(true);
                }
            }

            if (r2 is CircleRoom)
            {
                if (GenerationUtility.PointInCircle(pos, r2.Position, ((CircleRoom)r2).Radius))
                {
                    return(true);
                }
            }
            else
            {
                RectangleRoom rect = (RectangleRoom)r2;
                rect.BoxBounds(out tl, out tr, out bl, out br);
                if (GenerationUtility.PointInBox(pos, tl, tr, bl, br))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #23
0
        public IEnumerator RasterizeFloor(Floor f)
        {
            Square[,,,] squares = f.Squares;

            foreach (Room room in f.Rooms)
            {
                if (room is CircleRoom)
                {
                    CircleRoom circle = (CircleRoom)room;
                    RasterizeCircle(squares, f.rasterizationGrid, circle.Position, circle.Radius);
                }
                else
                {
                    RectangleRoom rect = (RectangleRoom)room;
                    Vector3       tl, tr, bl, br;
                    rect.BoxBounds(out tl, out tr, out bl, out br);
                    RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br);
                }
            }
            yield return(null);

            if (f.Paths != null)
            {
                foreach (FloorPath p in f.Paths)
                {
                    foreach (Edge e in p.Edges)
                    {
                        Vector3 tl, tr, bl, br;
                        GenerationUtility.BoxBounds(e.Start, e.End, e.Width, out tl, out tr, out bl, out br);
                        RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br);
                        if (!e.TailEdge)
                        {
                            RasterizeCircle(squares, f.rasterizationGrid, e.End, e.Width / 2f);
                        }
                    }
                }
            }

            f.Squares = squares;
        }
        private void RaiseMesh(Square[,,,] squares, RasterizationGrid rast, Vector3 start, Vector3 end, float width, Vector3 startHeight, Vector3 endHeight)
        {
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br);
            float   left         = Mathf.Min(tl.x, tr.x, bl.x, br.x);
            float   right        = Mathf.Max(tl.x, tr.x, bl.x, br.x);
            float   up           = Mathf.Max(tl.y, tr.y, bl.y, br.y);
            float   down         = Mathf.Min(tl.y, tr.y, bl.y, br.y);
            Vector2 topLeft      = new Vector2(left, up);
            Vector2 bottomRight  = new Vector2(right, down);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            if (squares[sr, sc, gr, gc].Marked)
                            {
                                squares[sr, sc, gr, gc].SetZHeight(startHeight, endHeight);
                            }
                        }
                    }
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Generates list of random values that were generated for referenced column in referenced table. If no referenced values are found or generates list of NULL values.
        /// </summary>
        /// <param name="numberOfRowsToGenerate"></param>
        /// <param name="valuesGeneratedForDatabase">Hash containing lists of values generated for all tables and columns.</param>
        /// <param name="foreignTableName"></param>
        /// <param name="foreignColumnName"></param>
        /// <returns></returns>
        public static List <string> GenerateRandomValuesForForeignKey(int numberOfRowsToGenerate, Dictionary <string, List <string> > valuesGeneratedForDatabase, DatabaseColumn column, DatabaseTable table)
        {
            string columnName        = column.Name;
            string foreignTableName  = column.ForeignTableName;
            string foreignColumnName = column.ForeignColumnName;
            bool   isNullable        = column.IsNullable == 1;

            List <string> tempListOfValuesOfForeignColumn = new List <string>();

            // If no values are to be referenced assume key is nullable, and return list of null values.
            if (foreignTableName == null ||
                foreignColumnName == null ||
                !valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn))
            {
                if (isNullable == false)
                {
                    throw new GenerationException($"Values for column '{columnName}' referencing {foreignTableName}:{foreignColumnName} not found, and {columnName} is not nullable");
                }

                return(GenerationUtility.GenerateListOfNullValues(numberOfRowsToGenerate));
            }

            // problemi sa stranim kljucevima
            //if (columnName.ToLower().Contains("id") && !foreignColumnName.ToLower().Contains("id"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}
            //else if (columnName.ToLower().Contains("name") && !foreignColumnName.ToLower().Contains("name"))
            //{
            //    foreignColumnName = columnName;
            //    valuesGeneratedForDatabase.TryGetValue($"{foreignTableName}:{foreignColumnName}", out tempListOfValuesOfForeignColumn);
            //}

            Random        random                = new Random();
            List <string> resultingList         = new List <string>();
            int           numberOfForeignValues = tempListOfValuesOfForeignColumn.Count();
            int           numberOfUniques       = table.DatabaseColumns.Where(c => c.IsUnique == 1).Count();

            // If this table is unique then there must be at least as many foreign keys
            if (column.IsUnique == 1 && numberOfRowsToGenerate > numberOfForeignValues && numberOfUniques == 1)
            {
                throw new GenerationException($@"Column {column.Table.Name}:{columnName} is unique and references {foreignTableName}:{foreignColumnName}. Table {column.Table.Name} has {numberOfRowsToGenerate} rows, {foreignTableName} has {numberOfForeignValues} rows. Table with unique foreign key to another table must have more or equal rows to referenced table.");
            }

            // If this is a selfreflection only use the values that were made before this row
            if (foreignTableName == column.Table.Name)
            {
                for (int i = 0; i < numberOfRowsToGenerate; i++)
                {
                    // If column is unique then watch out for duplicates
                    if (column.IsUnique == 1)
                    {
                        int    randomValue = random.Next(0, i);
                        string value       = tempListOfValuesOfForeignColumn[randomValue];
                        while (resultingList.Contains(value))
                        {
                            randomValue = randomValue + 1 % (i + 1);
                            value       = tempListOfValuesOfForeignColumn[randomValue];
                        }
                        resultingList.Add(value);
                    }
                    else
                    {
                        resultingList.Add(tempListOfValuesOfForeignColumn[random.Next(0, i)]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < numberOfRowsToGenerate; i++)
                {
                    if (column.IsUnique == 1)
                    {
                        // I there are no more new values place old ones
                        if (resultingList.Count() >= numberOfForeignValues)
                        {
                            for (int j = i; j < numberOfRowsToGenerate; j++)
                            {
                                resultingList.Add(tempListOfValuesOfForeignColumn[random.Next(0, numberOfForeignValues - 1)]);
                            }

                            break;
                        }

                        int    randomValue = random.Next(0, numberOfForeignValues - 1);
                        string value       = tempListOfValuesOfForeignColumn[randomValue];
                        while (resultingList.Contains(value))
                        {
                            randomValue = (randomValue + 1) % numberOfForeignValues;
                            value       = tempListOfValuesOfForeignColumn[randomValue];
                        }
                        resultingList.Add(value);
                    }
                    else
                    {
                        resultingList.Add(tempListOfValuesOfForeignColumn[random.Next(0, numberOfForeignValues - 1)]);
                    }
                }
            }

            return(resultingList);
        }
        /// <summary> Checks if the given edge is blocked. </summary>
        /// <param name="begin"> The start of the edge. </param>
        /// <param name="end"> The end of the edge. </param>
        /// <param name="r1"> The starting room of the path. </param>
        /// <param name="r2"> The ending room of the path. </param>
        /// <param name="floor"> The floor this path is on. </param>
        /// <param name="upperLayer"> The Layer above this path's floor. </param>
        /// <param name="lowerLayer"> The layer below this path's floor. </param>
        /// <returns> True if there is something blocking this edge. </returns>
        private bool CheckEdgeBlocked(Vector3 begin, Vector3 end, Room r1, Room r2, Floor floor, MiddleLayer upperLayer, MiddleLayer lowerLayer)
        {
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(begin, end, this.pathWidth, out tl, out tr, out bl, out br);
            foreach (Room r in floor.Rooms)
            {
                if (r != r1 && r != r2)
                {
                    if (r.IsIntersectingLine(tl, bl))
                    {
                        return(true);
                    }

                    if (r.IsIntersectingLine(tr, br))
                    {
                        return(true);
                    }
                }
            }

            if (upperLayer != null)
            {
                foreach (LayerPath l in upperLayer.Paths)
                {
                    if (l.IsIntersectingLine(tl, bl))
                    {
                        Vector3 pos    = GenerationUtility.LineLineIntersection(tl, bl, l.Start.Position, l.End.Position);
                        bool    inRoom = IsInRoom(pos, l.Start, l.End);
                        if (!inRoom)
                        {
                            return(true);
                        }
                    }

                    if (l.IsIntersectingLine(tr, br))
                    {
                        Vector3 pos    = GenerationUtility.LineLineIntersection(tr, br, l.Start.Position, l.End.Position);
                        bool    inRoom = IsInRoom(pos, l.Start, l.End);
                        if (!inRoom)
                        {
                            return(true);
                        }
                    }
                }
            }

            if (lowerLayer != null)
            {
                foreach (LayerPath l in lowerLayer.Paths)
                {
                    if (l.IsIntersectingLine(tl, bl))
                    {
                        Vector3 pos    = GenerationUtility.LineLineIntersection(tl, bl, l.Start.Position, l.End.Position);
                        bool    inRoom = IsInRoom(pos, l.Start, l.End);
                        if (!inRoom)
                        {
                            return(true);
                        }
                    }

                    if (l.IsIntersectingLine(tr, br))
                    {
                        Vector3 pos    = GenerationUtility.LineLineIntersection(tr, br, l.Start.Position, l.End.Position);
                        bool    inRoom = IsInRoom(pos, l.Start, l.End);
                        if (!inRoom)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #27
0
        public void FillBox(Vector3 tl, Vector3 tr, Vector3 bl, Vector3 br)
        {
            if (this.Reserved)
            {
                return;
            }

            bool topLeft     = GenerationUtility.PointInBox(this.TopLeft.Position, tl, tr, bl, br);
            bool topRight    = GenerationUtility.PointInBox(this.TopRight.Position, tl, tr, bl, br);
            bool bottomLeft  = GenerationUtility.PointInBox(this.BottomLeft.Position, tl, tr, bl, br);
            bool bottomRight = GenerationUtility.PointInBox(this.BottomRight.Position, tl, tr, bl, br);

            if (topLeft)
            {
                this.TopLeft.Filled = true;
            }
            if (topRight)
            {
                this.TopRight.Filled = true;
            }
            if (bottomLeft)
            {
                this.BottomLeft.Filled = true;
            }
            if (bottomRight)
            {
                this.BottomRight.Filled = true;
            }

            if (topLeft || topRight || bottomLeft || bottomRight)
            {
                this.Filled = true;
            }

            if (!this.Filled)
            {
                return; // square is empty so work is done
            }
            if (GenerationUtility.CheckBoxLineIntersection(this.TopLeft.Position, this.TopRight.Position, tl, tr, bl, br))
            {
                this.Top.Filled = true;
                this.Top.SetPosition(
                    GenerationUtility.BoxLineIntersection(this.TopLeft.Position, this.TopRight.Position, tl, tr, bl, br));
            }

            if (GenerationUtility.CheckBoxLineIntersection(this.BottomLeft.Position, this.BottomRight.Position, tl, tr, bl, br))
            {
                this.Bottom.Filled = true;
                this.Bottom.SetPosition(
                    GenerationUtility.BoxLineIntersection(this.BottomLeft.Position, this.BottomRight.Position, tl, tr, bl, br));
            }

            if (GenerationUtility.CheckBoxLineIntersection(this.TopLeft.Position, this.BottomLeft.Position, tl, tr, bl, br))
            {
                this.Left.Filled = true;
                this.Left.SetPosition(
                    GenerationUtility.BoxLineIntersection(this.TopLeft.Position, this.BottomLeft.Position, tl, tr, bl, br));
            }

            if (GenerationUtility.CheckBoxLineIntersection(this.TopRight.Position, this.BottomRight.Position, tl, tr, bl, br))
            {
                this.Right.Filled = true;
                this.Right.SetPosition(
                    GenerationUtility.BoxLineIntersection(this.TopRight.Position, this.BottomRight.Position, tl, tr, bl, br));
            }
        }
Пример #28
0
        public void FillCircle(Vector3 center, float radius)
        {
            if (this.Reserved)
            {
                return; // don't fill reserved squares
            }
            bool topLeft     = GenerationUtility.PointInCircle(this.TopLeft.Position, center, radius);
            bool topRight    = GenerationUtility.PointInCircle(this.TopRight.Position, center, radius);
            bool bottomLeft  = GenerationUtility.PointInCircle(this.BottomLeft.Position, center, radius);
            bool bottomRight = GenerationUtility.PointInCircle(this.BottomRight.Position, center, radius);

            if (topLeft)
            {
                this.TopLeft.Filled = true;
            }
            if (topRight)
            {
                this.TopRight.Filled = true;
            }
            if (bottomLeft)
            {
                this.BottomLeft.Filled = true;
            }
            if (bottomRight)
            {
                this.BottomRight.Filled = true;
            }

            if (topLeft || topRight || bottomLeft || bottomRight)
            {
                this.Filled = true;
            }

            if (!this.Filled)
            {
                return; // square is empty so work is done
            }
            if (GenerationUtility.CheckCircleLineIntersection(this.TopLeft.Position, this.TopRight.Position, center, radius))
            {
                this.Top.Filled = true;
                this.Top.SetPosition(
                    GenerationUtility.CircleLineIntersection(this.TopLeft.Position, this.TopRight.Position, center, radius));
            }

            if (GenerationUtility.CheckCircleLineIntersection(this.BottomLeft.Position, this.BottomRight.Position, center, radius))
            {
                this.Bottom.Filled = true;
                this.Bottom.SetPosition(
                    GenerationUtility.CircleLineIntersection(this.BottomLeft.Position, this.BottomRight.Position, center, radius));
            }

            if (GenerationUtility.CheckCircleLineIntersection(this.TopLeft.Position, this.BottomLeft.Position, center, radius))
            {
                this.Left.Filled = true;
                this.Left.SetPosition(
                    GenerationUtility.CircleLineIntersection(this.TopLeft.Position, this.BottomLeft.Position, center, radius));
            }

            if (GenerationUtility.CheckCircleLineIntersection(this.TopRight.Position, this.BottomRight.Position, center, radius))
            {
                this.Right.Filled = true;
                this.Right.SetPosition(
                    GenerationUtility.CircleLineIntersection(this.TopRight.Position, this.BottomRight.Position, center, radius));
            }
        }
 public List <string> GenerateVarchar()
 {
     return(GenerationUtility.GenerateListOfRandomFromList(NumberOfRowsToGenerate, ctx.Countries.Select(c => c.Name).ToList(), true));
 }
        /// <summary> Finds all the allowed middle layer paths for the given floors. </summary>
        /// <param name="floor1"> The top floor. </param>
        /// <param name="floor2"> The bottom floor. </param>
        /// <param name="layer"> The layer to hold the paths. </param>
        public IEnumerator FindMiddleLayerPathsAsync(Floor floor1, Floor floor2, MiddleLayer layer)
        {
            foreach (Room r in floor1.Rooms)
            {
                r.GetComponent <Collider>().enabled = true;
            }

            foreach (Room r in floor2.Rooms)
            {
                r.GetComponent <Collider>().enabled = true;
            }

            List <LayerPath> paths = new List <LayerPath>();

            foreach (Room r1 in floor1.Rooms)
            {
                foreach (Room r2 in floor2.Rooms)
                {
                    LayerPath p = CompareRoom(r1, r2, floor1, floor2, this.layerPathWidth * layer.WidthScale, paths);
                    if (p != null)
                    {
                        paths.Add(p);
                    }
                }

                yield return(null);
            }

            List <LayerPath> finalPaths = new List <LayerPath>();
            int i = 0;

            while (i < this.pathsToKeep && i < paths.Count)
            {
                LayerPath path    = paths[Random.Range(0, paths.Count - 1)];
                bool      blocked = false;
                foreach (LayerPath p in finalPaths)
                {
                    if (GenerationUtility.CheckLineLineIntersection(
                            path.Start.Position,
                            path.End.Position,
                            p.Start.Position,
                            p.End.Position))
                    {
                        blocked = true;
                    }
                }

                if (!blocked)
                {
                    i++;
                    finalPaths.Add(path);
                }
            }

            layer.Paths = finalPaths;

            foreach (Room r in floor1.Rooms)
            {
                r.GetComponent <Collider>().enabled = false;
            }

            foreach (Room r in floor2.Rooms)
            {
                r.GetComponent <Collider>().enabled = false;
            }
        }