Add RandomSource to Configuration class (closes #19).
This commit is contained in:
@@ -48,7 +48,8 @@ namespace TriangleNet.Examples
|
||||
var config = new Configuration()
|
||||
{
|
||||
Predicates = () => predicates,
|
||||
TrianglePool = () => pool.Restart()
|
||||
TrianglePool = () => pool.Restart(),
|
||||
RandomSource = () => Random.Shared
|
||||
};
|
||||
|
||||
var triangulator = new Dwyer();
|
||||
@@ -118,7 +119,8 @@ namespace TriangleNet.Examples
|
||||
var config = new Configuration()
|
||||
{
|
||||
Predicates = () => predicates,
|
||||
TrianglePool = () => pool.Restart()
|
||||
TrianglePool = () => pool.Restart(),
|
||||
RandomSource = () => Random.Shared
|
||||
};
|
||||
|
||||
var mesher = new GenericMesher(config);
|
||||
|
||||
@@ -34,11 +34,12 @@ namespace TriangleNet
|
||||
/// Initializes a new instance of the <see cref="Configuration" /> class.
|
||||
/// </summary>
|
||||
/// <param name="predicates">Factory method for <see cref="IPredicates" />.</param>
|
||||
/// <param name="trianglePool">Factory method for <see cref="TrianglePool" />.</param>
|
||||
/// <param name="trianglePool">Factory method for <see cref="TriangleNet.TrianglePool" />.</param>
|
||||
public Configuration(Func<IPredicates> predicates, Func<TrianglePool> trianglePool)
|
||||
{
|
||||
Predicates = predicates;
|
||||
TrianglePool = trianglePool;
|
||||
RandomSource = () => new Random();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,8 +48,13 @@ namespace TriangleNet
|
||||
public Func<IPredicates> Predicates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the factory method for the <see cref="TrianglePool"/>.
|
||||
/// Gets or sets the factory method for the <see cref="TriangleNet.TrianglePool"/>.
|
||||
/// </summary>
|
||||
public Func<TrianglePool> TrianglePool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the factory method for a <see cref="Random"/> source.
|
||||
/// </summary>
|
||||
public Func<Random> RandomSource { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace TriangleNet
|
||||
|
||||
predicates = config.Predicates();
|
||||
|
||||
locator = new TriangleLocator(this, predicates);
|
||||
locator = new TriangleLocator(this, predicates, config.RandomSource());
|
||||
|
||||
TransferNodes(points);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace TriangleNet
|
||||
{
|
||||
using System;
|
||||
using TriangleNet.Geometry;
|
||||
using TriangleNet.Topology;
|
||||
|
||||
@@ -24,35 +25,26 @@ namespace TriangleNet
|
||||
/// </remarks>
|
||||
public class TriangleLocator
|
||||
{
|
||||
TriangleSampler sampler;
|
||||
Mesh mesh;
|
||||
|
||||
IPredicates predicates;
|
||||
private readonly TriangleSampler sampler;
|
||||
private readonly Mesh mesh;
|
||||
private readonly IPredicates predicates;
|
||||
|
||||
// Pointer to a recently visited triangle. Improves point location if
|
||||
// proximate vertices are inserted sequentially.
|
||||
internal Otri recenttri;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TriangleLocator" /> class.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
public TriangleLocator(Mesh mesh)
|
||||
: this(mesh, RobustPredicates.Default)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TriangleLocator" /> class.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
/// <param name="predicates">The predicates.</param>
|
||||
public TriangleLocator(Mesh mesh, IPredicates predicates)
|
||||
/// <param name="random">The random source used in <see cref="TriangleSampler" />.</param>
|
||||
public TriangleLocator(Mesh mesh, IPredicates predicates, Random random)
|
||||
{
|
||||
this.mesh = mesh;
|
||||
this.predicates = predicates;
|
||||
|
||||
sampler = new TriangleSampler(mesh);
|
||||
sampler = new TriangleSampler(mesh, random);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,13 +16,11 @@ namespace TriangleNet
|
||||
/// </summary>
|
||||
class TriangleSampler : IEnumerable<Triangle>
|
||||
{
|
||||
private const int RANDOM_SEED = 110503;
|
||||
|
||||
// Empirically chosen factor.
|
||||
private const int samplefactor = 11;
|
||||
|
||||
private Random random;
|
||||
private Mesh mesh;
|
||||
private readonly Random random;
|
||||
private readonly Mesh mesh;
|
||||
|
||||
// Number of random samples for point location (at least 1).
|
||||
private int samples = 1;
|
||||
@@ -30,11 +28,6 @@ namespace TriangleNet
|
||||
// Number of triangles in mesh.
|
||||
private int triangleCount = 0;
|
||||
|
||||
public TriangleSampler(Mesh mesh)
|
||||
: this(mesh, new Random(RANDOM_SEED))
|
||||
{
|
||||
}
|
||||
|
||||
public TriangleSampler(Mesh mesh, Random random)
|
||||
{
|
||||
this.mesh = mesh;
|
||||
@@ -46,8 +39,8 @@ namespace TriangleNet
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
this.samples = 1;
|
||||
this.triangleCount = 0;
|
||||
samples = 1;
|
||||
triangleCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user