### Basic 1-Wide Grid Casting with Java Source: https://github.com/emortalmc/rayfast/wiki/Grid-Casting Demonstrates how to create an iterator over grid units along a specified line using `GridCast.createGridIterator`. The iterator yields consecutive grid units intersected by the line. This method is useful for voxel-based games where traversing blocks is essential. ```java double posX = Math.random(), posY = Math.random(), posZ = Math.random(); double dirX = Math.random(), dirY = Math.random(), dirZ = Math.random(); Iterator iterator = GridCast.createGridIterator( posX, posY, posZ, dirX, dirY, dirZ ); while (iterator.hasNext()) { Vector3d gridUnit = iterator.next(); System.out.println(gridUnit.x() + ":" + gridUnit.y() + ":" + gridUnit.z()); } ``` -------------------------------- ### Registering Custom Entity Bounding Boxes with Area3d Converter Source: https://github.com/emortalmc/rayfast/wiki/Area3d This example shows how to register a custom entity's bounding box with the Area3d converter. This allows the Rayfast library to efficiently convert and use the custom entity's spatial properties for raycasting operations. The registration is done by providing the entity class and a method reference that returns an Area3d instance. ```java import dev.emortal.rayfast.area.Area3d; // Assuming ExampleRaycastEntity is a custom class with a getBoundingBox() method // that returns an Area3d instance. Area3d.CONVERTER.register(ExampleRaycastEntity.class, ExampleRaycastEntity::getBoundingBox); // After registration, you can convert an entity to Area3d // Note: The null argument in from() might be a placeholder or require a specific context, // depending on the actual implementation of Area3d.CONVERTER.from(). Area3d entityArea = Area3d.CONVERTER.from(null); // Now you can perform intersections with the converted entity area // The intersection method signature might vary, this is a placeholder double[] intersection = entityArea.lineIntersection(...); ``` -------------------------------- ### Java Grid Casting - Limited Range with Custom Grid Size and Collision Detection Source: https://context7.com/emortalmc/rayfast/llms.txt This Java code snippet shows how to perform grid casting with a maximum distance and a custom grid size using Rayfast. It utilizes `Vector3d` for cleaner syntax and includes an example of checking for solid blocks. The `GridCast.createGridIterator` method is used with parameters for grid size and maximum ray length. Dependencies include `dev.emortal.rayfast.casting.grid.GridCast` and `dev.emortal.rayfast.vector.Vector3d`. ```java import dev.emortal.rayfast.casting.grid.GridCast; import dev.emortal.rayfast.vector.Vector3d; import java.util.Iterator; // Using Vector3d objects for cleaner syntax Vector3d start = Vector3d.of(0.0, 64.0, 0.0); Vector3d direction = Vector3d.of(1.0, 0.0, 0.5); // Cast through a 2x2x2 grid with max distance of 50 units Iterator iterator = GridCast.createGridIterator( start, direction, 2.0, // Grid size 50.0 // Maximum ray length ); // Check blocks for collisions while (iterator.hasNext()) { Vector3d block = iterator.next(); // Example: Check if this block is solid if (isBlockSolid((int) block.x(), (int) block.y(), (int) block.z())) { System.out.println("Ray hit solid block at " + block); break; } } // Helper method (example implementation) private static boolean isBlockSolid(int x, int y, int z) { // Your block checking logic here return (x + y + z) % 5 == 0; // Example: every 5th block is solid } ``` -------------------------------- ### Java: Get All Intersections with Distance and Order Source: https://context7.com/emortalmc/rayfast/llms.txt This Java code snippet demonstrates how to find all intersection points between a ray and a 3D rectangular prism, including entry and exit points, ordered by distance. It utilizes the `Area3dRectangularPrism` and `Vector3d` classes from the `dev.emortal.rayfast` library. The output includes the number of hits and detailed information for each intersection point. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.area.Intersection; import dev.emortal.rayfast.vector.Vector3d; import java.util.List; // Create a large box that ray will pass through Area3d largeBox = Area3dRectangularPrism.of( 10.0, 0.0, 10.0, 30.0, 20.0, 30.0 ); // Define ray that enters and exits the box Vector3d rayStart = Vector3d.of(0.0, 10.0, 20.0); Vector3d rayDir = Vector3d.of(1.0, 0.0, 0.0); // Get ALL intersections (entry and exit points) ordered by distance List> allHits = largeBox.lineIntersection(rayStart, rayDir, Intersection.ALL_FORWARDS_3D); System.out.println("Found " + allHits.size() + " intersection points:"); for (int i = 0; i < allHits.size(); i++) { Intersection.Result hit = allHits.get(i); Vector3d point = hit.intersection(); if (point != null) { double distance = Math.sqrt( Math.pow(point.x() - rayStart.x(), 2) + Math.pow(point.y() - rayStart.y(), 2) + Math.pow(point.z() - rayStart.z(), 2) ); String hitType = (i == 0) ? "Entry" : "Exit"; System.out.printf("%s point %d: (%.2f, %.2f, %.2f) at distance %.2f%n", hitType, i + 1, point.x(), point.y(), point.z(), distance); } } // Alternative: Just check if ray intersects (boolean test) boolean doesIntersect = largeBox.lineIntersects(rayStart, rayDir); System.out.println("Ray intersects box: " + doesIntersect); ``` -------------------------------- ### Java Grid Casting - Retrieving Exact Intersection Points Source: https://context7.com/emortalmc/rayfast/llms.txt This Java snippet demonstrates how to obtain the exact coordinates where a ray intersects each grid unit using Rayfast's `GridCast.createExactGridIterator`. It's useful for precise calculations of entry points into voxels. The function takes starting position, direction, grid size, and maximum distance as input. Dependencies include `dev.emortal.rayfast.casting.grid.GridCast` and `dev.emortal.rayfast.vector.Vector3d`. ```java import dev.emortal.rayfast.casting.grid.GridCast; import dev.emortal.rayfast.vector.Vector3d; import java.util.Iterator; Vector3d playerPos = Vector3d.of(10.5, 65.0, 20.3); Vector3d lookDirection = Vector3d.of(0.8, -0.1, 0.6); // Get exact intersection points (not just grid coordinates) Iterator exactIterator = GridCast.createExactGridIterator( playerPos, lookDirection, 1.0, // Standard 1x1x1 grid 100.0 // Max distance ); while (exactIterator.hasNext()) { Vector3d exactHitPoint = exactIterator.next(); // exactHitPoint contains precise x,y,z where ray entered this grid unit System.out.printf("Ray entered grid at exact position: (%.3f, %.3f, %.3f)%n", exactHitPoint.x(), exactHitPoint.y(), exactHitPoint.z()); // Calculate distance from player double distance = Math.sqrt( Math.pow(exactHitPoint.x() - playerPos.x(), 2) + Math.pow(exactHitPoint.y() - playerPos.y(), 2) + Math.pow(exactHitPoint.z() - playerPos.z(), 2) ); if (distance > 50.0) { break; // Custom early exit } } ``` -------------------------------- ### Java Grid Casting - Basic Voxel Iteration with Unlimited Range Source: https://context7.com/emortalmc/rayfast/llms.txt This snippet demonstrates basic grid casting in Java using Rayfast's GridCast. It iterates through 1x1x1 voxel grid units along a ray path indefinitely. The output includes the coordinates of each grid unit encountered. Dependencies include `dev.emortal.rayfast.casting.grid.GridCast` and `dev.emortal.rayfast.vector.Vector3d`. ```java import dev.emortal.rayfast.casting.grid.GridCast; import dev.emortal.rayfast.vector.Vector3d; import java.util.Iterator; // Define ray starting position and direction double posX = 5.5, posY = 10.0, posZ = 3.2; double dirX = 0.6, dirY = -0.3, dirZ = 0.75; // Create iterator that traverses a 1x1x1 grid indefinitely Iterator iterator = GridCast.createGridIterator( posX,posY, posZ, dirX, dirY, dirZ ); // Process the first 100 grid units int count = 0; while (iterator.hasNext() && count < 100) { Vector3d gridUnit = iterator.next(); System.out.println("Grid unit: " + gridUnit.x() + ":" + gridUnit.y() + ":" + gridUnit.z()); count++; } ``` -------------------------------- ### Register and Convert Custom Class to Area3d using Java Source: https://github.com/emortalmc/rayfast/wiki/Converter This snippet demonstrates how to use the Rayfast Converter class to register a custom 'Point' class and then convert an instance of 'Point' into an Area3d object. It shows the registration of a 'Point' class to generate a cube with specific Z-bounds and then utilizes the converter to create this cube from a 'Point' instance. The converter handles the transformation logic defined during registration. ```java import dev.emortal.rayfast.area.Area3d; import dev.emortal.rayfast.area.Area3dRectangularPrism; // Assume Point class is defined elsewhere, e.g.: // class Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } } // Register the Point class to generate a cube with minZ = -5 and maxZ = 5. Area3d.CONVERTER.register(Point.class, point -> Area3dRectangularPrism.of( -point.x, -point.y, -5, point.x, point.y, 5 ) ); // Example usage: // Point point = new Point(5, 6); // Create a cube from the converter // Area3d cube = Area3d.CONVERTER.from(point); ``` -------------------------------- ### Area3D - Mutable Entity Bounding Box (Java) Source: https://context7.com/emortalmc/rayfast/llms.txt Demonstrates a mutable bounding box for a game entity that updates automatically with the entity's position. It uses a nested BoundingBox class within GameEntity to recalculate bounds on access, avoiding manual updates. Dependencies include Rayfast's Area3D, Area3dLike, Area3dRectangularPrism, and Vector3d classes. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dLike; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.vector.Vector3d; import org.jetbrains.annotations.NotNull; // Entity with position and bounding box class GameEntity implements Area3dLike { private double x, y, z; private final BoundingBox boundingBox; public GameEntity(double x, double y, double z, double width, double height, double depth) { this.x = x; this.y = y; this.z = z; this.boundingBox = new BoundingBox(this, width, height, depth); } public void setPosition(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public double getX() { return x; } public double getY() { return y; } public double getZ() { return z; } public BoundingBox getBoundingBox() { return boundingBox; } @Override public @NotNull Area3d asArea3d() { return boundingBox; } // Mutable bounding box that recalculates on each access static class BoundingBox implements Area3dRectangularPrism { private final GameEntity entity; private final double halfWidth, halfHeight, halfDepth; BoundingBox(GameEntity entity, double width, double height, double depth) { this.entity = entity; this.halfWidth = width / 2.0; this.halfHeight = height / 2.0; this.halfDepth = depth / 2.0; } @Override public double minX() { return entity.getX() - halfWidth; } @Override public double minY() { return entity.getY() - halfHeight; } @Override public double minZ() { return entity.getZ() - halfDepth; } @Override public double maxX() { return entity.getX() + halfWidth; } @Override public double maxY() { return entity.getY() + halfHeight; } @Override public double maxZ() { return entity.getZ() + halfDepth; } } } // Usage example GameEntity player = new GameEntity(10.0, 64.0, 20.0, 0.6, 1.8, 0.6); // Raycast at initial position Vector3d ray = Vector3d.of(0.0, 65.0, 20.0); Vector3d dir = Vector3d.of(1.0, 0.0, 0.0); boolean hit1 = player.getBoundingBox().lineIntersects(ray, dir); System.out.println("Hit at position 1: " + hit1); // Move entity and raycast again (no new object creation needed) player.setPosition(15.0, 64.0, 20.0); boolean hit2 = player.getBoundingBox().lineIntersects(ray, dir); System.out.println("Hit at position 2: " + hit2); ``` -------------------------------- ### Raycasting with Area3dRectangularPrism Source: https://github.com/emortalmc/rayfast/wiki/Area3d This snippet demonstrates how to create a rectangular prism using Area3dRectangularPrism and perform a line intersection test. It initializes the prism with random coordinates and casts a ray using random points and directions. The output indicates whether the line intersected the prism. ```java import dev.emortal.rayfast.area.Area3d; import dev.emortal.rayfast.area.Area3dRectangularPrism; import dev.emortal.rayfast.vector.Vector3d; // Create a rectangular prism with random coordinates Area3d rectangularPrism = Area3dRectangularPrism.of( Math.random(), Math.random(), Math.random(), // Min position Math.random(), Math.random(), Math.random() // Max position ); // Cast a ray though it, and check if it was intersected Vector3d intersection = rectangularPrism.lineIntersection( Math.random(), Math.random(), Math.random(), // Line point Math.random(), Math.random(), Math.random() // Line direction ); System.out.println("Line Intersected: " + (intersection != null)); ``` -------------------------------- ### Combined Raycasting for Grids and Entities (Java) Source: https://context7.com/emortalmc/rayfast/llms.txt Performs raycasting that simultaneously checks against voxel grids and entity bounding boxes. It utilizes a builder pattern to configure casting parameters like maximum distance, grid size, and stopping conditions. The output provides hit information for both grid units and entities, ordered by distance. Dependencies include classes for `CombinedCast`, `Area3dLike`, and `Vector3d`. ```java import dev.emortal.rayfast.casting.combined.CombinedCast; import dev.emortal.rayfast.casting.combined.CombinedCastResult.HitResult; import dev.emortal.rayfast.casting.combined.CombinedCastResult.HitType; import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.area.area3d.Area3dLike; import dev.emortal.rayfast.vector.Vector3d; import java.util.List; import java.util.ArrayList; // Create entities List entities = new ArrayList<>(); entities.add(Area3dRectangularPrism.of(10.0, 64.0, 10.0, 11.0, 66.0, 11.0)); entities.add(Area3dRectangularPrism.of(15.0, 64.0, 15.0, 16.0, 66.0, 16.0)); entities.add(Area3dRectangularPrism.of(20.0, 64.0, 20.0, 21.0, 66.0, 21.0)); // Build combined cast with grid checking and entity checking CombinedCast cast = CombinedCast.builder() .max(50.0) // Maximum ray distance .gridSize(1.0) // 1x1x1 block grid .ordered(true) // Return results in distance order .stopWhen((Vector3d gridPos) -> { // Stop if solid block found int x = (int) Math.floor(gridPos.x()); int y = (int) Math.floor(gridPos.y()); int z = (int) Math.floor(gridPos.z()); return isBlockSolid(x, y, z); }) .stopWhen((Vector3d hitPos, Area3d area) -> { // Stop if entity hit (returns true to stop) return true; }) .build(); // Perform combined cast Vector3d origin = Vector3d.of(0.0, 65.0, 0.0); Vector3d direction = Vector3d.of(1.0, 0.0, 1.0); List results = cast.apply(entities, origin, direction); // Process results (ordered by distance) for (HitResult result : results) { Vector3d hitPos = result.position(); double distance = Math.sqrt(result.distanceSquared()); if (result.type() == HitType.AREA3D) { System.out.printf("Hit entity at (%.2f, %.2f, %.2f), distance: %.2f%n", hitPos.x(), hitPos.y(), hitPos.z(), distance); break; // Stop on first entity hit } else if (result.type() == HitType.GRIDUNIT) { System.out.printf("Passed through grid unit at (%.0f, %.0f, %.0f)%n", Math.floor(hitPos.x()), Math.floor(hitPos.y()), Math.floor(hitPos.z())); } } private static boolean isBlockSolid(int x, int y, int z) { // Example: blocks below y=64 are solid return y < 64 || (x == 12 && z == 12); } ``` -------------------------------- ### Type Converter - Entity to Area3d Conversion (Java) Source: https://context7.com/emortalmc/rayfast/llms.txt Illustrates registering a custom type converter for a 'Monster' class to automatically transform it into an Area3d object using its hitbox. This allows for seamless integration of custom entity types with Rayfast's raycasting system without manual conversion. It requires Rayfast's Area3d and Area3dRectangularPrism classes. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; // Custom entity class class Monster { private double x, y, z; private Area3dRectangularPrism hitbox; public Monster(double x, double y, double z) { this.x = x; this.y = y; this.z = z; this.hitbox = Area3dRectangularPrism.of( x - 0.5, y, z - 0.5, x + 0.5, y + 2.0, z + 0.5 ); } public Area3dRectangularPrism getHitbox() { return hitbox; } public void updatePosition(double newX, double newY, double newZ) { this.x = newX; this.y = newY; this.z = newZ; this.hitbox = Area3dRectangularPrism.of( x - 0.5, y, z - 0.5, x + 0.5, y + 2.0, z + 0.5 ); } } // Register converter once at application startup Area3d.CONVERTER.register(Monster.class, Monster::getHitbox); // Now you can convert monsters to Area3d efficiently Monster zombie = new Monster(10.0, 64.0, 20.0); // Convert using the registered converter Area3d zombieArea = Area3d.CONVERTER.from(zombie); // Perform raycasting Vector3d rayOrigin = Vector3d.of(5.0, 65.0, 20.0); Vector3d rayDir = Vector3d.of(1.0, 0.0, 0.0); boolean hitZombie = zombieArea.lineIntersects(rayOrigin, rayDir); System.out.println("Hit zombie: " + hitZombie); // Update position and cast again zombie.updatePosition(15.0, 64.0, 20.0); Area3d updatedArea = Area3d.CONVERTER.from(zombie); boolean hitAfterMove = updatedArea.lineIntersects(rayOrigin, rayDir); System.out.println("Hit after move: " + hitAfterMove); ``` -------------------------------- ### Ray Intersection with 3D Rectangular Prism Source: https://context7.com/emortalmc/rayfast/llms.txt Tests for ray intersection with a 3D rectangular bounding box. It takes a ray's origin and direction and returns the intersection point if one exists. Dependencies include Area3d, Area3dRectangularPrism, and Vector3d from the dev.emortal.rayfast library. The output is a Vector3d representing the intersection point or null if no intersection occurs. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.vector.Vector3d; // Create a rectangular prism (e.g., entity bounding box) Area3d boundingBox = Area3dRectangularPrism.of( 10.0, 20.0, 30.0, // Min X, Y, Z 15.0, 25.0, 35.0 // Max X, Y, Z ); // Cast ray from position through direction Vector3d rayOrigin = Vector3d.of(5.0, 22.5, 32.5); Vector3d rayDirection = Vector3d.of(1.0, 0.0, 0.0); Vector3d intersection = boundingBox.lineIntersection(rayOrigin, rayDirection); if (intersection != null) { System.out.printf("Ray hit box at (%.2f, %.2f, %.2f)%n", intersection.x(), intersection.y(), intersection.z()); // Calculate hit distance double distance = Math.sqrt( Math.pow(intersection.x() - rayOrigin.x(), 2) + Math.pow(intersection.y() - rayOrigin.y(), 2) + Math.pow(intersection.z() - rayOrigin.z(), 2) ); System.out.printf("Distance to hit: %.2f%n", distance); } else { System.out.println("Ray did not intersect the box"); } ``` -------------------------------- ### Ray Intersection with Combined 3D Shapes Source: https://context7.com/emortalmc/rayfast/llms.txt Performs ray intersection tests against multiple combined 3D shapes, such as several rectangular prisms. It uses the Area3d.combined() method to create a single target for raycasting. Dependencies include Area3d, Area3dRectangularPrism, and Vector3d. The method returns the first intersection point with any of the combined shapes and allows checking which specific shape was hit. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.vector.Vector3d; // Create multiple bounding boxes (e.g., multiple entities) Area3d entity1 = Area3dRectangularPrism.of(10.0, 0.0, 10.0, 12.0, 2.0, 12.0); Area3d entity2 = Area3dRectangularPrism.of(20.0, 0.0, 20.0, 22.0, 2.0, 22.0); Area3d entity3 = Area3dRectangularPrism.of(15.0, 5.0, 15.0, 17.0, 7.0, 17.0); // Combine all areas into single raycasting target Area3d combinedAreas = Area3d.combined(entity1, entity2, entity3); // Cast ray through combined areas Vector3d rayStart = Vector3d.of(0.0, 1.0, 0.0); Vector3d rayDir = Vector3d.of(1.0, 0.0, 1.0); Vector3d hit = combinedAreas.lineIntersection(rayStart, rayDir); if (hit != null) { System.out.printf("Ray hit combined shape at (%.2f, %.2f, %.2f)%n", hit.x(), hit.y(), hit.z()); // Check which specific entity was hit if (entity1.lineIntersects(rayStart, rayDir)) { System.out.println("Entity 1 was hit"); } if (entity2.lineIntersects(rayStart, rayDir)) { System.out.println("Entity 2 was hit"); } if (entity3.lineIntersects(rayStart, rayDir)) { System.out.println("Entity 3 was hit"); } } else { System.out.println("Ray missed all entities"); } ``` -------------------------------- ### 2D Rectangle Ray Intersection and Point Containment (Java) Source: https://context7.com/emortalmc/rayfast/llms.txt Tests for ray intersection with 2D rectangles, suitable for top-down games or UI elements. It calculates the intersection point and distance. Additionally, it provides functionality to check if a given 2D point is contained within the rectangle and to calculate the rectangle's area. Dependencies include classes for `Area2d`, `Area2dRectangle`, and `Vector2d`. ```java import dev.emortal.rayfast.area.area2d.Area2d; import dev.emortal.rayfast.area.area2d.Area2dRectangle; import dev.emortal.rayfast.vector.Vector2d; import dev.emortal.rayfast.area.Intersection; // Create 2D rectangular area (e.g., collision box in top-down game) Area2d rectangle = Area2dRectangle.of( 10.0, 10.0, // Min X, Y 20.0, 20.0 // Max X, Y ); // Cast 2D ray Vector2d rayOrigin = Vector2d.of(5.0, 15.0); Vector2d rayDirection = Vector2d.of(1.0, 0.0); Intersection.Result result = rectangle.lineIntersection( rayOrigin, rayDirection ); if (result.intersection() != null) { Vector2d hitPoint = result.intersection(); System.out.printf("2D Ray hit at (%.2f, %.2f)%n", hitPoint.x(), hitPoint.y()); // Calculate 2D distance double dx = hitPoint.x() - rayOrigin.x(); double dy = hitPoint.y() - rayOrigin.y(); double distance = Math.sqrt(dx * dx + dy * dy); System.out.printf("Distance: %.2f%n", distance); } else { System.out.println("No intersection"); } // Check if point is inside rectangle Vector2d testPoint = Vector2d.of(15.0, 15.0); boolean inside = rectangle.containsPoint(testPoint); System.out.println("Point (15, 15) is inside: " + inside); // Calculate area double area = rectangle.area(); System.out.printf("Rectangle area: %.2f%n", area); ``` -------------------------------- ### Point Containment Test in 3D Area Source: https://context7.com/emortalmc/rayfast/llms.txt Checks if a given 3D point lies within a defined 3D area, specifically a rectangular prism. It utilizes the containsPoint method, which can accept a Vector3d or individual coordinates. Dependencies include Area3d, Area3dRectangularPrism, and Vector3d. The method returns a boolean indicating containment and can also calculate the area (volume) of the region. ```java import dev.emortal.rayfast.area.area3d.Area3d; import dev.emortal.rayfast.area.area3d.Area3dRectangularPrism; import dev.emortal.rayfast.vector.Vector3d; // Define a region Area3d region = Area3dRectangularPrism.of( 0.0, 0.0, 0.0, 100.0, 50.0, 100.0 ); // Test multiple points Vector3d[] testPoints = { Vector3d.of(50.0, 25.0, 50.0), // Inside Vector3d.of(150.0, 25.0, 50.0), // Outside (x too large) Vector3d.of(0.0, 0.0, 0.0), // On boundary }; for (Vector3d point : testPoints) { boolean inside = region.containsPoint(point); System.out.printf("Point (%.1f, %.1f, %.1f) is %s the region%n", point.x(), point.y(), point.z(), inside ? "inside" : "outside"); } // Alternative: using individual coordinates boolean isInside = region.containsPoint(25.0, 10.0, 75.0); System.out.println("Point (25, 10, 75) inside: " + isInside); // Calculate region volume double volume = region.area(); System.out.printf("Region volume: %.2f cubic units%n", volume); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.