Skip to content

Commit

Permalink
Adding, correcting code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
FObermaier committed Feb 16, 2018
1 parent 0cb2d84 commit 66c2f93
Show file tree
Hide file tree
Showing 39 changed files with 297 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public string Type

public long Id { get; set; }

public IAttributesTable Properties { get; set; }
public IAttributesTable Properties { get; set; }

/// <inheritdoc cref="object.ToString()"/>
public override string ToString()
{
return string.Format("Type: {0}", Type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public double[] Translate
get { return _translate; }
}

/// <inheritdoc cref="object.ToString()"/>
public override string ToString()
{
return string.Format("Scale: {0}, Translate: {1}", Scale, Translate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private enum IsNoDataCheck
private readonly IsNoDataCheck _isNoDataCheck;

/// <summary>
/// Initializes this stucture with a <paramref name="noDataValue"/>
/// Initializes this structure with a <paramref name="noDataValue"/>
/// </summary>
/// <param name="noDataValue">The value that is to be treated as <c>null</c></param>
/// <param name="lessThan">This optional parameter controls whether a value has to be less than <paramref name="noDataValue"/> to be considered <c>null</c></param>
Expand Down Expand Up @@ -184,19 +184,19 @@ public CoordinateBuffer(double nullValue, bool lessThan = false)
}

/// <summary>
/// Creates an instance of this class with an inital <paramref name="capacity"/>
/// Creates an instance of this class with an initial <paramref name="capacity"/>
/// </summary>
/// <param name="capacity">The inital capacity of the buffer.</param>
/// <param name="capacity">The initial capacity of the buffer.</param>
public CoordinateBuffer(int capacity)
{
_coordinates = new List<double[]>(capacity);
_doubleNoDataChecker = new DoubleNoDataChecker(double.NaN);
}

/// <summary>
/// Creates an instance of this class with an inital <paramref name="capacity"/>
/// Creates an instance of this class with an initial <paramref name="capacity"/>
/// </summary>
/// <param name="capacity">The inital capacity of the buffer.</param>
/// <param name="capacity">The initial capacity of the buffer.</param>
/// <param name="nullValue">The value that should be treated as null.</param>
/// <param name="lessThan">This optional parameter controls whether a value has to be less than <paramref name="nullValue"/> to be considered <c>null</c></param>
public CoordinateBuffer(int capacity, double nullValue, bool lessThan = false)
Expand Down Expand Up @@ -304,7 +304,7 @@ public int Capacity
/// <param name="y">The y-Ordinate</param>
/// <param name="z">The (optional) z-Ordinate</param>
/// <param name="m">The (optional) m-Ordinate</param>
/// <param name="allowRepeated">Allows repated coordinates to be added</param>
/// <param name="allowRepeated">Allows repeated coordinates to be added</param>
/// <returns><value>true</value> if the coordinate was successfully added.</returns>
public bool AddCoordinate(double x, double y, double? z = null, double? m = null, bool allowRepeated = true)
{
Expand Down Expand Up @@ -354,7 +354,7 @@ public void AddMarker()
/// <param name="y">The y-Ordinate</param>
/// <param name="z">The (optional) z-Ordinate</param>
/// <param name="m">The (optional) m-Ordinate</param>
/// <param name="allowRepeated">Allows repated coordinates to be added</param>
/// <param name="allowRepeated">Allows repeated coordinates to be added</param>
/// <returns><value>true</value> if the coordinate was successfully inserted.</returns>
public bool InsertCoordinate(int index, double x, double y, double? z = null, double? m = null, bool allowRepeated = true)
{
Expand Down Expand Up @@ -406,7 +406,7 @@ public void Clear()
}

/// <summary>
/// Convertes the contents of the buffer to an array of <see cref="Coordinate"/>s
/// Converts the contents of the buffer to an array of <see cref="Coordinate"/>s
/// </summary>
/// <returns>An array of <see cref="Coordinate"/>s</returns>
public Coordinate[] ToCoordinateArray()
Expand Down Expand Up @@ -475,7 +475,7 @@ public ICoordinateSequence[] ToSequences(ICoordinateSequenceFactory factory = nu
if (factory == null)
factory = _factory ?? (_factory = GeometryServiceProvider.Instance.DefaultCoordinateSequenceFactory);

// Copy the markers, append if neccessary
// Copy the markers, append if necessary
var markers = new List<int>(_markers);
if (markers.Count == 0 || markers[markers.Count-1] < _coordinates.Count)
markers.Add(_coordinates.Count);
Expand All @@ -492,7 +492,7 @@ public ICoordinateSequence[] ToSequences(ICoordinateSequenceFactory factory = nu
// compute the length of the current sequence
var length = markers[s] - offset;

// create a sequence of the apropriate size
// create a sequence of the appropriate size
var sequence = res[s] = factory.Create(length, useOrdinates);
var i = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ByteStreamProvider(string kind, string text, Encoding encoding)
/// </summary>
/// <param name="kind">The kind of stream</param>
/// <param name="stream">The stream</param>
/// <param name="isReadonly">A value indicating whether the contents are readonly</param>
/// <param name="isReadonly">A value indicating whether the contents are read-only</param>
public ByteStreamProvider(string kind, Stream stream, bool isReadonly = false)
:this(kind, ReadFully(stream), -1, isReadonly)
{
Expand All @@ -66,7 +66,7 @@ public ByteStreamProvider(string kind, Stream stream, bool isReadonly = false)
/// <param name="kind">The kind of stream</param>
/// <param name="bytes">The array of bytes</param>
/// <param name="maxLength">The maximum length of the</param>
/// <param name="isReadonly">A value indicating whether the contents are readonly</param>
/// <param name="isReadonly">A value indicating whether the contents are read-only</param>
public ByteStreamProvider(string kind, byte[] bytes, int maxLength = -1, bool isReadonly = false)
{
Kind = kind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public double M
get { return _m; }
set { _m = value; }
}


/// <inheritdoc cref="object.ToString()"/>
public override string ToString()
{
string stringRep = X + " " + Y + " m=" + M;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NetTopologySuite.Geometries;
using NetTopologySuite.Algorithm.Match;
using NetTopologySuite.Geometries;
using NetTopologySuite.Tests.NUnit;
using NUnit.Framework;

Expand Down Expand Up @@ -26,10 +27,20 @@ public void TestRobust()
private void CheckOctagonalEnvelope(string wkt, string wktExpected)
{
var input = Read(wkt);
if (!input.IsValid) throw new IgnoreException("input geometry not valid");
var expected = Read(wktExpected);
if (!expected.IsValid) throw new IgnoreException("expected geometry not valid");

var octEnv = OctagonalEnvelope.GetOctagonalEnvelope(input);
var isEqual = octEnv.EqualsNormalized(expected);
Assert.IsTrue(isEqual);

var hsmDiff = 1d;
if (!isEqual)
{
var hsm = new HausdorffSimilarityMeasure();
hsmDiff = hsm.Measure(octEnv, expected);
}
Assert.IsTrue(isEqual, $"Failed, Hausdorff Similarity Measure value = {hsmDiff:R}.");
}
}
}
166 changes: 166 additions & 0 deletions NetTopologySuite.Samples.Console/Tests/StackOverflow/MakeValid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using GeoAPI.Geometries;
using NetTopologySuite.Algorithm.Match;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries.Utilities;
using NetTopologySuite.IO;
using NetTopologySuite.Noding;
using NetTopologySuite.Operation.Buffer;
using NetTopologySuite.Operation.Polygonize;
using NUnit.Framework;

namespace NetTopologySuite.Samples.Tests.StackOverflow
{
[System.ComponentModel.Category("Technique")]
public class MakeValid
{
private const string Wkt =
"MULTIPOLYGON(((6.8016626382085361 52.715309958659567, 6.8016978566354931 52.715300551948957, "+
"6.8015610818087193 52.715189826862179, 6.8014185055170415 52.715082765798371, "+
"6.8011385751008762 52.714892848902714, 6.80060419093019 52.714522597434573, "+
"6.7999630427768381 52.714053843670676, 6.7997671025094686 52.713897979848007, "+
"6.7995041016726177 52.713681792796635, 6.8008707444707825 52.71273529869638, "+
"6.8018179126154372 52.713377474968908, 6.8019432523746257 52.713500919031091, "+
"6.8019712703624577 52.71358956783984, 6.8019625919554079 52.713687641028628, "+
"6.801900320844819 52.714051499553385, 6.8018106242715941 52.714620612080388, "+
"6.801752965346215 52.714943969273726, 6.8016626382085361 52.715309958659567)))";

[Test, Ignore("Known to fail")]
public void TestBuffer0()
{
var rdr = new WKTReader();
var geom = rdr.Read(Wkt);
Assert.That(geom, Is.Not.Null);
Assert.That(geom.IsValid, Is.False);

var fixedGeom = geom.Normalized().Buffer(0);
Assert.That(fixedGeom, Is.Not.Null);
var hsm = new HausdorffSimilarityMeasure();
Assert.That(hsm.Measure(fixedGeom, geom), Is.GreaterThan(0.9));
}

[Test]
public void TestValidate()
{
var rdr = new WKTReader();
var geom = rdr.Read(Wkt);
Assert.That(geom, Is.Not.Null);
Assert.That(geom.IsValid, Is.False);

var fixedGeom = geom.Validate();
Assert.That(fixedGeom, Is.Not.Null);
var hsm = new HausdorffSimilarityMeasure();
var m1 = hsm.Measure(fixedGeom, geom);
var m2 = hsm.Measure(geom, fixedGeom);
Assert.That(m1, Is.GreaterThan(0.9));
}
}

/// <summary>
/// Extension method to validate polygons
/// </summary>
internal static class ValidateGeometryExtension
{
/// <summary>
/// Get or create a valid version of the geometry given. If the geometry is a
/// polygon or multi polygon, self intersections or inconsistencies are fixed.
/// Otherwise the geometry is returned.
/// </summary>
/// <param name="geom">The geometry to be fixed</param>
/// <returns>The fixed geometry</returns>
public static IGeometry Validate(this IGeometry geom)
{
if (geom is IPolygon)
{
if (geom.IsValid)
{
geom.Normalize(); // validate does not pick up rings in the wrong order - this will fix that
return geom; // If the polygon is valid just return it
}
var polygonizer = new Polygonizer();
AddPolygon((IPolygon)geom, polygonizer);
return ToPolygonGeometry(polygonizer.GetPolygons(), geom.Factory);
}

if (geom is IMultiPolygon)
{
if (geom.IsValid)
{
geom.Normalize(); // validate does not pick up rings in the wrong order - this will fix that
return geom; // If the multipolygon is valid just return it
}
var polygonizer = new Polygonizer();
for (int n = geom.NumGeometries; n-- > 0;)
{
AddPolygon((IPolygon)geom.GetGeometryN(n), polygonizer);
}
return ToPolygonGeometry(polygonizer.GetPolygons(), geom.Factory);
}

// ToDo other validations

// Only care about polygons
return geom;
}

/// <summary>
/// Add all line strings from the polygon given to the polygonizer given
/// </summary>
/// <param name="polygon">The polygon from which to extract the line strings</param>
/// <param name="polygonizer">The polygonizer</param>
static void AddPolygon(IPolygon polygon, Polygonizer polygonizer)
{
AddLineString(polygon.ExteriorRing, polygonizer);
for (var n = polygon.NumInteriorRings; n-- > 0;)
{
AddLineString(polygon.GetInteriorRingN(n), polygonizer);
}
}

/// <summary>
/// Add the linestring given to the polygonizer
/// </summary>
/// <param name="lineString">The line string</param>
/// <param name="polygonizer">The polygonizer</param>
static void AddLineString(ILineString lineString, Polygonizer polygonizer)
{
if (lineString is ILinearRing)
{ // LinearRings are treated differently to line strings : we need a LineString NOT a LinearRing
lineString = lineString.Factory.CreateLineString(lineString.CoordinateSequence);
}

// unioning the linestring with the point makes any self intersections explicit.
var point = lineString.Factory.CreatePoint(lineString.GetCoordinateN(0));
var toAdd = lineString.Union(point);

//Add result to polygonizer
polygonizer.Add(toAdd);
}


/// <summary>
/// Get a geometry from a collection of polygons.
/// </summary>
/// <param name="polygons"></param>
/// <param name="factory">Factory to create <see cref="IMultiPolygon"/>s</param>
/// <returns><c>null</c> if there were no polygons, the polygon if there was only one, or a MultiPolygon containing all polygons otherwise</returns>
static IGeometry ToPolygonGeometry(ICollection<IGeometry> polygons, IGeometryFactory factory)
{
switch (polygons.Count)
{
case 0:
return null; // No valid polygons!
case 1:
return polygons.First(); // single polygon - no need to wrap
default:
//polygons may still overlap! Need to sym difference them
IGeometry ret = (IPolygon)polygons.First().Clone();
foreach (var polygon in polygons.Skip(1))
ret = ret.SymmetricDifference(polygon);
return ret;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NonRobustLineIntersectorTest
//MD suggests we ignore this issue for now.
// li.computeIntersection(new Coordinate(220, 260), new Coordinate(220, 0),
// new Coordinate(220, 0), new Coordinate(100, 0));
// assertEquals((new Coordinate(220, 0)).toString(), li.getIntersection(0).toString());
// assertEquals((new Coordinate(220, 0)).ToString(), li.getIntersection(0).ToString());
}
[TestAttribute]
[IgnoreAttribute("The JTS testGetIntersectionNum test was being ignored")]
Expand Down
10 changes: 5 additions & 5 deletions NetTopologySuite.Tests.NUnit/Index/Strtree/STRtreeDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public TestTree(int nodeCapacity)
{
}

public IList<IBoundable<Envelope, object>> BoundablesAtLevel(int level) { return base.BoundablesAtLevel(level); }
public new IList<IBoundable<Envelope, object>> BoundablesAtLevel(int level) { return base.BoundablesAtLevel(level); }

public AbstractNode<Envelope, object> Root { get { return base.Root; } }
public new AbstractNode<Envelope, object> Root { get { return base.Root; } }

public IList<IBoundable<Envelope, object>> CreateParentBoundables(IList<IBoundable<Envelope, object>> verticalSlice, int newLevel)
public new IList<IBoundable<Envelope, object>> CreateParentBoundables(IList<IBoundable<Envelope, object>> verticalSlice, int newLevel)
{
return base.CreateParentBoundables(verticalSlice, newLevel);
}
public IList<IBoundable<Envelope, object>>[] VerticalSlices(IList<IBoundable<Envelope, object>> childBoundables, int size)
public new IList<IBoundable<Envelope, object>>[] VerticalSlices(IList<IBoundable<Envelope, object>> childBoundables, int size)
{
return base.VerticalSlices(childBoundables, size);
}
public IList<IBoundable<Envelope, object>> CreateParentBoundablesFromVerticalSlice(IList<IBoundable<Envelope, object>> childBoundables, int newLevel)
public new IList<IBoundable<Envelope, object>> CreateParentBoundablesFromVerticalSlice(IList<IBoundable<Envelope, object>> childBoundables, int newLevel)
{
return base.CreateParentBoundablesFromVerticalSlice(childBoundables, newLevel);
}
Expand Down
4 changes: 2 additions & 2 deletions NetTopologySuite.Tests.NUnit/Index/Strtree/STRtreeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ private class TestTree : STRtree
{
public TestTree(int nodeCapacity) : base(nodeCapacity) { }

public AbstractNode Root()
public new AbstractNode Root()
{
return base.Root;
}

public IList<IBoundable<Envelope, object>> BoundablesAtLevel(int level)
public new IList<IBoundable<Envelope, object>> BoundablesAtLevel(int level)
{
return base.BoundablesAtLevel(level);
}
Expand Down
2 changes: 1 addition & 1 deletion NetTopologySuite.Tests.NUnit/Mathematics/DDIOTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void TestRepeatedSqrt()
}

/// <summary>
/// This routine simply tests for robustness of the toString function.
/// This routine simply tests for robustness of the ToString function.
/// </summary>
private static void WriteRepeatedSqrt(DD xdd)
{
Expand Down
9 changes: 9 additions & 0 deletions NetTopologySuite/Algorithm/Angle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ public enum Orientation
/// </summary>
public static class AngleUtility
{
/// <summary>
/// Value of 2 * Pi
/// </summary>
public const double PiTimes2 = 2.0 * System.Math.PI;
/// <summary>
/// Value of Pi / 2
/// </summary>
public const double PiOver2 = System.Math.PI / 2.0;
/// <summary>
/// Value of Pi / 4
/// </summary>
public const double PiOver4 = System.Math.PI / 4.0;

///<summary>
Expand Down

0 comments on commit 66c2f93

Please sign in to comment.