| 1 |
# test_Polygon_getLocationOfPoint.praat |
| 2 |
|
| 3 |
eps = 1e-15 |
| 4 |
|
| 5 |
# minimal crossing Polygon |
| 6 |
|
| 7 |
px[1] = 0.123 |
| 8 |
py[1] = 0 |
| 9 |
px[2] = 0.123 |
| 10 |
py[2] = 1 |
| 11 |
px[3] = 1.123 |
| 12 |
py[3] = 0 |
| 13 |
px[4] = 1.123 |
| 14 |
py[4] = 1 |
| 15 |
np = 4 |
| 16 |
|
| 17 |
p = Create simple Polygon... p 'px[1]' 'py[1]' 'px[2]' 'py[2]' 'px[3]' 'py[3]' 'px[4]' 'py[4]' |
| 18 |
|
| 19 |
px[5] = px[1] |
| 20 |
py[5] = py[1] |
| 21 |
|
| 22 |
printline ... x left |
| 23 |
xm = px[1] - 0.1 |
| 24 |
for i to 100 |
| 25 |
ym = randomUniform(py[1]-1, py[2]+1) |
| 26 |
loc$ = Get location of point... xm ym eps |
| 27 |
assert loc$="O"; 'xm' 'ym' |
| 28 |
endfor |
| 29 |
|
| 30 |
printline ... x right |
| 31 |
xm = px[3] + 0.1 |
| 32 |
for i to 100 |
| 33 |
ym = randomUniform(py[1]-1, py[2]+1) |
| 34 |
loc$ = Get location of point... xm ym eps |
| 35 |
assert loc$="O"; 'xm' 'ym' |
| 36 |
endfor |
| 37 |
|
| 38 |
printline ... y top |
| 39 |
ym = py[2] + 0.1 |
| 40 |
for i to 100 |
| 41 |
xm = randomUniform(px[1]-1, px[3]+1) |
| 42 |
loc$ = Get location of point... xm ym eps |
| 43 |
assert loc$="O"; 'xm' 'ym' |
| 44 |
endfor |
| 45 |
|
| 46 |
printline ... y bottom |
| 47 |
ym = py[1] - 0.1 |
| 48 |
for i to 100 |
| 49 |
xm = randomUniform(px[1]-1, px[3]+1) |
| 50 |
loc$ = Get location of point... xm ym eps |
| 51 |
assert loc$="O"; 'xm' 'ym' |
| 52 |
endfor |
| 53 |
|
| 54 |
printline ... vertices |
| 55 |
for i to np |
| 56 |
loc$ = Get location of point... px[i] py[i] eps |
| 57 |
assert loc$ = "V" |
| 58 |
endfor |
| 59 |
|
| 60 |
printline ... edges |
| 61 |
for i to np |
| 62 |
for j to 100 |
| 63 |
f = randomUniform(0,1) |
| 64 |
xm = px[i]+f*(px[i+1]-px[i]) |
| 65 |
ym = py[i] +f*(py[i+1]-py[i]) |
| 66 |
loc$ = Get location of point... xm ym eps |
| 67 |
assert loc$ = "E"; 'xm' 'ym' |
| 68 |
endfor |
| 69 |
endfor |
| 70 |
|
| 71 |
printline ... inside |
| 72 |
for i to 100 |
| 73 |
fx = randomUniform (0,0.5) |
| 74 |
fy = randomUniform (fx, 1-fx) |
| 75 |
xm = px[1]+fx |
| 76 |
ym = py[1]+fy |
| 77 |
loc$ = Get location of point... xm ym eps |
| 78 |
assert loc$ = "I"; 'xm' 'ym' |
| 79 |
fx = 1 - fx |
| 80 |
xm = px[1]+fx |
| 81 |
loc$ = Get location of point... xm ym eps |
| 82 |
assert loc$ = "I"; 'xm' 'ym' |
| 83 |
endfor |
| 84 |
|
| 85 |
printline ... outside |
| 86 |
#could be done better |
| 87 |
for i to 100 |
| 88 |
fx = randomUniform (0,0.5) |
| 89 |
fy = randomUniform (0, fx) |
| 90 |
xm = px[1] + fx |
| 91 |
ym = py[1] + fy |
| 92 |
loc$ = Get location of point... xm ym eps |
| 93 |
assert loc$ = "O"; 'xm' 'ym' |
| 94 |
endfor |
| 95 |
|
| 96 |
select p |
| 97 |
Remove |
| 98 |
# now use epsilon ... |
| 99 |
|
| 100 |
|