bool ContainedInCoreCrvs(SmSlivers sliver, List <Polygon> corePolys) { bool contained = false; if (corePolys != null && corePolys.Count > 0) { for (int c = 0; c < corePolys.Count; c++) { if (corePolys[c].Contains(sliver._poly.Centroid())) { return(true); } } } return(contained); }
public void InitSubSpaces(double _seamFactor, IList <Polygon> corePolys) { _SubSpaces = new Polygon[_Walls.Length]; semiSlivers = new List <Polygon>(); indecesforPurgin = new List <int>(); int pIntOffset = 0; double crvLength = 0.0; List <Line> splitLines = new List <Line>(); Line ln; //creation of new zones for (int w = 0; w < _Walls.Length; w++) { crvLength = _Walls[w]._curve.Length(); var numSlivers = (int)Math.Floor(crvLength / _SplitInterval); ln = new Line(_Walls[w]._curve.PointAt(0.0), _Walls[w]._curve.PointAt(1.0)); splitLines = ln.DivideByLength(numSlivers, false); var crossDir = Vector3.ZAxis; if (_Walls[w]._flipped == true) { crossDir *= -1.0; } var diagPoint = ln.Start + _Walls[w]._direction.Cross(crossDir).Unitized() * _leaseOffset + (ln.End - ln.Start); var p = Polygon.Rectangle(ln.Start, diagPoint); _SubSpaces[w] = p; } var otherSubSpaces = new Polygon[_Walls.Length]; for (int i = 0; i < _SubSpaces.Length; i++) { Polygon resultingPoly = null; Polygon[] offsets = new Polygon[1]; if (i == 0) { offsets[0] = _SubSpaces[_SubSpaces.Length - 1]; var splitters = _SubSpaces[i].Difference(offsets); if (splitters != null) { if (splitters.Count == 2) { resultingPoly = splitters[1]; } else { resultingPoly = splitters[0]; } otherSubSpaces[i] = resultingPoly; } } else { offsets[0] = _SubSpaces[i - 1]; var splitters = _SubSpaces[i].Difference(offsets); if (splitters != null) { if (splitters.Count == 2) { resultingPoly = splitters[1]; } else { resultingPoly = splitters[0]; } otherSubSpaces[i] = resultingPoly; } } } _SubSpaces = otherSubSpaces; var tempWalls = new SmWall[_Walls.Length]; for (int w = 0; w < _Walls.Length; w++) { var newWallSeg = AlignWallPlease(_SubSpaces[w], _Walls[w]); tempWalls[w] = new SmWall(w, newWallSeg); if (_Walls[w]._flipped) { tempWalls[w]._flipped = true; } tempWalls[w]._direction = _Walls[w]._direction; tempWalls[w]._normalDir = _Walls[w]._normalDir; } _Walls = tempWalls; _Slivers = new List <SmSlivers> [_SubSpaces.Length]; //creation of SLIVERS int counter = 0; for (int w = 0; w < _Walls.Length; w++) { ln = new Line(_Walls[w]._curve.PointAt(0.0), _Walls[w]._curve.PointAt(1.0)); splitLines = ln.DivideByLength(_SplitInterval, false); var tempList = new List <SmSlivers>(); for (int i = 0; i < splitLines.Count; i++) { var crossDir = Vector3.ZAxis; if (_Walls[w]._flipped == true) { crossDir *= -1.0; } var diagPoint = splitLines[i].Start + _Walls[w]._direction.Cross(crossDir).Unitized() * _leaseOffset + (splitLines[i].End - splitLines[i].Start); var p = Polygon.Rectangle(splitLines[i].Start, diagPoint); if (_SubSpaces[counter].Contains(p.Centroid())) { tempList.Add(new SmSlivers(i, p)); } } _Slivers[counter] = tempList; counter++; } for (int j = 0; j < _Slivers.Length; j++) { var PIndexes = new List <int>(); var sortedFaces = _Slivers[j].ToList(); for (int s = 0; s < sortedFaces.Count; s++) { if (ContainedInCoreCrvs(sortedFaces[s], coreCrvs)) { sortedFaces.RemoveAt(s); s--; } } var sfCount = sortedFaces.Count; for (int s = 6; s >= 0; s--) { var subIndex = sfCount - s; var subModIndex = pIntOffset + subIndex; if (!PIndexes.Contains(subModIndex)) { PIndexes.Add(subModIndex); } } semiSlivers.AddRange(sortedFaces.OrderBy(s => s._stIndex).Select(s => s._poly)); indecesforPurgin.AddRange(PIndexes); pIntOffset += sfCount; } //Init smart slivers _smSubSpaces = new SmSlivers[semiSlivers.Count]; for (int g = 0; g < _smSubSpaces.Length; g++) { _smSubSpaces[g] = new SmSlivers(g, semiSlivers[g]); } int modIndex = 0; int indexOffset = (int)(_seamFactor * (semiSlivers.Count)); var modSubSpaces = new Polygon[semiSlivers.Count]; var lastIndexContainer = new List <int>(); for (int i = 0; i < semiSlivers.Count; i++) { modIndex = (i + indexOffset) % semiSlivers.Count; modSubSpaces[i] = semiSlivers[modIndex]; _smSubSpaces[i]._shiftIndex = modIndex; } semiSlivers = modSubSpaces.ToList(); }