com.powsybl.diagram.util.forcelayout.Vector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-diagram-util Show documentation
Show all versions of powsybl-diagram-util Show documentation
Force layout for PowSyBl Diagram
/**
* Copyright (c) 2021, 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.diagram.util.forcelayout;
/**
* @author Mathilde Grapin {@literal }
*/
public class Vector {
private final double x;
private final double y;
public Vector(double x, double y) {
this.x = x;
this.y = y;
}
public Vector add(Vector otherVector) {
return new Vector(x + otherVector.getX(), y + otherVector.getY());
}
public Vector subtract(Vector otherVector) {
return new Vector(x - otherVector.getX(), y - otherVector.getY());
}
public Vector multiply(double scalar) {
return new Vector(x * scalar, y * scalar);
}
public Vector divide(double scalar) {
return new Vector(x / scalar, y / scalar);
}
public double magnitude() {
return Math.sqrt(x * x + y * y);
}
public double magnitudeSquare() {
return x * x + y * y;
}
public Vector normalize() {
return this.divide(this.magnitude());
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}