Skip to content

Commit b1d9201

Browse files
committed
Now that random generation is user-exposed, have better exception for invalid sites
1 parent b2f9980 commit b1d9201

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace SharpVoronoiLib.Exceptions;
2+
3+
public class VoronoiRandomPointGenerationEncounteredTooManyInvalidSites()
4+
: NullReferenceException("While generating random points for sites, the algorithm encountered too many invalid site points. " +
5+
"This is likely an issue with the random point generation algorithm.");

SharpVoronoiLib/Point Generation/RandomPointGeneration.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SharpVoronoiLib;
1+
using SharpVoronoiLib.Exceptions;
2+
3+
namespace SharpVoronoiLib;
24

35
internal abstract class RandomPointGeneration : IPointGenerationAlgorithm
46
{
@@ -28,14 +30,14 @@ public List<VoronoiSite> Generate(double minX, double minY, double maxX, double
2830
{
2931
i--;
3032
failSafetyCounter--;
31-
if (failSafetyCounter == 0) throw new Exception("Too many invalid points generated");
33+
if (failSafetyCounter == 0) throw new VoronoiRandomPointGenerationEncounteredTooManyInvalidSites();
3234
continue;
3335
}
3436

3537
if (!sites.Add(site))
3638
{
3739
failSafetyCounter--;
38-
if (failSafetyCounter == 0) throw new Exception("Too many invalid points generated");
40+
if (failSafetyCounter == 0) throw new VoronoiRandomPointGenerationEncounteredTooManyInvalidSites();
3941
i--;
4042
}
4143
}

0 commit comments

Comments
 (0)