All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.gse.map.BranchGraphic Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
/**
 * Copyright (c) 2018, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.gse.map;

import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.powsybl.commons.PowsyblException;

import java.util.List;
import java.util.Objects;

/**
 * @author Geoffroy Jamgotchian 
 */
public class BranchGraphic implements IndexableGraphic {

    private final List pylons;

    private final LineGraphic line;

    public BranchGraphic(List pylons, LineGraphic line) {
        this.pylons = Objects.requireNonNull(pylons);
        if (pylons.isEmpty()) {
            throw new PowsyblException("Empty poly segment");
        }
        this.line = Objects.requireNonNull(line);
    }

    public List getPylons() {
        return pylons;
    }

    public LineGraphic getLine() {
        return line;
    }

    @Override
    public Rectangle getBoundingBox() {
        double minLon = Double.MAX_VALUE;
        double minLat = Double.MAX_VALUE;
        double maxLon = Double.MIN_VALUE;
        double maxLat = Double.MIN_VALUE;
        for (PylonGraphic pylon : pylons) {
            Coordinate c = pylon.getCoordinate();
            minLon = Math.min(minLon, c.getLon());
            minLat = Math.min(minLat, c.getLat());
            maxLon = Math.max(maxLon, c.getLon());
            maxLat = Math.max(maxLat, c.getLat());
        }
        return Geometries.rectangleGeographic(minLon, minLat, maxLon, maxLat);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy