Index: src/Common/NetTopologySuite/Algorithm/CentroidLine.cs
===================================================================
diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a
--- src/Common/NetTopologySuite/Algorithm/CentroidLine.cs (.../CentroidLine.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9)
+++ src/Common/NetTopologySuite/Algorithm/CentroidLine.cs (.../CentroidLine.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a)
@@ -11,46 +11,50 @@
///
public class CentroidLine
{
- private ICoordinate centSum = new Coordinate();
+ private readonly ICoordinate centSum = new Coordinate();
private double totalLength = 0.0;
///
///
///
- public CentroidLine() { }
+ public CentroidLine() {}
+ ///
+ ///
+ ///
+ public ICoordinate Centroid
+ {
+ get
+ {
+ ICoordinate cent = new Coordinate();
+ cent.X = centSum.X/totalLength;
+ cent.Y = centSum.Y/totalLength;
+ return cent;
+ }
+ }
+
///
/// Adds the linestring(s) defined by a Geometry to the centroid total.
/// If the point is not linear it does not contribute to the centroid.
///
/// The point to add.
public void Add(IGeometry geom)
{
- if (geom is ILineString)
- Add(geom.Coordinates);
+ if (geom is ILineString)
+ {
+ Add(geom.Coordinates);
+ }
- else if (geom is IGeometryCollection)
+ else if (geom is IGeometryCollection)
{
IGeometryCollection gc = (IGeometryCollection) geom;
foreach (IGeometry geometry in gc.Geometries)
+ {
Add(geometry);
+ }
}
}
- ///
- ///
- ///
- public ICoordinate Centroid
- {
- get
- {
- ICoordinate cent = new Coordinate();
- cent.X = centSum.X / totalLength;
- cent.Y = centSum.Y / totalLength;
- return cent;
- }
- }
-
///
/// Adds the length defined by an array of coordinates.
///
@@ -62,11 +66,11 @@
double segmentLen = pts[i].Distance(pts[i + 1]);
totalLength += segmentLen;
- double midx = (pts[i].X + pts[i + 1].X) / 2;
- centSum.X += segmentLen * midx;
- double midy = (pts[i].Y + pts[i + 1].Y) / 2;
- centSum.Y += segmentLen * midy;
+ double midx = (pts[i].X + pts[i + 1].X)/2;
+ centSum.X += segmentLen*midx;
+ double midy = (pts[i].Y + pts[i + 1].Y)/2;
+ centSum.Y += segmentLen*midy;
}
}
}
-}
+}
\ No newline at end of file