test_Polygon_getLocationOfPoint.praat 1.9 KB

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