Segment finis
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
package TD3.segment;
|
||||
|
||||
/********************************************************************************************
|
||||
* @author JunkJumper *
|
||||
* @license https://creativecommons.org/licenses/by/4.0/ License CC BY 4.0 *
|
||||
* @since File available since 24/05/2020 *
|
||||
********************************************************************************************/
|
||||
|
||||
import TD1.point.Point;
|
||||
import TD9.comparable.main;
|
||||
|
||||
@ -11,29 +17,26 @@ public class Segment {
|
||||
this(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public Segment(int xi, int yi, int xj, int yj) {
|
||||
public Segment(double xi, double yi, double xj, double yj) {
|
||||
this.origine = new Point(xi, yi);
|
||||
this.extremite = new Point(xj, yj);
|
||||
}
|
||||
|
||||
public Segment(Point o, Point e) {
|
||||
this.setOrigine(o);
|
||||
this.setExtremite(e);
|
||||
this(o.getX(), o.getY(), e.getX(), e.getY());
|
||||
}
|
||||
|
||||
public Segment(int x, int y, Point p) {
|
||||
this.setOrigine(x, y);
|
||||
this.setExtremite(p);
|
||||
public Segment(double x, double y, Point p) {
|
||||
this(x, y, p.getX(), p.getY());
|
||||
}
|
||||
|
||||
public Segment(Point p, int x, int y) {
|
||||
this.setOrigine(p);
|
||||
this.setExtremite(x, y);
|
||||
public Segment(Point p, double x, double y) {
|
||||
this(p.getX(), p.getY(), x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
Segment s = (Segment)obj;
|
||||
Segment s = (Segment) obj;
|
||||
return (this.origine.equals(s.origine) && this.extremite.equals(s.extremite));
|
||||
}
|
||||
|
||||
@ -47,6 +50,14 @@ public class Segment {
|
||||
return new Segment(this.origine, this.getExtremite());
|
||||
}
|
||||
|
||||
public Segment projX() {
|
||||
return new Segment(this.origine.projX(), this.extremite.projX());
|
||||
}
|
||||
|
||||
public Segment projY() {
|
||||
return new Segment(this.origine.projY(), this.extremite.projY());
|
||||
}
|
||||
|
||||
public Point getOrigine() {
|
||||
return origine;
|
||||
}
|
||||
@ -71,15 +82,4 @@ public class Segment {
|
||||
this.setExtremite(new Point(x, y));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Point un = new Point(3, 6);
|
||||
Point deux = new Point(1, 8);
|
||||
Segment seg1 = new Segment(2, 4, 6, 3);
|
||||
Segment seg2 = new Segment(un, deux);
|
||||
|
||||
System.out.println(seg1.toString());
|
||||
System.out.println(seg2.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class SegmentTest {
|
||||
|
||||
private Point un = new Point(3, 6);
|
||||
private Point deux = new Point(1, 8);
|
||||
|
||||
private Segment seg1 = new Segment(2, 4, 6, 3);
|
||||
private Segment seg2 = new Segment(un, deux);
|
||||
private Segment seg3 = new Segment(1, 6, un);
|
||||
@ -43,4 +44,16 @@ public class SegmentTest {
|
||||
s = (Segment) seg3.clone();
|
||||
assertTrue(s.equals(seg3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjX() {
|
||||
Segment s = new Segment(2, 0, 6, 0);
|
||||
assertEquals(s, seg1.projX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjY() {
|
||||
Segment s = new Segment(0, 4, 0, 3);
|
||||
assertEquals(s, seg1.projY());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user