public void Draw(LevelSkeleton levelSkeleton) { if (_lineRendererGameObjects != null) { _lineRendererGameObjects.ForEach(_ => Destroy(_)); } if (_pointGameObjects != null) { _pointGameObjects.ForEach(_ => Destroy(_)); } _lineRendererGameObjects = new List <GameObject>(); _pointGameObjects = new List <GameObject>(); levelSkeleton.Lines.ToList().ForEach(_ => { var lineRendererGameObject = CreateLine(_.Points.pointA.Position, _.Points.pointB.Position); _lineRendererGameObjects.Add(lineRendererGameObject); }); levelSkeleton.Points.ToList().ForEach(_ => { var pointGameObject = CreatePoint(_); _pointGameObjects.Add(pointGameObject); }); }
// Start is called before the first frame update void Start() { var levelSkeletonGeneratorParams = new LevelSkeletonGeneratorParams(); var levelSkeletonGenerator = new LevelSkeletonGenerator(levelSkeletonGeneratorParams); _levelSkeleton = levelSkeletonGenerator.Execute(); var levelSkeletonRenderer = GetComponent <LevelSkeletonRenderer>(); levelSkeletonRenderer.Draw(_levelSkeleton); }
public static bool IsDuplicateLines(this LevelSkeleton skeleton) { return((from line in skeleton.Lines let otherLines = skeleton.Lines.Except(new List <SkeletonLine> { line }) where otherLines.Any(_ => _.ContainsSkeletonPoint(line.Points.pointA.Position) && _.ContainsSkeletonPoint(line.Points.pointB.Position)) select line) .Any()); }
public static bool IsLinesIntersects(this LevelSkeleton skeleton) { foreach (var line in skeleton.Lines) { if (skeleton.Lines.Where(_ => _ != line && !_.ContainsSkeletonPoint(line.Points.pointA) && !_.ContainsSkeletonPoint(line.Points.pointB)).Any(_ => _.FindIntersection(line).HasValue)) { return(true); } } return(false); }
public static void Draw(this LevelSkeleton skeleton) { skeleton.Lines.ToList().ForEach(_ => { Debug.DrawLine(_.Points.pointA.Position, _.Points.pointB.Position, Color.green); }); skeleton.Points.ToList().ForEach(_ => { Gizmos.color = Color.yellow; Gizmos.DrawSphere(_.Position, 0.1f); }); }
public static LevelSkeleton ToBasementSkeleton(this LevelSkeleton skeleton) { var basementSkeleton = new LevelSkeleton(); var newLines = skeleton.ToGraph().AlgorithmByPrim().Edges.ToList().Select(_ => { return(new SkeletonLine(_.Vertexes.ToList()[0].Data, _.Vertexes.ToList()[1].Data, new EntityType(Color.blue, "Basement"))); }); basementSkeleton.AddLines(newLines); return(basementSkeleton); }
public static Graph <SkeletonPoint> ToGraph(this LevelSkeleton skeleton) { var vertexDictionary = new Dictionary <string, Vertex <SkeletonPoint> >(); skeleton.Points.ToList().ForEach(_ => { vertexDictionary.Add(_.Id, new Vertex <SkeletonPoint>(_)); }); var edges = skeleton.Lines.Select(_ => new Edge <SkeletonPoint>(vertexDictionary[_.Points.pointA.Id], vertexDictionary[_.Points.pointB.Id], _.Length)); return(new Graph <SkeletonPoint>(vertexDictionary.Values.ToList(), edges)); }
public void Draw(LevelSkeleton levelSkeleton) { Clear(); _lineRendererGameObjects = new List <GameObject>(); _pointGameObjects = new List <GameObject>(); levelSkeleton.Lines.ToList().ForEach(_ => { var lineRendererGameObject = CreateLine(_.Points.pointA.Position, _.Points.pointB.Position, _.Type, _.Id); _lineRendererGameObjects.Add(lineRendererGameObject); }); levelSkeleton.Points.ToList().ForEach(_ => { var pointGameObject = CreatePoint(_, _.Id); _pointGameObjects.Add(pointGameObject); }); }
public static List <List <SkeletonLine> > GetCycles(this LevelSkeleton skeleton) { var cycles = new List <List <SkeletonLine> >(); var graphCycles = skeleton.ToGraph().GetCycles(); foreach (var graphCycle in graphCycles) { var cycle = new List <SkeletonLine>(); graphCycle.ForEach(edge => cycle.Add(skeleton.Lines.First(_ => _.ContainsSkeletonPoint(edge.VertexA.Data) && _.ContainsSkeletonPoint(edge.VertexB.Data)))); if (!cycles.Any(_ => _.IsCycleEquals(cycle))) { cycles.Add(cycle); } } return(cycles); }
public static LevelSkeleton ToTriangleSkeleton(this LevelSkeleton skeleton) { var fullSkeleton = new LevelSkeleton(); fullSkeleton.AddLines(skeleton.Lines); var linesToRemove = new List <SkeletonLine>(); var isFirst = true; while (isFirst || linesToRemove.Count > 0) { isFirst = false; linesToRemove = new List <SkeletonLine>(); var lines = fullSkeleton.Lines.OrderBy(_ => _.Length).ToList(); foreach (var line in lines) { var l = fullSkeleton.Lines.Except(new[] { line }) .Except(linesToRemove) .Where(_ => _.FindIntersection(line) != null && _.Length > line.Length) .ToList(); if (l.Count > 0) { l = l.OrderBy(_ => _.Length).ToList(); linesToRemove.Add(l.Last()); break; } linesToRemove.AddRange(l.Except(linesToRemove)); } if (linesToRemove.Count > 0) { fullSkeleton.RemoveLines(linesToRemove); } } fullSkeleton.SetLineType(new EntityType(Color.red, "Additional")); return(fullSkeleton); }