/*
 * Line.java
 *
 * Created on Štvrtok, 2007, marec 29, 22:26
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pathfinder;

/**
 *
 * @author radu
 */
  
public class Line {
    


public  Point begin;
public  Point end;

public Line(Point begin, Point end){
        this.begin=begin;
        this.end=end;
    }
  public Point intersect(Line other_line)
    {
        float denom = ((other_line.end.getY() - other_line.begin.getY())*(end.getX() - begin.getX())) -
                      ((other_line.end.getX() - other_line.begin.getX())*(end.getY() - begin.getY()));

        float nume_a = ((other_line.end.getX() - other_line.begin.getX())*(begin.getY() - other_line.begin.getY())) -
                       ((other_line.end.getY() - other_line.begin.getY())*(begin.getX() - other_line.begin.getX()));

//        float nume_b = ((end.x - begin.x)*(begin.y - other_line.begin.y)) -
//                       ((end.y - begin.y)*(begin.x - other_line.begin.x));

//        if(denom == 0.0f)
//        {
//            if(nume_a == 0.0f && nume_b == 0.0f)
//            {
//                return COINCIDENT;
//            }
//            return PARALLEL;
//        }

        float ua = nume_a / denom;
//        float ub = nume_b / denom;

//        if(ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f)
//        {
            // Get the intersection point.
            Point intersection=new Point((float)0.0,(float)0.0);
            intersection.setX(begin.getX() + ua*(end.getX() - begin.getX()));
            intersection.setY(begin.getY() + ua*(end.getY() - begin.getY()));

            return intersection;
 //       }

 //       return NOT_INTERESECTING;
    }
}
    

