Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit a7a72941 authored by Nico Mack's avatar Nico Mack

Added Linear class for manipulation lines in euclidean space

parent 3fecb764
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.utility;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class Linear {
private double slope = Double.NaN;
private double intercept = Double.NaN;
private double constant = Double.NaN;
private LineType type;
private Class<? extends CoordinateState> coordinateClass;
private enum LineType {
OBLIQUE, VERTICAL, HORIZONTAL
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param slope
* @param intercept
*/
// ---------------------------------------------------------------------------
public Linear(double slope, double intercept) {
this.slope = slope;
this.intercept = intercept;
this.type = LineType.OBLIQUE;
this.coordinateClass = CameraCoordinates.class;
}
// ---------------------------------------------------------------------------
public Linear(Point first, Point secnd) {
this.coordinateClass = first.getState().getClass();
Point second = secnd.clone().toCoordinates(this.coordinateClass);
if (second.x == first.x) { // Vertical line
this.constant = first.x;
this.type = LineType.VERTICAL;
} else if (second.y == first.y) { // Horizontal line
this.constant = first.y;
this.type = LineType.HORIZONTAL;
} else {
this.slope = (second.y - first.y) / (second.x - first.x);
this.intercept = -this.slope * first.x;
this.type = LineType.OBLIQUE;
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple getter method for slope.
*
* @return The value of slope.
*/
// ---------------------------------------------------------------------------
public double getSlope() {
return slope;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for slope.
*
* @param slope
* The value to set slope to.
*/
// ---------------------------------------------------------------------------
public void setSlope(double slope) {
this.slope = slope;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for intercept.
*
* @return The value of intercept.
*/
// ---------------------------------------------------------------------------
public double getIntercept() {
return intercept;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for intercept.
*
* @param intercept
* The value to set intercept to.
*/
// ---------------------------------------------------------------------------
public void setIntercept(double intercept) {
this.intercept = intercept;
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public boolean isVertical() {
return this.type == LineType.VERTICAL;
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public boolean isHorizontal() {
return this.type == LineType.HORIZONTAL;
}
// ---------------------------------------------------------------------------
/**
* @param x
* @return
*/
// ---------------------------------------------------------------------------
public double getValueFor(double x) {
if (this.type != LineType.OBLIQUE) {
return this.constant;
}
return this.slope * x + this.intercept;
}
// ---------------------------------------------------------------------------
/**
* @param other
* @return
*/
// ---------------------------------------------------------------------------
public Point intersectionWith(Linear other) {
if ((this.type == LineType.OBLIQUE) && (other.type == LineType.OBLIQUE)) {
double x = (other.intercept - this.intercept) / (this.slope - other.slope);
double y = this.slope * x + this.intercept;
return new Point((float) x, (float) y, 0f, coordinateClass);
}
return null;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment