in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/shape/TriangleSampler.java [333:359]
public static TriangleSampler of(UniformRandomProvider rng,
double[] a,
double[] b,
double[] c) {
final int dimension = a.length;
if (dimension != b.length || dimension != c.length) {
throw new IllegalArgumentException(
new StringBuilder("Mismatch of vertex dimensions: ").append(dimension).append(',')
.append(b.length).append(',')
.append(c.length).toString());
}
// Detect non-finite vertices
Coordinates.requireFinite(a, "Vertex a");
Coordinates.requireFinite(b, "Vertex b");
Coordinates.requireFinite(c, "Vertex c");
// Low dimension specialisations
if (dimension == TWO_D) {
return new TriangleSampler2D(rng, a, b, c);
} else if (dimension == THREE_D) {
return new TriangleSampler3D(rng, a, b, c);
} else if (dimension > THREE_D) {
return new TriangleSamplerND(rng, a, b, c);
}
// Less than 2D
throw new IllegalArgumentException(
"Unsupported dimension: " + dimension);
}