commit d3e231310f17a79e3c83b9c2b992d97b2f2c683b
parent a7f79ff6659a713e30e6bdb078ef5c1aab419e18
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 27 Jul 2021 08:42:27 +0200
Fix the checks of the scam_generate_ray function
Diffstat:
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/scam.c b/src/scam.c
@@ -30,14 +30,16 @@ check_sample
ASSERT(cam);
if(!sample) return 0;
- if(sample->film[0] < 0 || sample->film[1] >= 1) {
+ if(sample->film[0] < 0 || sample->film[0] >= 1
+ || sample->film[1] < 0 || sample->film[1] >= 1) {
log_err(cam,
"Invalid camera film sample (%g, %g). It must be in [0, 1[^2.\n",
SPLIT2(sample->film));
return 0;
}
- if(sample->lens[0] < 0 || sample->lens[1] >= 1) {
+ if(sample->lens[0] < 0 || sample->lens[0] >= 1
+ || sample->lens[1] < 0 || sample->lens[1] >= 1) {
log_err(cam,
"Invalid camera lens sample (%g, %g). It must be in [0, 1[^2.\n",
SPLIT2(sample->lens));
diff --git a/src/test_scam_pinhole.c b/src/test_scam_pinhole.c
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define _POSIX_C_SOURCE 200112L /* nextafter */
+#define _POSIX_C_SOURCE 200112L /* nextafterf */
#include "scam.h"
#include "test_scam_utils.h"
@@ -128,6 +128,20 @@ main(int argc, char** argv)
CHK(scam_generate_ray(NULL, &sample, &ray) == RES_BAD_ARG);
CHK(scam_generate_ray(cam, NULL, &ray) == RES_BAD_ARG);
CHK(scam_generate_ray(cam, &sample, NULL) == RES_BAD_ARG);
+
+ sample.film[0] = nextafterf(0, -1);
+ CHK(scam_generate_ray(cam, &sample, &ray) == RES_BAD_ARG);
+ sample.film[0] = 1;
+ CHK(scam_generate_ray(cam, &sample, &ray) == RES_BAD_ARG);
+ sample.film[0] = 0;
+ sample.film[1] = nextafterf(0, -1);
+ CHK(scam_generate_ray(cam, &sample, &ray) == RES_BAD_ARG);
+ sample.film[1] = 1;
+ CHK(scam_generate_ray(cam, &sample, &ray) == RES_BAD_ARG);
+ sample.film[0] = 0;
+ sample.film[1] = nextafterf(1, 0);
+ CHK(scam_generate_ray(cam, &sample, &ray) == RES_OK);
+
FOR_EACH(i, 0, nsamps) {
double cos_ray_axis_x;
double cos_ray_axis_y;