]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/shisensho/Line.java
a1a7681319d8293e34aa1efba3f67421496d758b
[FreeShisen] / src / de / cwde / shisensho / Line.java
1 package de.cwde.shisensho;
2
3 public class Line {
4 public Line(Point a, Point b) {
5 this.a=a;
6 this.b=b;
7 }
8
9 public boolean equals(Line l) {
10 return (a.equals(l.a) && b.equals(l.b));
11 }
12
13 public boolean isHorizontal() {
14 return (a.i==b.i);
15 }
16
17 public boolean isVertical() {
18 return (a.j==b.j);
19 }
20
21 public boolean contains(Point p) {
22 return (p.i==a.i && p.i==b.i && p.j>=getMin().j && p.j<=getMax().j)
23 || (p.j==a.j && p.j==b.j && p.i>=getMin().i && p.i<=getMax().i);
24 }
25
26 public Point cuts(Line l) {
27 if (isHorizontal() && l.isVertical()
28 && getMin().j<=l.a.j && getMax().j>=l.a.j
29 && l.getMin().i<=a.i && l.getMax().i>=a.i ) {
30 return new Point(a.i,l.a.j);
31 } else if (isVertical() && l.isHorizontal()
32 && getMin().i<=l.a.i && getMax().i>=l.a.i
33 && l.getMin().j<=a.j && l.getMax().j>=a.j ) {
34 return new Point(l.a.i,a.j);
35 } else return null;
36 }
37
38 public Point getMin() {
39 if (a.i<b.i || a.j<b.j) return a;
40 else return b;
41 }
42
43 public Point getMax() {
44 if (a.i>b.i || a.j>b.j) return a;
45 else return b;
46 }
47
48 public String toString() {
49 return a+"-"+b;
50 }
51
52 public Point a;
53 public Point b;
54 }
Impressum, Datenschutz