refactor(demo): simplify benchmark teardown and improve CSG demo structure feat master
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 1 Apr 2026 20:12:44 +0000 (23:12 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 1 Apr 2026 20:12:44 +0000 (23:12 +0300)
- Replace manual shape removal loops with shapes.clear() in all benchmark
  teardown methods for cleaner and more efficient cleanup
- Extract createCube() and createSphere() factory methods in CSGDemo to
  encapsulate shape creation with appropriate shading settings (cubes with
  shading enabled, spheres with shading disabled for glow effect)
- Update CSG demo colors to green/orange palette and enhance lighting
  configuration with brighter lights and warm fill tint
- Use static color imports for cleaner code in description panels

src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/LitSolidCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/StarGridTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/essentials/CSGDemo.java

index 9fd491e..4932cdf 100644 (file)
@@ -99,14 +99,10 @@ public class LitSolidCubesTest implements BenchmarkTest {
 
     @Override
     public void teardown(final ShapeCollection shapes) {
-        for (final SolidPolygonCube cube : cubes) {
-            shapes.getShapes().remove(cube);
-        }
+        shapes.clear();
         cubes.clear();
 
         for (final OrbitingLight ol : orbitingLights) {
-            shapes.getShapes().remove(ol.marker);
-            // Remove light from global lighting manager
             if (viewPanel != null) {
                 viewPanel.getLightingManager().removeLight(ol.light);
             }
index e3d9abe..01ec844 100644 (file)
@@ -72,9 +72,7 @@ public class SolidCubesTest implements BenchmarkTest {
 
     @Override
     public void teardown(ShapeCollection shapes) {
-        for (Object cube : cubes) {
-            shapes.getShapes().remove(cube);
-        }
+        shapes.clear();
         cubes.clear();
     }
 }
\ No newline at end of file
index 8ba2f86..2e80dc3 100644 (file)
@@ -70,9 +70,7 @@ public class StarGridTest implements BenchmarkTest {
 
     @Override
     public void teardown(ShapeCollection shapes) {
-        for (Object star : stars) {
-            shapes.getShapes().remove(star);
-        }
+        shapes.clear();
         stars.clear();
     }
 
index 32738e3..887b29d 100644 (file)
@@ -73,9 +73,7 @@ public class TexturedCubesTest implements BenchmarkTest {
 
     @Override
     public void teardown(ShapeCollection shapes) {
-        for (Object cube : cubes) {
-            shapes.getShapes().remove(cube);
-        }
+        shapes.clear();
         cubes.clear();
     }
 
index afc26c4..23dc72f 100644 (file)
@@ -74,9 +74,7 @@ public class WireframeCubesTest implements BenchmarkTest {
 
     @Override
     public void teardown(ShapeCollection shapes) {
-        for (Object cube : cubes) {
-            shapes.getShapes().remove(cube);
-        }
+        shapes.clear();
         cubes.clear();
     }
 }
\ No newline at end of file
index 6169fc0..cf33722 100644 (file)
@@ -10,7 +10,6 @@ import eu.svjatoslav.sixth.e3d.gui.TextPointer;
 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
 import eu.svjatoslav.sixth.e3d.math.Transform;
-import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
 import eu.svjatoslav.sixth.e3d.renderer.raster.lighting.LightSource;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.solid.SolidPolygonCube;
@@ -19,7 +18,7 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextC
 
 import static eu.svjatoslav.sixth.e3d.geometry.Point3D.origin;
 import static eu.svjatoslav.sixth.e3d.geometry.Point3D.point;
-import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.hex;
+import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.*;
 
 /**
  * Demo showcasing Constructive Solid Geometry (CSG) boolean operations.
@@ -47,19 +46,40 @@ import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.hex;
 public class CSGDemo {
 
     /**
-     * Color for the first argument in boolean operations (cube).
+     * Distance between shapes on the X axis.
      */
-    private static final Color COLOR_FIRST = hex("FF6464D9");
+    private static final double SPACING = 400;
+
+    // ==================== SHAPE FACTORY METHODS ====================
 
     /**
-     * Color for the second argument in boolean operations (sphere).
+     * Creates a cube for CSG operations with current demo parameters.
+     *
+     * <p>The cube is created with shading enabled for realistic lighting.</p>
+     *
+     * @return a new SolidPolygonCube centered at origin with shading enabled
      */
-    private static final Color COLOR_SECOND = hex("6496FFD9");
+    private static SolidPolygonCube createCube() {
+        final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, hex("39FF14D9"));
+        cube.setShadingEnabled(true);
+        return cube;
+    }
 
     /**
-     * Distance between shapes on the X axis.
+     * Creates a sphere for CSG operations with current demo parameters.
+     *
+     * <p>The sphere is created with shading disabled, causing it to glow
+     * at full intensity regardless of lighting conditions.</p>
+     *
+     * @return a new SolidPolygonSphere centered at origin with shading disabled
      */
-    private static final double SPACING = 400;
+    private static SolidPolygonSphere createSphere() {
+        final SolidPolygonSphere sphere = new SolidPolygonSphere(origin(), 96, 12, hex("FF6600C0"));
+        sphere.setShadingEnabled(false);
+        return sphere;
+    }
+
+    // ==================== MAIN ENTRY POINT ====================
 
     /**
      * Entry point for the CSG demo.
@@ -75,7 +95,7 @@ public class CSGDemo {
         viewPanel.getCamera().getTransform().set(-244.24, 254.40, -458.83, -0.26, 0.24, -0.00);
 
         // Set up lighting
-        viewPanel.getLightingManager().setAmbientLight(hex("3C3C46"));
+        viewPanel.getLightingManager().setAmbientLight(hex("0D0D0D"));
 
         // Create lights
         createLights(viewPanel, shapes);
@@ -97,19 +117,18 @@ public class CSGDemo {
      */
     private static void createSubtractDemo(final ShapeCollection shapes, final Point3D location) {
 
-        final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
-        cube.subtract(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+        final SolidPolygonCube cube = createCube();
+        cube.subtract(createSphere());
 
         shapes.addShape(cube
                 .setTransform(new Transform(location))
-                .setShadingEnabled(true)
                 .setBackfaceCulling(true));
 
         final String description =
                 "Subtract: Cube - Sphere\n" +
                         "\n" +
-                        "Red = Cube (kept)\n" +
-                        "Blue = Sphere (carved out)";
+                        "Green = Cube (kept)\n" +
+                        "Orange = Sphere (carved out)";
 
         shapes.addShape(createDescriptionPanel(location, description));
     }
@@ -123,19 +142,18 @@ public class CSGDemo {
      */
     private static void createUnionDemo(final ShapeCollection shapes, final Point3D location) {
 
-        final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
-        cube.union(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+        final SolidPolygonCube cube = createCube();
+        cube.union(createSphere());
 
         shapes.addShape(cube
                 .setTransform(new Transform(location))
-                .setShadingEnabled(true)
                 .setBackfaceCulling(true));
 
         final String description =
                 "Union: Cube + Sphere\n" +
                         "\n" +
-                        "Red = Cube\n" +
-                        "Blue = Sphere";
+                        "Green = Cube\n" +
+                        "Orange = Sphere";
 
         shapes.addShape(createDescriptionPanel(location, description));
     }
@@ -149,19 +167,18 @@ public class CSGDemo {
      */
     private static void createIntersectDemo(final ShapeCollection shapes, final Point3D location) {
 
-        final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
-        cube.intersect(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+        final SolidPolygonCube cube = createCube();
+        cube.intersect(createSphere());
 
         shapes.addShape(cube
                 .setTransform(new Transform(location))
-                .setShadingEnabled(true)
                 .setBackfaceCulling(true));
 
         final String description =
                 "Intersect: Cube ∩ Sphere\n" +
                         "\n" +
-                        "Red = from Cube\n" +
-                        "Blue = from Sphere";
+                        "Green = from Cube\n" +
+                        "Orange = from Sphere";
 
         shapes.addShape(createDescriptionPanel(location, description));
     }
@@ -181,8 +198,8 @@ public class CSGDemo {
         final TextCanvas panel = new TextCanvas(
                 transform,
                 new TextPointer(5, 35),
-                Color.WHITE,
-                new Color(0, 0, 40, 180));
+                WHITE,
+                TRANSPARENT);
 
         panel.setText(text);
         return panel;
@@ -195,20 +212,22 @@ public class CSGDemo {
      * @param shapes    the shape collection
      */
     private static void createLights(final ViewPanel viewPanel, final ShapeCollection shapes) {
-        // Main light from above-front
+        // Main light from above-front - bright white
         final LightSource mainLight = new LightSource(
                 point(0, -300, -400),
                 hex("FFFFFF"),
-                1.5
+                5.5
         );
         viewPanel.getLightingManager().addLight(mainLight);
 
-        // Fill light from the side
+        // Fill light from the side - warm orange tint
         final LightSource fillLight = new LightSource(
                 point(500, 100, -200),
-                hex("9696C8"),
-                0.8
+                hex("FF6600"),
+                5.5
         );
         viewPanel.getLightingManager().addLight(fillLight);
+
+        viewPanel.getLightingManager().setAmbientLight(hex("3D3D5D"));
     }
 }
\ No newline at end of file