DbscanResultBuilder.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections.Generic;
  2. namespace DbscanImplementation.ResultBuilding
  3. {
  4. public class DbscanResultBuilder<TF>
  5. {
  6. public DbscanResult<TF> Result { get; private set; }
  7. public DbscanResultBuilder()
  8. {
  9. Result = new DbscanResult<TF>();
  10. }
  11. public void Process(DbscanPoint<TF> point)
  12. {
  13. if (point.ClusterId.HasValue && !Result.Clusters.ContainsKey(point.ClusterId.Value))
  14. {
  15. Result.Clusters.Add(point.ClusterId.Value, new List<DbscanPoint<TF>>());
  16. }
  17. switch (point)
  18. {
  19. case DbscanPoint<TF> core when core.PointType == PointType.Core:
  20. Result.Clusters[core.ClusterId.Value].Add(core);
  21. break;
  22. case DbscanPoint<TF> border when border.PointType == PointType.Border:
  23. Result.Clusters[border.ClusterId.Value].Add(border);
  24. break;
  25. case DbscanPoint<TF> noise when noise.PointType == PointType.Noise:
  26. Result.Noise.Add(noise);
  27. break;
  28. }
  29. }
  30. }
  31. }