From 07cdc0c21361c8d5c7e7a0c29067404ecd9eecc5 Mon Sep 17 00:00:00 2001 From: jbb01 <32650546+jbb01@users.noreply.github.com> Date: Sun, 4 Aug 2024 19:54:21 +0200 Subject: [PATCH] remove Double#isFinite checks in Vec3 constructor A performance analysis showed, that the Double#isFinite checks in the Vec3 constructor add significant overhead without providing much value to the application. --- src/main/java/eu/jonahbauer/raytracing/math/Vec3.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java b/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java index adbfbb4..76c8d41 100644 --- a/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java +++ b/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java @@ -11,9 +11,7 @@ public record Vec3(double x, double y, double z) { public static final Vec3 UNIT_Z = new Vec3(0, 0, 1); public Vec3 { - if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)) { - throw new IllegalArgumentException("x, y and z must be finite"); - } + assert Double.isFinite(x) && Double.isFinite(y) && Double.isFinite(z) : "x, y and z must be finite"; } public static @NotNull Vec3 random() {