Quasar C++ API: maximum value and step size swapped in range object

Q&AQuasar C++ API: maximum value and step size swapped in range object
Frank Vernaillen asked 2 years ago

The scalar and integer quasar::Range(minVal, maxVal, step = 1) constructors in quasar_dsl.h build an incorrect range object: maxVal and step are swapped.
So Range(1, 5, 1) returns [1], and Range(1, 1, 5) returns [1 2 3 4 5], which is wrong.
The way these 3 parameters are interpreted corresponds to the Quasar syntax of minVal:step:maxVal, but not to the order of the arguments in the C++ Range constructor. (The order of course is different to leverage C++’s default argument mechanism for step, which needs to come last.)
I think step and maxVal need to be pushed in reverse order on the evaluation stack in quasar_dsl.h.

1 Answers
bgoossen Staff answered 2 years ago

Indeed, there is a mistake in quasar_dsl.h. Thanks for pointing this out! The two constructors of Range() need to be modified to:
stack->PushValue(qvalue_t::fromScalar(minVal));
stack->PushValue(qvalue_t::fromScalar(step));
stack->PushValue(qvalue_t::fromScalar(maxVal)); 
This corresponds to the minVal..step..maxVal notation of Quasar.