diff options
author | Marius Kintel <marius@kintel.net> | 2013-08-15 03:01:43 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-08-15 03:01:43 (GMT) |
commit | ea606f69fcf5e0c75b2b484f49d6f3fe1c69ff78 (patch) | |
tree | 99724a00db25f825d68752230f2b89751ca6d42f /src/func.cc | |
parent | 70247b75457afed5a1ca3c0caf1168dff22b690e (diff) | |
parent | af7e8320e2d0fda0e2b8505f50080ff3d33e7531 (diff) |
Merge branch 'master' of github.com:openscad/openscad
Diffstat (limited to 'src/func.cc')
-rw-r--r-- | src/func.cc | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/func.cc b/src/func.cc index eaaae74..20f487a 100644 --- a/src/func.cc +++ b/src/func.cc @@ -153,10 +153,10 @@ Value builtin_rands(const Context *, const EvalContext *evalctx) deterministic = false; } else if (evalctx->numArgs() == 4 && - evalctx->getArgValue(0).type() == Value::NUMBER && - evalctx->getArgValue(1).type() == Value::NUMBER && - evalctx->getArgValue(2).type() == Value::NUMBER && - evalctx->getArgValue(3).type() == Value::NUMBER) + evalctx->getArgValue(0).type() == Value::NUMBER && + evalctx->getArgValue(1).type() == Value::NUMBER && + evalctx->getArgValue(2).type() == Value::NUMBER && + evalctx->getArgValue(3).type() == Value::NUMBER) { deterministic_rng.seed( (unsigned int) evalctx->getArgValue(3).toDouble() ); deterministic = true; @@ -165,19 +165,24 @@ Value builtin_rands(const Context *, const EvalContext *evalctx) { return Value(); } - + double min = std::min( evalctx->getArgValue(0).toDouble(), evalctx->getArgValue(1).toDouble() ); double max = std::max( evalctx->getArgValue(0).toDouble(), evalctx->getArgValue(1).toDouble() ); + size_t numresults = std::max( 0, static_cast<int>( evalctx->getArgValue(2).toDouble() ) ); boost::uniform_real<> distributor( min, max ); Value::VectorType vec; - for (int i=0; i<evalctx->getArgValue(2).toDouble(); i++) { - if ( deterministic ) { - vec.push_back( Value( distributor( deterministic_rng ) ) ); - } else { - vec.push_back( Value( distributor( lessdeterministic_rng ) ) ); + if (min==max) { // workaround boost bug + for (size_t i=0; i < numresults; i++) + vec.push_back( Value( min ) ); + } else { + for (size_t i=0; i < numresults; i++) { + if ( deterministic ) { + vec.push_back( Value( distributor( deterministic_rng ) ) ); + } else { + vec.push_back( Value( distributor( lessdeterministic_rng ) ) ); + } } } - return Value(vec); } |