Skip to content

Commit 3c2f82b

Browse files
committed
Remove the Random() function and use a fixed table of arbitrary vectors in raycast.cpp
This also fixes issue #666.
1 parent fd2dfe8 commit 3c2f82b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/solvespace.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ static constexpr double LENGTH_EPS = 1e-6;
122122
static constexpr double VERY_POSITIVE = 1e10;
123123
static constexpr double VERY_NEGATIVE = -1e10;
124124

125-
inline double Random(double vmax) {
126-
return (vmax*rand()) / RAND_MAX;
127-
}
128-
129125
#include "platform/platform.h"
130126
#include "platform/gui.h"
131127
#include "resource.h"

src/srf/raycast.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ SShell::Class SShell::ClassifyRegion(Vector edge_n, Vector inter_surf_n,
419419
// using the closest intersection point. If the ray hits a surface on edge,
420420
// then just reattempt in a different random direction.
421421
//-----------------------------------------------------------------------------
422+
423+
// table of vectors in 6 arbitrary directions covering 4 of the 8 octants.
424+
// use overlapping sets of 3 to reduce memory usage.
425+
static const double Random[8] = {1.278, 5.0103, 9.427, -2.331, 7.13, 2.954, 5.034, -4.777};
426+
422427
bool SShell::ClassifyEdge(Class *indir, Class *outdir,
423428
Vector ea, Vector eb,
424429
Vector p,
@@ -549,7 +554,7 @@ bool SShell::ClassifyEdge(Class *indir, Class *outdir,
549554
// Cast a ray in a random direction (two-sided so that we test if
550555
// the point lies on a surface, but use only one side for in/out
551556
// testing)
552-
Vector ray = Vector::From(Random(1), Random(1), Random(1));
557+
Vector ray = Vector::From(Random[cnt], Random[cnt+1], Random[cnt+2]);
553558

554559
AllPointsIntersecting(
555560
p.Minus(ray), p.Plus(ray), &l,
@@ -598,7 +603,8 @@ bool SShell::ClassifyEdge(Class *indir, Class *outdir,
598603
// then our ray always lies on edge, and that's okay. Otherwise
599604
// try again in a different random direction.
600605
if(!onEdge) break;
601-
if(cnt++ > 5) {
606+
cnt++;
607+
if(cnt > 5) {
602608
dbp("can't find a ray that doesn't hit on edge!");
603609
dbp("on edge = %d, edge_inters = %d", onEdge, edge_inters);
604610
SS.nakedEdges.AddEdge(ea, eb);

0 commit comments

Comments
 (0)