/// <summary> /// Initializes a new instance of the <see cref="SweepLine" /> class. /// </summary> /// <param name="source">The source coordinates.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public SweepLine(IEnumerable <IList <Coordinate> > source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = new List <Coordinate>(); _endpoints = new List <Int32>(); foreach (IList <Coordinate> coordinateList in source) { if (coordinateList == null || coordinateList.Count < 2) { continue; } if (coordinateList.First() == coordinateList.Last()) { _endpoints.Add(_source.Count); } for (Int32 i = 0; i <= coordinateList.Count - 1; i++) { _source.Add(coordinateList[i]); } if (coordinateList.First() == coordinateList.Last()) { _endpoints.Add(_source.Count - 2); } } _tree = new SweepLineTree(precisionModel ?? PrecisionModel.Default); _coordinateComparer = new CoordinateComparer(); }
/// <summary> /// Initializes a new instance of the <see cref="SweepLine" /> class. /// </summary> /// <param name="source">The source coordinates representing a line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public SweepLine(IList <Coordinate> source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = source; _tree = new SweepLineTree(precisionModel ?? PrecisionModel.Default); _coordinateComparer = new CoordinateComparer(); if (source.Count >= 2 && source.First() == source.Last()) { _endpoints = new List <Int32> { 0, source.Count - 2 } } ; }
/// <summary> /// Initializes a new instance of the <see cref="SweepLine" /> class. /// </summary> /// <param name="source">The source coordinates representing a line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public SweepLine(IEnumerable <Coordinate> source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } this.source = new List <Coordinate>(source.Elements()); this.tree = new SweepLineTree(precisionModel ?? PrecisionModel.Default); this.coordinateComparer = new CoordinateComparer(); if (this.source.Count >= 2 && this.source[0] == this.source[this.source.Count - 1]) { this.endpoints = new List <Int32> { 0, this.source.Count - 2 } } ; }
/// <summary> /// Initializes a new instance of the <see cref="SweepLine" /> class. /// </summary> /// <param name="source">The source coordinates.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public SweepLine(IEnumerable <IEnumerable <Coordinate> > source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } List <Coordinate> sourceList = new List <Coordinate>(); this.endpoints = new List <Int32>(); foreach (IEnumerable <Coordinate> collection in source) { Int32 collectionCount = collection.Count(); if (collection == null || collectionCount < 2) { continue; } Boolean firstEqualsLast = collection.FirstElement() == collection.LastElement(); if (firstEqualsLast) { this.endpoints.Add(sourceList.Count); } sourceList.AddRange(collection.Elements()); if (firstEqualsLast) { this.endpoints.Add(sourceList.Count - 2); } } this.source = sourceList; this.tree = new SweepLineTree(precisionModel); this.coordinateComparer = new CoordinateComparer(); }