Index: src/Common/NetTopologySuite/Algorithm/CentroidPoint.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Algorithm/CentroidPoint.cs (.../CentroidPoint.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Algorithm/CentroidPoint.cs (.../CentroidPoint.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -11,28 +11,46 @@ public class CentroidPoint { private int ptCount = 0; - private ICoordinate centSum = new Coordinate(); + private readonly ICoordinate centSum = new Coordinate(); /// /// /// - public CentroidPoint() { } + public CentroidPoint() {} + /// + /// + /// + public ICoordinate Centroid + { + get + { + ICoordinate cent = new Coordinate(); + cent.X = centSum.X/ptCount; + cent.Y = centSum.Y/ptCount; + return cent; + } + } + /// /// Adds the point(s) defined by a Geometry to the centroid total. /// If the point is not of dimension 0 it does not contribute to the centroid. /// /// The point to add. public void Add(IGeometry geom) { - if (geom is IPoint) + if (geom is IPoint) + { Add(geom.Coordinate); + } - else if(geom is IGeometryCollection) + else if (geom is IGeometryCollection) { IGeometryCollection gc = (IGeometryCollection) geom; foreach (IGeometry geometry in gc.Geometries) + { Add(geometry); + } } } @@ -46,19 +64,5 @@ centSum.X += pt.X; centSum.Y += pt.Y; } - - /// - /// - /// - public ICoordinate Centroid - { - get - { - ICoordinate cent = new Coordinate(); - cent.X = centSum.X / ptCount; - cent.Y = centSum.Y / ptCount; - return cent; - } - } - } -} + } +} \ No newline at end of file