/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.features.slaves.laufbau;

import de.steamwar.bausystem.region.Point;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Cuboid {
    private double x;
    private double y;
    private double z;
    private double dx;
    private double dy;
    private double dz;

    public boolean intersects(Cuboid cuboid) {
        double minx = x - cuboid.dx;
        double miny = y - cuboid.dy;
        double minz = z - cuboid.dz;
        double maxx = minx + dx + cuboid.dx;
        double maxy = miny + dy + cuboid.dy;
        double maxz = minz + dz + cuboid.dz;
        return maxx > cuboid.x && maxy > cuboid.y && maxz > cuboid.z && minx < cuboid.x && miny < cuboid.y && minz < cuboid.z;
    }

    public double volume() {
        return dx * dy * dz;
    }

    public Cuboid add(Point point) {
        return new Cuboid(x + point.getX(), y + point.getY(), z + point.getZ(), dx, dy, dz);
    }
}
