package ruum;
import java.lang.Math;
import java.awt.Graphics;

public class Joon extends Ese{
Punkt alg, lopp;
public Joon(Punkt p1, Punkt p2){
alg=(Punkt)p1.clone(); lopp=(Punkt)p2.clone();
}

public Joon(int x1, int y1, int z1, int x2, int y2, int z2){
alg=new Punkt(x1, y1, z1);
lopp=new Punkt(x2, y2, z2);
}

public void joonista(Graphics g){
Punkt a=(Punkt)alg.clone();
Punkt o=(Punkt)lopp.clone();
if(!((a.z>0)&&(o.z>0))){        //kui joone ots on selja taga
 if ((a.z<0)&&(o.z>0)){         //siis teeme joone lu"hemaks.
     a=Punkt.liida(a,Punkt.korruta(Punkt.lahuta(o, a),
                          (double)(5-a.z)/(o.z-a.z))); //5 on 0 asemel 
System.out.println(a.toString());                      //va"ikese varuga
   }
 if ((o.z<0)&&(a.z>0)){
     o=Punkt.liida(o,Punkt.korruta(Punkt.lahuta(a, o),
                                   (double)(5-o.z)/(a.z-o.z)));
   }
}

if((a.z>0)&&(o.z>0)){
g.drawLine(Math.round(a.x*grtegur/a.z),
           Math.round(-a.y*grtegur/a.z), 
           Math.round(o.x*grtegur/o.z),
           Math.round(-o.y*grtegur/o.z));}
}

public Object clone(){
Joon j=new Joon(alg, lopp);
 return j;
}

public String toString(){return alg.toString()+"; "+lopp.toString();}
}

