summaryrefslogtreecommitdiff
path: root/branches/sm-unittesting/src/org/reprap/geometry/polygons/TestMain.java
blob: 6aeb20bdde3255ac3940c006a9b3da2ce0e567a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

package org.reprap.geometry.polygons;

public class TestMain
{
	public static void fred(String[] args)
	{
		Rr2Point p = new Rr2Point(0.1, 0.15);
		Rr2Point q = new Rr2Point(0.2, 0.85);
		Rr2Point r = new Rr2Point(1, 0.89);
		
		Rr2Point s = new Rr2Point(0.95, 0.03);
		Rr2Point pp = new Rr2Point(0.35, 0.62);
		Rr2Point qq = new Rr2Point(0.55, 0.65);
		Rr2Point rr = new Rr2Point(0.45, 0.5);
		Rr2Point ss = new Rr2Point(0.4, 0.3);    
		RrLine x = new RrLine(new Rr2Point(-1, -1), new Rr2Point(1, 1));
		
		RrPolygon a = new RrPolygon();
		a.append(p, 1);
		a.append(q, 1);
		a.append(r, 1);
		a.append(s, 1);
		
		RrPolygonList c = new RrPolygonList();
		c.append(a);
		
		a = new RrPolygon();
		a.append(rr, 2);
		a.append(qq, 2);
		a.append(pp, 2);
		a.append(ss, 2);
		c.append(a);
		
		RrPolygonList d = c.offset(0.03);
		
		RrPolygon  e = d.hatch(x, 0.03, 3, 4);
		//d = d.offset(0.003);
		//e = e.join_up(d);
		//c.append(d); 
		c.append(e);
		
		new RrGraphics(c, false);
	}
	
	public static void main(String[] args)
	{
		Rr2Point p = new Rr2Point(0.1, 0.15);
		Rr2Point q = new Rr2Point(0.2, 0.85);
		Rr2Point r = new Rr2Point(1, 0.89);
		Rr2Point s = new Rr2Point(0.95, 0.03);
		
		Rr2Point pp = new Rr2Point(0.35, 0.62);
		Rr2Point qq = new Rr2Point(0.55, 0.95);
		Rr2Point rr = new Rr2Point(0.45, 0.5);
		RrLine x = new RrLine(new Rr2Point(-1, -1), new Rr2Point(1, 1));
		
		RrHalfPlane ph = new RrHalfPlane(p, q);
		RrHalfPlane qh = new RrHalfPlane(q, r);
		RrHalfPlane rh = new RrHalfPlane(r, s);
		RrHalfPlane sh = new RrHalfPlane(s, p);
		
		RrHalfPlane pph = new RrHalfPlane(pp, qq);
		RrHalfPlane qqh = new RrHalfPlane(qq, rr);
		RrHalfPlane rrh = new RrHalfPlane(rr, pp);
		
		RrCSG pc = new RrCSG(ph);
		RrCSG qc = new RrCSG(qh);
		RrCSG rc = new RrCSG(rh);
		RrCSG sc = new RrCSG(sh);
		
		pc = RrCSG.intersection(pc, qc);
		rc = RrCSG.intersection(sc, rc);		
		pc = RrCSG.intersection(pc, rc);
		//pc = RrCSG.union(pc, rc); // !!
		
		RrCSG ppc = new RrCSG(pph);
		RrCSG qqc = new RrCSG(qqh);
		RrCSG rrc = new RrCSG(rrh);
		
		
		ppc = RrCSG.intersection(ppc, qqc);
		ppc = RrCSG.intersection(ppc, rrc);
		ppc = RrCSG.difference(pc, ppc);
		
		pc = ppc.offset(-0.15);
		ppc = RrCSG.difference(ppc, pc);
		
		//ppc = RrCSG.union(rc, ppc);
		ppc = RrCSG.union(new RrCSG(ppc), ppc);
		//System.out.println(ppc.toString());
		ppc = ppc.simplify(1.0e-6);
		//System.out.println(ppc.toString());
		//ppc = ppc.regularise();
		//System.out.println(ppc.toString());
		RrCSGPolygon cp = new RrCSGPolygon(ppc, new 
				RrBox(new Rr2Point(0,0), new Rr2Point(1,1)));
		
		cp.divide(1.0e-6, 1.0);
		//System.out.println(cp.toString());
		//new RrGraphics(cp, true);
		
		RrPolygon  h = cp.hatch_join(x, 0.005, 1, 3);
		RrPolygonList hp = new RrPolygonList();
		RrPolygon a = new RrPolygon();
		a.append(p, 5);
		a.append(q, 5);
		a.append(r, 5);
		a.append(s, 5);
		hp.append(h);
		//hp.append(a);
		new RrGraphics(hp, false);  
		
	}
}