diff options
Diffstat (limited to 'šola/p1/dn')
-rw-r--r-- | šola/p1/dn/Premica.java | 50 | ||||
-rw-r--r-- | šola/p1/dn/Tocka.java | 27 | ||||
-rwxr-xr-x | šola/p1/dn/tj.sh | 11 |
3 files changed, 86 insertions, 2 deletions
diff --git a/šola/p1/dn/Premica.java b/šola/p1/dn/Premica.java new file mode 100644 index 0000000..2d2ec4e --- /dev/null +++ b/šola/p1/dn/Premica.java @@ -0,0 +1,50 @@ +import java.util.*; +public class Premica { + private double k; + private double n; + public Premica(double k, double n) { + this.k = k; + this.n = n; + } + public double vrniK() { + return this.k; + } + public double vrniN() { + return this.n; + } + public String toString() { + return String.format(Locale.ROOT, "y = %.2f x + %.2f", this.k, this.n); + } + public Tocka tockaPriX(double x) { + return new Tocka(x, this.k*x+this.n); + } + public static Premica skoziTocko(double k, Tocka t) { + return new Premica(k, t.vrniY()-k*t.vrniX()); + } + + public Premica vzporednica(Tocka t) { + return skoziTocko(this.k, t); + } + + public Premica pravokotnica(Tocka t) { + return skoziTocko(-1/this.k, t); + } + + public Tocka presecisce(Premica p, double epsilon) { + if (Math.abs(this.k - p.vrniK()) < epsilon) + return null; + return tockaPriX((this.n-p.vrniN())/(p.vrniK()-this.k)); + } + public Tocka projekcija(Tocka t) { + return presecisce(pravokotnica(t), 0); + } + public double razdalja(Tocka t) { + return t.razdalja(projekcija(t)); + } + public double razdaljaOdIzhodisca() { + return Tocka.izhodisce().razdalja(projekcija(Tocka.izhodisce())); + } + public double razdalja(double n) { + return new Premica(this.k, n).razdalja(tockaPriX(0)); + } +} diff --git a/šola/p1/dn/Tocka.java b/šola/p1/dn/Tocka.java new file mode 100644 index 0000000..8dce30b --- /dev/null +++ b/šola/p1/dn/Tocka.java @@ -0,0 +1,27 @@ +import java.util.*; +public class Tocka { + private double x; + private double y; + public Tocka(double x, double y) { + this.x = x; + this.y = y; + } + public double vrniX() { + return this.x; + } + public double vrniY() { + return this.y; + } + public String toString() { + return String.format(Locale.ROOT, "(%.2f, %.2f)", this.x, this.y); + } + public static Tocka izhodisce() { + return new Tocka(0, 0); + } + public double razdalja(Tocka t) { + return Math.sqrt(Math.pow(this.x-t.x, 2)+Math.pow(this.y-t.y, 2)); + } + public double razdaljaOdIzhodisca() { + return izhodisce().razdalja(this); + } +} diff --git a/šola/p1/dn/tj.sh b/šola/p1/dn/tj.sh index 705db03..dcb1270 100755 --- a/šola/p1/dn/tj.sh +++ b/šola/p1/dn/tj.sh @@ -6,11 +6,17 @@ d=$3 uspelih=0 napa=0 predolg=0 -for f in $2/*.in +find $2 -name '*.java' -or -name '*.in' | while read -r f do echo -n "$f ... " uspeh=0 - out=$(timeout 5s /usr/bin/time --quiet -f %E diff --ignore-trailing-space --side-by-side <(java $1 < $f) `sed s/in$/out/ <<<$f` 2>&1) && uspeh=1 + if grep 'java$' <<<$f > /dev/null + then + stdout=`echo <(java $f)` + else + stdout=`echo <(java $1 < $f)` + fi + out=$(timeout 5s /usr/bin/time --quiet -f %E diff --ignore-trailing-space --side-by-side <(java `grep 'java$' <<<$f > /dev/null && echo $f || echo $1` <$f) `sed -e s/in$/out/ -e 's/Test\([0-9]\)/test\1/' -e s/java$/out/ <<<$f` 2>&1) && uspeh=1 koda=$? if [ $uspeh -eq 0 ] then @@ -27,6 +33,7 @@ do tac $f | tac echo "IZHOD: Levo je vaš izhod, desno je pravilen izhod:" head -n-1 <<<$out + grep 'java$' <<<$f > /dev/null && echo "PRIPOROČILO: Če DN zahteva razrede (kot recimo DN06), morate imeti v trenutnem direktoriju PREVEDENE .class datoteke vaših zahtevanih razredov. Če so v katerem drugem direktoriju, morate nastaviti CLASSPATH." fi else uspelih=$(($uspelih+1)) |