public Triangle FindFriend(Vector point) { var rayEngine = new RayEngine(); Segment segment = null; var ray = new Ray(CircleCenter, point); foreach (var edge in Polymer.ToSegments()) { if (rayEngine.TryFindCrossingPoint(ray, edge, out Vector foo)) { segment = edge; break; } } if (segment != null) { var triangle = Neighbours.First(n => n.Polymer.ToSegments().Any(y => y == segment)); if (triangle.Polymer.ContainsPoint(point)) { return(triangle); } else { return(triangle.FindFriend(point)); } } else { return(null); } }
public Triangulation(IHardenedPolymer polymer) : this() { IHardenedPolymer hull = MakeHull(polymer); FillOuterHull(hull); IHardenedPolymer innerPoints = new Polymer(polymer.Except(hull)); #warning Add inner points here. FillInnerPoints(innerPoints); throw new NotImplementedException(); }
private (Triangle C, Triangle D) Flip(Triangle A, Triangle B) { var mutual = A.Polymer.Intersect(B.Polymer).ToList(); if (mutual.Count != 2) { throw new Exception("This triangles don't constitute quadrilateral!"); } var union = A.Polymer.Union(B.Polymer).ToList(); #warning Мы изменяем лист по которому проходим Vector m0 = mutual[0]; Vector m1 = mutual[1]; var c = new Polymer(union.Except(new[] { m0 })); var d = new Polymer(union.Except(new[] { m1 })); var C = new Triangle(c); var D = new Triangle(d); // До сюда все ОК. // Убрать старые triangles.Add(C); triangles.Add(D); // Добавить новые triangles.Remove(A); triangles.Remove(B); // Добавить новым соседей var allNeighbours = A.Neighbours.Union(B.Neighbours).Except(new[] { A, B }).ToList(); List <Triangle> findNeighbours(Func <Vector, bool> func) => allNeighbours.Where(n => n.Polymer.Any(func)).ToList(); C.Neighbours = findNeighbours(p => p == m1); D.Neighbours = findNeighbours(p => p == m0); // Обработать соседей void handleNeighbours(Triangle @base, Triangle toAdd) { @base.Neighbours.Remove(A); @base.Neighbours.Remove(B); @base.Neighbours.Add(toAdd); } C.Neighbours.ForEach(x => handleNeighbours(x, C)); D.Neighbours.ForEach(x => handleNeighbours(x, D)); // Добавить C к D и D к C C.Neighbours.Add(D); D.Neighbours.Add(C); return(C, D); }
public bool Equals(Triangle triangle) { foreach (var node in triangle.Polymer) { if (!Polymer.Contains(node)) { return(false); } } foreach (var node in Polymer) { if (!triangle.Polymer.Contains(node)) { return(false); } } return(true); }
private Triangulation() { cache = new Triangle[cacheSize, cacheSize]; triangles = new List <Triangle>(); points = new Polymer(); }
public override string ToString() { return(string.Join("; ", Polymer.Select(x => x.ToString()))); }