001package fr.aumgn.dac2.arena.regions;
002
003import fr.aumgn.bukkitutils.geom.Vector;
004import fr.aumgn.bukkitutils.geom.Vector2D;
005import fr.aumgn.dac2.arena.Diving;
006import fr.aumgn.dac2.shape.CuboidShape;
007import fr.aumgn.dac2.shape.Shape;
008
009public class SurroundingRegion extends Region {
010
011    private static CuboidShape cuboidFor(Diving diving, Pool pool) {
012        Vector2D divingPos = diving.getPosition().to2D();
013        Vector2D poolMin = pool.getShape().getMin2D();
014        Vector2D poolMax = pool.getShape().getMax2D();
015
016        Vector min = new Vector(
017                Math.min(poolMin.getX(), divingPos.getX()) - MARGIN,
018                pool.getShape().getMinY(),
019                Math.min(poolMin.getZ(), divingPos.getZ()) - MARGIN);
020        Vector max = new Vector(
021                Math.max(poolMax.getX(), divingPos.getX()) + MARGIN,
022                diving.getPosition().getY() - MAX_Y_OFFSET,
023                Math.max(poolMax.getZ(), divingPos.getZ()) + MARGIN);
024
025        return new CuboidShape(min, max);
026    }
027
028    private static final double MARGIN = 5.0;
029    private static final double MAX_Y_OFFSET = 3.0;
030
031    private final Shape shape;
032
033    public SurroundingRegion(Shape shape) {
034        this.shape = shape;
035    }
036
037    public SurroundingRegion(Diving diving, Pool pool) {
038        this(cuboidFor(diving, pool));
039    }
040
041    @Override
042    public Shape getShape() {
043        return shape;
044    }
045}