at.entenbaer.utils.TPALine.java Source code

Java tutorial

Introduction

Here is the source code for at.entenbaer.utils.TPALine.java

Source

/**
 * This file is part of TexturePoemApp.
 * Created by Matthias Perkonigg, 2015.
 * TexturePoemApp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *   
 *  TexturePoemApp 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TexturePoemApp.  If not, see <http://www.gnu.org/licenses/>.
 */

package at.entenbaer.utils;

import org.opencv.core.Point;

import java.util.Comparator;

/**
 * Class that reprsents a line with a start and an end point
 */
public class TPALine implements Comparable<TPALine> {

    private Point startP;
    private Point endP;

    public TPALine(Point startP, Point endP) {
        this.startP = startP;
        this.endP = endP;
    }

    public TPALine(int startX, int startY, int endX, int endY) {
        this.startP = new Point(startX, startY);
        this.endP = new Point(endX, endY);
    }

    public Point getEndP() {
        return endP;
    }

    public Point getStartP() {
        return startP;
    }

    public void setEndP(Point endP) {
        this.endP = endP;
    }

    public void setStartP(Point startP) {
        this.startP = startP;
    }

    public Point getMidpoint() {
        return new Point((this.getStartP().x + this.getEndP().x) / 2, (this.getStartP().y + this.getEndP().y) / 2);
    }

    public double getDistance() {
        return Math.sqrt(Math.pow((endP.x - startP.x), 2.0) + Math.pow((endP.y - startP.y), 2.0));
    }

    @Override
    public int compareTo(TPALine another) {
        return (int) (this.startP.y - another.startP.y);
    }
}