Hallo!
Habe ein Problem, und zwar hab ich eine Methode geschrieben die ich mit junit testen will!
Kann mir das jemand vereinfachen oder ist das so ok?
Wäre um vorschläge und anregungen dankbar.
import java.text.*;
class CT_Image{
static double berechneSchnittlaenge(double a, double b, double c,
double x1, double x2, double y1, double y2) {
// Variablendeklaration Anfang
int s = 0, t = 0; // Kontrollwerte
double lx1 = 0, lx2 = 0, xs1=0, xs2=0, hx, // x-Koordinaten
by1 = 0, by2 = 0, ys1=0, ys2=0, hy, // y-Koordinaten
w, // Werte der Geradengleichung
h=0; // Schnittlaenge
// Variablendeklaration Ende
// Schnittpunktermittlung
xs1 = (c - b*y1) / a;
xs2 = (c - b*y2) / a;
ys1 = (c - a*x1) / b;
ys2 = (c - a*x2) / b;
// Ermittlung der Rechteck-Schnittpunkte
if(x1 <= xs1 && xs1 <= x2)
{lx1 = xs1; by1 = y1;}
else
if(x1 <= xs2 && xs2 <= x2)
{lx1 = xs2; by1 = y2; s++;}
else
if(y1 <= ys1 && ys1<= y2)
{lx1 = x1; by1 = ys1; t++;}
if(x1 <= xs2 && xs2 <= x2 && s != 1)
{lx2 = xs2; by2 = y2;}
else
if(y1 <= ys1 && ys1 <= y2 && t != 1)
{lx2 = x1; by2 = ys1;}
else
if(y1 <= ys2 && ys2 <= y2)
{lx2 = x2; by2 = ys2;}
// Schnittpunktdifferenz ermitteln
hx = lx1 - lx2;
hy = by1 - by2;
// Satz des Pytagoras
h = (Math.sqrt((hx*hx)+(hy*hy)));
// Rückgabe des Methodenwertes
return h;
}
Habe ein Problem, und zwar hab ich eine Methode geschrieben die ich mit junit testen will!
Kann mir das jemand vereinfachen oder ist das so ok?
Wäre um vorschläge und anregungen dankbar.
import java.text.*;
class CT_Image{
static double berechneSchnittlaenge(double a, double b, double c,
double x1, double x2, double y1, double y2) {
// Variablendeklaration Anfang
int s = 0, t = 0; // Kontrollwerte
double lx1 = 0, lx2 = 0, xs1=0, xs2=0, hx, // x-Koordinaten
by1 = 0, by2 = 0, ys1=0, ys2=0, hy, // y-Koordinaten
w, // Werte der Geradengleichung
h=0; // Schnittlaenge
// Variablendeklaration Ende
// Schnittpunktermittlung
xs1 = (c - b*y1) / a;
xs2 = (c - b*y2) / a;
ys1 = (c - a*x1) / b;
ys2 = (c - a*x2) / b;
// Ermittlung der Rechteck-Schnittpunkte
if(x1 <= xs1 && xs1 <= x2)
{lx1 = xs1; by1 = y1;}
else
if(x1 <= xs2 && xs2 <= x2)
{lx1 = xs2; by1 = y2; s++;}
else
if(y1 <= ys1 && ys1<= y2)
{lx1 = x1; by1 = ys1; t++;}
if(x1 <= xs2 && xs2 <= x2 && s != 1)
{lx2 = xs2; by2 = y2;}
else
if(y1 <= ys1 && ys1 <= y2 && t != 1)
{lx2 = x1; by2 = ys1;}
else
if(y1 <= ys2 && ys2 <= y2)
{lx2 = x2; by2 = ys2;}
// Schnittpunktdifferenz ermitteln
hx = lx1 - lx2;
hy = by1 - by2;
// Satz des Pytagoras
h = (Math.sqrt((hx*hx)+(hy*hy)));
// Rückgabe des Methodenwertes
return h;
}
Zuletzt bearbeitet: