testGeom_Poly.f90 122 KB
Newer Older
1
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
2
3
4
5
6
7
!                          Futility Development Group                          !
!                             All rights reserved.                             !
!                                                                              !
! Futility is a jointly-maintained, open-source project between the University !
! of Michigan and Oak Ridge National Laboratory.  The copyright and license    !
! can be found in LICENSE.txt in the head directory of this repository.        !
8
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
9
PROGRAM testGeom_Poly
10
#include "UnitTest.h"
Graham, Aaron's avatar
Graham, Aaron committed
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
USE ISO_FORTRAN_ENV
USE UnitTest
USE IntrType
USE Constants_Conversion
USE ParameterLists
USE Geom_Points
USE Geom_Line
USE Geom_CircCyl
USE Geom_Box
USE Geom_Graph
USE Geom_Poly

IMPLICIT NONE

LOGICAL(SBK) :: bool
TYPE(GraphType) :: testGraph

CREATE_TEST('GEOM_POLY')
CALL eParams%setQuietMode(.TRUE.)
CALL eParams%setStopOnError(.FALSE.)

REGISTER_SUBTEST('Uninitialized',testUninit)
REGISTER_SUBTEST('%clear',testClear)
REGISTER_SUBTEST('%set',testSet)
REGISTER_SUBTEST('Polygonize',testPolygonize)
REGISTER_SUBTEST('%isCircle',testIsCircle)
REGISTER_SUBTEST('%getRadius',testGetRadius)
REGISTER_SUBTEST('%isSector',testIsSector)
REGISTER_SUBTEST('%isSection',testIsSection)
REGISTER_SUBTEST('%getInnerRadius',testGetInnerRadius)
REGISTER_SUBTEST('%getOuterRadius',testGetOuterRadius)
REGISTER_SUBTEST('%generateGraph',testGenerateGraph)
REGISTER_SUBTEST('%intersectLine',testIntersectLine)
REGISTER_SUBTEST('%doesLineIntersect',testDoesLineIntersect)
REGISTER_SUBTEST('%onSurface',testPointOnSurface)
REGISTER_SUBTEST('%pointInside',testPointInside)
REGISTER_SUBTEST('%boundsPoly',testPolyInside)
REGISTER_SUBTEST('%doesPolyIntersect',testDoesPolyIntersect)
REGISTER_SUBTEST('%subtractSubVolume',testSubtractSubVol)
REGISTER_SUBTEST('Operator(==)',testEquivalence)
51
REGISTER_SUBTEST('Assignment(=)',testAssignment)
52
REGISTER_SUBTEST('RotateClockwise',testRotateClockwise)
53
REGISTER_SUBTEST('averageVertexDistance',testAverageVertexDistance)
Graham, Aaron's avatar
Graham, Aaron committed
54
55

FINALIZE_TEST()
56
57
!
!===============================================================================
Graham, Aaron's avatar
Graham, Aaron committed
58
CONTAINS
59
60
!
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
61
62
63
64
65
66
67
68
69
70
71
SUBROUTINE testUninit()
  TYPE(PolygonType) :: testPolyType
  ASSERT(.NOT.testPolyType%isinit,'%isinit')
  ASSERT(testPolyType%area .APPROXEQA. 0.0_SRK,'%area')
  ASSERT(testPolyType%nVert == 0,'%nVert')
  ASSERT(testPolyType%nQuadEdge == 0,'%nQuadEdge')
  ASSERT(.NOT.ALLOCATED(testPolyType%vert),'%vert')
  ASSERT(.NOT.ALLOCATED(testPolyType%edge),'%edge')
  ASSERT(.NOT.ALLOCATED(testPolyType%quad2edge),'%quad2edge')
  ASSERT(.NOT.ALLOCATED(testPolyType%quadEdge),'%quadEdge')
ENDSUBROUTINE testUninit
72
73
!
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
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
SUBROUTINE testClear()
  TYPE(PolygonType) :: testPolyType
  !init by hand
  testPolyType%isinit=.TRUE.
  ALLOCATE(testPolyType%vert(3))
  CALL testPolyType%vert(1)%init(DIM=2,X=-1.5_SRK,Y=-1.5_SRK)
  CALL testPolyType%vert(2)%init(DIM=2,X=1.5_SRK,Y=-1.5_SRK)
  CALL testPolyType%vert(3)%init(DIM=2,X=0.0_SRK,Y=2.5_SRK)
  ALLOCATE(testPolyType%edge(2,3))
  testPolyType%edge(:,1)=(/1,2/)
  testPolyType%edge(:,2)=(/2,3/)
  testPolyType%edge(:,3)=(/3,1/)
  ALLOCATE(testPolyType%quadEdge(3,3))
  testPolyType%quadEdge=1.0_SRK
  testPolyType%nVert=3
  testPolyType%nQuadEdge=3
  testPolyType%area=6.0_SRK

  CALL testPolyType%clear()
  CALL testUninit()

  !Redundant Call
  CALL testPolyType%clear()

ENDSUBROUTINE testClear
99
100
!
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
SUBROUTINE testSet()
  TYPE(PolygonType) :: testPolyType
  INTEGER(SIK) :: i
  REAL(SRK) :: testCoord(2,9),c0(2)
  TYPE(PolygonType) :: refRect

  !Setup test graph - isosceles triangle
  testCoord(:,1)=(/-1.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,-2.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,1.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))

  !inext=testGraph%getCCWMostVert(1,0) !3
  !inext=testGraph%getCCWMostVert(1,3) !2
  !inext=testGraph%getCCWMostVert(3,2) !1
  !inext=testGraph%getCCWMostVert(2,1) !3
  !inext=testGraph%getCWMostVert(0,1) !2
  !inext=testGraph%getCWMostVert(1,2) !3
  !inext=testGraph%getCWMostVert(2,3) !1
  !inext=testGraph%getCWMostVert(3,1) !2

  CALL testPolyType%set(testGraph)
  ASSERT(testPolyType%isinit,'triangle %isinit')
  bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  ASSERT(bool,'triangle %vert(1)')
  bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,3))
  ASSERT(bool,'triangle %vert(2)')
  bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,2))
  ASSERT(bool,'triangle %vert(3)')
  ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'triangle %edge(:,1)')
  ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'triangle %edge(:,2)')
  ASSERT(ALL(testPolyType%edge(:,3) == (/3,1/)),'triangle %edge(:,3)')
  ASSERT(testPolyType%area .APPROXEQA. 3.0_SRK,'%area')
  bool=(testPolyType%centroid%coord(1) .APPROXEQA. 0.0_SRK) .AND. &
      (testPolyType%centroid%coord(2) .APPROXEQA. -1.0_SRK)
  ASSERT(bool,'%centroid')

  CALL testGraph%clear()
  CALL testPolyType%clear()
  !Setup test graph - rectangle
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,4.0_SRK/)
  testCoord(:,3)=(/1.0_SRK,4.0_SRK/)
  testCoord(:,4)=(/1.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))

  CALL testPolyType%set(testGraph)
  ASSERT(testPolyType%isinit,'rectangle %isinit')
  bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  ASSERT(bool,'rectangle %vert(1)')
  bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,2))
  ASSERT(bool,'rectangle %vert(2)')
  bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,3))
  ASSERT(bool,'rectangle %vert(3)')
  bool=ALL(testPolyType%vert(4)%coord .APPROXEQA. testCoord(:,4))
  ASSERT(bool,'rectangle %vert(4)')
  ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'rectangle %edge(:,1)')
  ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'rectangle %edge(:,2)')
  ASSERT(ALL(testPolyType%edge(:,3) == (/3,4/)),'rectangle %edge(:,3)')
  ASSERT(ALL(testPolyType%edge(:,4) == (/4,1/)),'rectangle %edge(:,4)')
  ASSERT(testPolyType%area .APPROXEQA. 18.0_SRK,'%area')
  bool=(testPolyType%centroid%coord(1) .APPROXEQA. -0.5_SRK) .AND. &
      (testPolyType%centroid%coord(2) .APPROXEQA. 1.0_SRK)
  ASSERT(bool,'%centroid')

  refRect%isInit=.TRUE.
  refRect%area=6.0_SRK*3.0_SRK
  refRect%nVert=4
  ALLOCATE(refRect%vert(4))
  DO i=1,4
    CALL refRect%vert(i)%init(COORD=testCoord(:,i))
  ENDDO
  ALLOCATE(refRect%edge(2,4))
  refRect%edge(:,1)=(/1,2/)
  refRect%edge(:,2)=(/2,3/)
  refRect%edge(:,3)=(/3,4/)
  refRect%edge(:,4)=(/4,1/)
  refRect%nQuadEdge=0
190
191
  ALLOCATE(refRect%quadEdge(3,0))
  ALLOCATE(refRect%quad2edge(0))
Graham, Aaron's avatar
Graham, Aaron committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  CALL refRect%centroid%init(COORD=(/-0.5_SRK,1.0_SRK/))
  bool=(testPolyType == refRect)
  ASSERT(bool,'== rectangle')

  CALL testGraph%clear()
  CALL testPolyType%clear()
  !Setup test graph - square with a full circle
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  c0=(/0.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
207
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
208
      testCoord(:,2),c0,SQRT(8.0_SRK))
209
  CALL testGraph%defineEdge(testCoord(:,2), &
Graham, Aaron's avatar
Graham, Aaron committed
210
      testCoord(:,3),c0,SQRT(8.0_SRK))
211
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
212
      testCoord(:,4),c0,SQRT(8.0_SRK))
213
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
      testCoord(:,1),c0,SQRT(8.0_SRK))

  CALL testPolyType%set(testGraph)
  ASSERT(testPolyType%isinit,'rectangle %isinit')
  bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  ASSERT(bool,'square-circ %vert(1)')
  bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,2))
  ASSERT(bool,'square-circ %vert(2)')
  bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,3))
  ASSERT(bool,'square-circ %vert(3)')
  bool=ALL(testPolyType%vert(4)%coord .APPROXEQA. testCoord(:,4))
  ASSERT(bool,'square-circ %vert(4)')
  ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'square-circ %edge(:,1)')
  ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'square-circ %edge(:,2)')
  ASSERT(ALL(testPolyType%edge(:,3) == (/3,4/)),'square-circ %edge(:,3)')
  ASSERT(ALL(testPolyType%edge(:,4) == (/4,1/)),'square-circ %edge(:,4)')
  bool=ALL(testPolyType%quadEdge(:,1) .APPROXEQA. &
      (/0.0_SRK,0.0_SRK, SQRT(8.0_SRK)/))
  ASSERT(bool,'square-circ %quadEdge(:,1)')
  bool=ALL(testPolyType%quadEdge(:,2) .APPROXEQA. &
      (/0.0_SRK,0.0_SRK, SQRT(8.0_SRK)/))
  ASSERT(bool,'square-circ %quadEdge(:,2)')
  bool=ALL(testPolyType%quadEdge(:,3) .APPROXEQA. &
      (/0.0_SRK,0.0_SRK, SQRT(8.0_SRK)/))
  ASSERT(bool,'square-circ %quadEdge(:,3)')
  bool=ALL(testPolyType%quadEdge(:,4) .APPROXEQA. &
      (/0.0_SRK,0.0_SRK, SQRT(8.0_SRK)/))
  ASSERT(bool,'square-circ %quadEdge(:,4)')
  ASSERT(testPolyType%area .APPROXEQA. 25.13274122871835_SRK,'%area')
  bool=(testPolyType%centroid%coord(1) .APPROXEQA. 0.0_SRK) .AND. &
      (testPolyType%centroid%coord(2) .APPROXEQA. 0.0_SRK)
  ASSERT(bool,'%centroid')

  !CALL testGraph%clear()
  !CALL testPolyType%clear()
  !!Setup test graph - square with a half circle
  !testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  !testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  !testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  !testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  !c0(2)=(/2.0_SRK,0.0_SRK/)
  !DO i=1,4
  !  CALL testGraph%insertVertex(testCoord(:,i))
  !ENDDO
  !CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  !CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  !CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  !CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
262
  !CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  !  testCoord(:,4),c0,2.0_SRK)
  !
  !CALL testPolyType%set(testGraph)
  !ASSERT(testPolyType%isinit,'rectangle %isinit')
  !bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  !ASSERT(bool,'square-quad %vert(1)')
  !bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,2))
  !ASSERT(bool,'square-quad %vert(2)')
  !bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,3))
  !ASSERT(bool,'square-quad %vert(3)')
  !bool=ALL(testPolyType%vert(4)%coord .APPROXEQA. testCoord(:,4))
  !ASSERT(bool,'square-quad %vert(4)')
  !ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'square-quad %edge(:,1)')
  !ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'square-quad %edge(:,2)')
  !ASSERT(ALL(testPolyType%edge(:,3) == (/3,4/)),'square-quad %edge(:,3)')
  !ASSERT(ALL(testPolyType%edge(:,4) == (/4,1/)),'square-quad %edge(:,4)')
  !bool=ALL(testPolyType%quadEdge(:,3) .APPROXEQA. &
  !  (/2.0_SRK,0.0_SRK,2.0_SRK/))
  !ASSERT(bool,'square-quad %quadEdge(:,3)')
  !ASSERT(testPolyType%area .APPROXEQA. 16.0_SRK+TWOPI,'%area')

  CALL testGraph%clear()
  CALL testPolyType%clear()
  !Setup test graph - square with a circle to subtract
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  c0=(/4.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
298
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
      testCoord(:,4),c0,SQRT(8.0_SRK))
  CALL testPolyType%set(testGraph)
  ASSERT(testPolyType%isinit,'rectangle %isinit')
  bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  ASSERT(bool,'square-quad %vert(1)')
  bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,2))
  ASSERT(bool,'square-quad %vert(2)')
  bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,3))
  ASSERT(bool,'square-quad %vert(3)')
  bool=ALL(testPolyType%vert(4)%coord .APPROXEQA. testCoord(:,4))
  ASSERT(bool,'square-quad %vert(4)')
  ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'square-quad %edge(:,1)')
  ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'square-quad %edge(:,2)')
  ASSERT(ALL(testPolyType%edge(:,3) == (/3,4/)),'square-quad %edge(:,3)')
  ASSERT(ALL(testPolyType%edge(:,4) == (/4,1/)),'square-quad %edge(:,4)')
  bool=ALL(testPolyType%quadEdge(:,1) .APPROXEQA. &
      (/4.0_SRK,0.0_SRK,SQRT(8.0_SRK)/))
  ASSERT(bool,'square-quad %quadEdge(:,1)')
  ASSERT(testPolyType%area .APPROXEQA. 16.0_SRK-2.28318530717959_SRK,'%area')
  bool=(testPolyType%centroid%coord(1) .APPROXEQA. -0.27698908095432_SRK) .AND. &
      (testPolyType%centroid%coord(2) .APPROXEQA. 0.0_SRK)
  ASSERT(bool,'%centroid')
  FINFO() testPolyType%centroid%coord

  CALL testGraph%clear()
  CALL testPolyType%clear()
  !Setup test graph - square with a circle to subtract
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  c0=(/0.0_SRK,0.0_SRK/)
334
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2), &
Graham, Aaron's avatar
Graham, Aaron committed
335
336
337
338
      c0,SQRT(8.0_SRK))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  c0=(/4.0_SRK,0.0_SRK/)
339
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
340
341
342
      testCoord(:,4),c0,SQRT(8.0_SRK))

  CALL testPolyType%set(testGraph)
343
  ASSERT(testPolyType%isinit,'rectangle %isinit')
Graham, Aaron's avatar
Graham, Aaron committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
  bool=ALL(testPolyType%vert(1)%coord .APPROXEQA. testCoord(:,1))
  ASSERT(bool,'square-2quad %vert(1)')
  bool=ALL(testPolyType%vert(2)%coord .APPROXEQA. testCoord(:,2))
  ASSERT(bool,'square-2quad %vert(2)')
  bool=ALL(testPolyType%vert(3)%coord .APPROXEQA. testCoord(:,3))
  ASSERT(bool,'square-2quad %vert(3)')
  bool=ALL(testPolyType%vert(4)%coord .APPROXEQA. testCoord(:,4))
  ASSERT(bool,'square-2quad %vert(4)')
  ASSERT(ALL(testPolyType%edge(:,1) == (/1,2/)),'square-2quad %edge(:,1)')
  ASSERT(ALL(testPolyType%edge(:,2) == (/2,3/)),'square-2quad %edge(:,2)')
  ASSERT(ALL(testPolyType%edge(:,3) == (/3,4/)),'square-2quad %edge(:,3)')
  ASSERT(ALL(testPolyType%edge(:,4) == (/4,1/)),'square-2quad %edge(:,4)')
  bool=ALL(testPolyType%quadEdge(:,1) .APPROXEQA. &
      (/0.0_SRK,0.0_SRK,SQRT(8.0_SRK)/))
  ASSERT(bool,'square-2quad %quadEdge(:,1)')
  bool=ALL(testPolyType%quadEdge(:,2) .APPROXEQA. &
      (/4.0_SRK,0.0_SRK,SQRT(8.0_SRK)/))
  ASSERT(bool,'square-2quad %quadEdge(:,2)')
  ASSERT(testPolyType%area .APPROXEQA. 16.0_SRK,'%area')
   bool=(testPolyType%centroid%coord(1) .APPROXEQA. -0.5707963267949_SRK) .AND. &
      (testPolyType%centroid%coord(2) .APPROXEQA. 0.0_SRK)
   ASSERT(bool,'%centroid')
   FINFO() testPolyType%centroid%coord

  CALL testGraph%clear()
  CALL testPolyType%clear()
ENDSUBROUTINE testSet
371
!
372
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
SUBROUTINE testSubtractSubVol()
  TYPE(PolygonType) :: testPolyType
  INTEGER(SIK) :: i
  REAL(SRK) :: testCoord(2,9)
  TYPE(PolygonType) :: testPoly2,testPoly3,testPoly4

  !Case 1, subtract itself
  !Setup test graph - quadralateral
  CALL testGraph%clear()
  CALL testPolyType%clear()
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,3.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,3.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
395
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
  CALL testPolyType%subtractSubVolume(testPolyType)
  ASSERT(.NOT.ASSOCIATED(testPolyType%subRegions),'%subRegions')
  ASSERT(testPolyType%area .APPROXEQA. 20.0_SRK,'%area')
  bool=ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.5_SRK/))
  ASSERT(bool,'%centroid')

  !Case 4, subtract a valid subregion
  CALL testGraph%clear()
  !Setup test graph - isosceles triangle
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,-1.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,2.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)

  !Triangle is fully inside quadralateral
417
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
418
419
  CALL testPolyType%subtractSubVolume(testPoly2)
  !Test valid subtractSubVolume
420
  ASSERT(ASSOCIATED(testPolyType%subRegions),'%subRegions')
Graham, Aaron's avatar
Graham, Aaron committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
  ASSERT(testPolyType%subRegions == testPoly2,'equivalence of %subRegions')
  ASSERT(testPolyType%area .APPROXEQA. 17.0_SRK,'%area')
  ASSERT(ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.5882352941176471_SRK/)),'%centroid')
  testPolyType%area=testPolyType%area+testPolyType%subRegions%area
  testPolyType%centroid%coord(2)=0.5_SRK
  CALL testPolyType%subRegions%clear()
  testPolyType%subRegions => NULL()

  !Case 2, subtract a rectangle that shares an edge with the polygon
  CALL testPoly2%clear()
  CALL testGraph%clear()
  !Setup test graph - colinear rectangle
  testCoord(:,1)=(/0.0_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,1.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,1.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly2%set(testGraph)
  !rectangle shares an edge with quadralateral
446
447
  ASSERT(testPolyType%isinit,'%isinit')
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
  CALL testPolyType%subtractSubVolume(testPoly2)
  ASSERT(.NOT.ASSOCIATED(testPolyType%subRegions),'%subRegions')

  !Case 8, subtracting a rectangle that intersects with other subregions
  CALL testGraph%clear()
  !Setup test graph - rectangle
  testCoord(:,1)=(/-0.5_SRK,-0.5_SRK/)
  testCoord(:,2)=(/-0.5_SRK,2.5_SRK/)
  testCoord(:,3)=(/0.5_SRK,2.5_SRK/)
  testCoord(:,4)=(/0.5_SRK,-0.5_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly4%set(testGraph)
  CALL testPolyType%subtractSubVolume(testPoly4)
  bool=.NOT.ASSOCIATED(testPolyType%subRegions%nextPoly)
  ASSERT(bool,'%subRegions%nextPoly')

  !Case 6, subtracting a smaller rectangle within a larger subregions
  !Reinit base polygon
  CALL testGraph%clear()
  CALL testPoly2%clear()
  CALL testPoly3%clear()
  CALL testPoly4%clear()
  CALL testPolyType%clear()
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,3.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,3.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
489
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
  CALL testGraph%clear()
  !Setup test graph - rectangle
  testCoord(:,1)=(/-1.0_SRK,1.0_SRK/)
  testCoord(:,2)=(/-1.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/1.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/1.0_SRK,1.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly2%set(testGraph)
504
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
  CALL testPolyType%subtractSubVolume(testPoly2)
  ASSERT(ASSOCIATED(testPolyType%subRegions),'%subRegions')
  ASSERT(testPolyType%area .APPROXEQA. 18.0_SRK,'%area')
  bool=ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.3888888888888889_SRK/))
  ASSERT(bool,'%centroid')

  !Setup test graph - rectangle
  CALL testGraph%clear()
  testCoord(:,1)=(/-0.5_SRK,1.1_SRK/)
  testCoord(:,2)=(/-0.5_SRK,1.9_SRK/)
  testCoord(:,3)=(/0.5_SRK,1.9_SRK/)
  testCoord(:,4)=(/0.5_SRK,1.1_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly3%set(testGraph)
525
  ASSERT(testPoly3%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  CALL testPolyType%subtractSubVolume(testPoly3)
  ASSERT(.NOT.ASSOCIATED(testPolyType%subRegions%nextPoly),'%subRegions%nextPoly')

  !Case 9, subtracting a larger rectangle over a two smaller subregions
  CALL testPoly3%clear()
  CALL testGraph%clear()
  !Setup test graph - rectangle
  testCoord(:,1)=(/-0.5_SRK,-1.0_SRK/)
  testCoord(:,2)=(/-0.5_SRK,0.0_SRK/)
  testCoord(:,3)=(/0.5_SRK,0.0_SRK/)
  testCoord(:,4)=(/0.5_SRK,-1.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly3%set(testGraph)
545
  ASSERT(testPoly3%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
  CALL testPolyType%subtractSubVolume(testPoly3)
  ASSERT(ASSOCIATED(testPolyType%subRegions),'%subRegions')
  ASSERT(ASSOCIATED(testPolyType%subRegions%nextPoly),'%subRegions%nextPoly')
  ASSERT(testPolyType%area .APPROXEQA. 17.0_SRK,'%area')
  bool=ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.4411764705882353_SRK/))
  ASSERT(bool,'%centroid')

  CALL testGraph%clear()
  !Setup test graph - rectangle
  testCoord(:,1)=(/-1.5_SRK,-1.25_SRK/)
  testCoord(:,2)=(/-1.5_SRK,2.75_SRK/)
  testCoord(:,3)=(/1.5_SRK,2.75_SRK/)
  testCoord(:,4)=(/1.5_SRK,-1.25_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly4%set(testGraph)
567
  ASSERT(testPoly4%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
568
569
570
571
572
573
574
575
576
577
  CALL testPolyType%subtractSubVolume(testPoly4)
  ASSERT(ASSOCIATED(testPolyType%subRegions),'%subRegions')
  ASSERT(.NOT.ASSOCIATED(testPolyType%subRegions%nextPoly),'%subRegions%nextPoly')
  ASSERT(testPolyType%area .APPROXEQA. 8.0_SRK,'%area')
  bool=ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.125_SRK/))
  ASSERT(bool,'%centroid')

  CALL testPoly2%clear()
  CALL testPolyType%clear()
ENDSUBROUTINE testSubtractSubVol
578
!
579
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
SUBROUTINE testPointOnSurface()
  TYPE(PolygonType) :: testPolyType
  INTEGER(SIK) :: i
  REAL(SRK) :: testCoord(2,9),c0(2)
  TYPE(PointType) :: point
  TYPE(PolygonType),TARGET :: testPoly2

  !Case 1, subtract itself
  !Setup test graph - quadralateral
  CALL testGraph%clear()
  CALL testPolyType%clear()
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,3.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,3.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
603
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
  CALL testPolyType%subtractSubVolume(testPolyType)
  ASSERT(.NOT.ASSOCIATED(testPolyType%subRegions),'%subRegions')
  ASSERT(testPolyType%area .APPROXEQA. 20.0_SRK,'%area')
  bool=ALL(testPolyType%centroid%coord .APPROXEQA. (/0.0_SRK,0.5_SRK/))
  ASSERT(bool,'%centroid')

  !Case 4, subtract a valid subregion
  CALL testGraph%clear()
  !Setup test graph - isosceles triangle
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,-1.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,2.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  c0=(/0.0_SRK,1.0_SRK/)
622
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
623
624
625
626
      testCoord(:,2),c0,SQRT(5.0_SRK))
  CALL testPoly2%set(testGraph)

  !Triangle is fully inside quadralateral
627
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
  testPolyType%subregions => testPoly2

  !Outer surfaces
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.0_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%onSurface(point),'West Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.1_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond West Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.9_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside West Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=3.0_SRK)
  ASSERT(testPolyType%onSurface(point),'North Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=3.1_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond North Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=2.9_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside North Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%onSurface(point),'East Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.1_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond East Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.9_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside East Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-2.0_SRK)
  ASSERT(testPolyType%onSurface(point),'South Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-2.1_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond South Outer Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-1.9_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside South Outer Edge')
  !Outer corners
  ASSERT(testPolyType%onSurface(testPolyType%vert(1)),'South-West Corner')
  ASSERT(testPolyType%onSurface(testPolyType%vert(2)),'North-West Corner')
  ASSERT(testPolyType%onSurface(testPolyType%vert(3)),'North-East Corner')
  ASSERT(testPolyType%onSurface(testPolyType%vert(4)),'South-East Corner')

  !Sub-region tests.
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.3333333333333333_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%onSurface(point),'1st Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.3433333333333333_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond 1st Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.3233333333333333_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside 1st Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.3333333333333333_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%onSurface(point),'2nd Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.3433333333333333_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond 2nd Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.3233333333333333_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside 2nd Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-SQRT(5.0_SRK)+1.0_SRK)
  ASSERT(testPolyType%onSurface(point),'3rd Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-SQRT(5.0_SRK)+0.9_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Beyond 3rd Inner Edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-SQRT(5.0_SRK)+1.1_SRK)
  ASSERT(.NOT.testPolyType%onSurface(point),'Inside 3rd Inner Edge')
  !Inner corners
  ASSERT(testPolyType%onSurface(testPolyType%subregions%vert(1)),'1st Inner Corner')
  ASSERT(testPolyType%onSurface(testPolyType%subregions%vert(2)),'2nd Inner Corner')
  ASSERT(testPolyType%onSurface(testPolyType%subregions%vert(3)),'3rd Inner Corner')
ENDSUBROUTINE testPointOnSurface
706
!
707
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
708
709
710
711
712
713
714
715
SUBROUTINE testPointInside()
  TYPE(PolygonType) :: testPolyType
  INTEGER(SIK) :: i
  REAL(SRK) :: testCoord(2,9),c0(2)
  TYPE(PointType) :: point
  TYPE(PolygonType),TARGET :: testPoly2,testPoly3

  COMPONENT_TEST('Triangle')
716
  CALL testGraph%clear()
Graham, Aaron's avatar
Graham, Aaron committed
717
718
719
720
721
722
723
724
725
726
727
728
729
  CALL testPolyType%clear()
  !Setup test graph - isosceles triangle
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,-1.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,2.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))

  CALL testPolyType%set(testGraph)
730
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.5_SRK,Y=-0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'low left')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.5_SRK,Y=-0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'low right')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.2_SRK,Y=0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'top right')
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.2_SRK,Y=0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'top left')
  CALL point%clear()
  CALL point%init(DIM=2,X=-5.0_SRK,Y=-5.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'outside')
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.5_SRK,Y=-1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'on bottom edge')
  CALL testGraph%clear()
  CALL testPolyType%clear()
  CALL point%clear()

  COMPONENT_TEST('Square')
  testCoord(:,1)=(/0.0_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,1.0_SRK/)
  testCoord(:,3)=(/1.0_SRK,1.0_SRK/)
  testCoord(:,4)=(/1.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,4))
  CALL testPolyType%set(testGraph)
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'left edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.5_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'top edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK,Y=0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'right edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.5_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'bottom edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'parallel -x outside')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'parallel +x outside')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'parallel -y outside')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=2.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'parallel +y outside')
  CALL testGraph%clear()
  CALL testPolyType%clear()

  COMPONENT_TEST('Quadrilateral')
  !Setup test graph - quadralateral
  testCoord(:,1)=(/-3.0_SRK,-3.0_SRK/)
  testCoord(:,2)=(/-1.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,3.0_SRK/)
  testCoord(:,4)=(/1.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
807
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'Q1')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'Q2')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK,Y=-1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'Q3')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK,Y=-1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'Q4')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'Outside Q1')
  CALL point%clear()
  CALL point%init(DIM=2,X=-3.0_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'Outside Q2')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.5_SRK,Y=-0.25_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'Outside Q3')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=-1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'Outside Q4')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=3.0_SRK)
  ASSERT(testPolyType%pointInside(point),'on vertex')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.0_SRK,Y=-3.0_SRK)
  !MODIFY Polygon for this test (edge must be co-linear axis)
  testPolyType%vert(4)%coord(2)=-3.0_SRK
  ASSERT(testPolyType%pointInside(point),'on edge')
  CALL point%clear()
  CALL point%init(DIM=2,X=3.0_SRK,Y=3.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'outside bugfix')

  !Setup test graph - quadralateral with quadratic edge
  COMPONENT_TEST('Quad Edges')
  CALL testGraph%clear()
  CALL testPolyType%clear()
  testCoord(:,1)=(/-3.0_SRK,3.0_SRK/)
  testCoord(:,2)=(/3.0_SRK,3.0_SRK/)
  testCoord(:,3)=(/3.0_SRK,0.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,5)=(/2.0_SRK,-2.0_SRK/)
  testCoord(:,6)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,7)=(/-2.0_SRK,2.0_SRK/)
  DO i=1,7
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,7),testCoord(:,1))
  c0=(/0.0_SRK,1.0_SRK/)
862
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
863
864
      testCoord(:,2),c0,SQRT(13.0_SRK))
  c0=(/4.0_SRK,0.0_SRK/)
865
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
866
867
      testCoord(:,5),c0,SQRT(8.0_SRK))
  c0=(/0.0_SRK,-4.0_SRK/)
868
  CALL testGraph%defineEdge(testCoord(:,5), &
Graham, Aaron's avatar
Graham, Aaron committed
869
870
      testCoord(:,6),c0,SQRT(8.0_SRK))
  c0=(/-1.0_SRK,0.0_SRK/)
871
  CALL testGraph%defineEdge(testCoord(:,6), &
Graham, Aaron's avatar
Graham, Aaron committed
872
873
      testCoord(:,7),c0,SQRT(5.0_SRK))
  CALL testPolyType%set(testGraph)
874
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
  CALL point%clear()
  CALL point%init(DIM=2,X=-5.0_SRK,Y=5.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'1:Outside Poly and West QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.5_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'2:Outside Poly, Inside West QuadEdge')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.5_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'3:Inside Poly and West QuadEdge')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.8_SRK,Y=0.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'4:Inside Poly and East QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=4.0_SRK,Y=1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'5:Outside Poly and Inside East QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-10.0_SRK,Y=-1.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'6:Outside Poly and East QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-3.0_SRK,Y=2.5_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'7:Outside Poly and North QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.5_SRK,Y=2.5_SRK)
  ASSERT(testPolyType%pointInside(point),'8:inside Poly and North QuadEdge (on line, in)')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=3.5_SRK)
  ASSERT(testPolyType%pointInside(point),'9:Outside Poly and Inside North QuadEdge')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.5_SRK,Y=2.5_SRK)
  ASSERT(testPolyType%pointInside(point),'10:Outside Poly and North QuadEdge')
  CALL point%clear()
  CALL point%init(DIM=2,X=4.0_SRK,Y=2.5_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'11:Outside Poly and North QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-3.0_SRK,Y=-1.9_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'12:Outside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-1.9_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'13:Inside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=3.0_SRK,Y=-1.9_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'14:Outside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-2.0_SRK,Y=-2.5_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'15:Outside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-2.5_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'16:Outside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.0_SRK,Y=-2.5_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'17:Outside Poly and South QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=2.9_SRK,Y=0.5_SRK)
  ASSERT(testPolyType%pointInside(point),'18:Inside Poly and East QuadEdge')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=5.0_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'19:Outside Poly and North QuadEdge (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-1.17157287525381_SRK)
  ASSERT(testPolyType%pointInside(point),'20:On bottom QuadEdge (in)')
  CALL point%clear()
  CALL point%init(DIM=2,X=-3.23606797749979_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'21:On left QuadEdge (in)')
  CALL testGraph%clear()

  COMPONENT_TEST('Circular Hole')
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)/SQRT(2.0_SRK)
  testCoord(:,2)=(/-1.0_SRK,1.0_SRK/)/SQRT(2.0_SRK)
  testCoord(:,3)=(/1.0_SRK,1.0_SRK/)/SQRT(2.0_SRK)
  testCoord(:,4)=(/1.0_SRK,-1.0_SRK/)/SQRT(2.0_SRK)
  c0=(/0.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
949
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
950
      testCoord(:,2),c0,1.0_SRK)
951
  CALL testGraph%defineEdge(testCoord(:,2), &
Graham, Aaron's avatar
Graham, Aaron committed
952
      testCoord(:,3),c0,1.0_SRK)
953
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
954
      testCoord(:,4),c0,1.0_SRK)
955
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
956
957
      testCoord(:,1),c0,1.0_SRK)
  CALL testPoly2%set(testGraph)
958
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
  testPolyType%subRegions => testPoly2
  CALL point%clear()
  CALL point%init(DIM=2,X=-0.6_SRK,Y=0.6_SRK)
  ASSERT(.NOT.testPolyType%pointInside(point),'20:Inside subvolume poly (out)')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.5_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'21:outside subvolume poly')
  !Sub-Region vertices
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK/SQRT(2.0_SRK),Y=-1.0_SRK/SQRT(2.0_SRK))
  ASSERT(testPolyType%pointInside(point),'22: SW vertex subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK/SQRT(2.0_SRK),Y=1.0_SRK/SQRT(2.0_SRK))
  ASSERT(testPolyType%pointInside(point),'23: NW vertex subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK/SQRT(2.0_SRK),Y=1.0_SRK/SQRT(2.0_SRK))
  ASSERT(testPolyType%pointInside(point),'24: NE vertex subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK/SQRT(2.0_SRK),Y=-1.0_SRK/SQRT(2.0_SRK))
  ASSERT(testPolyType%pointInside(point),'25: SE vertex subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=-1.0_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'26: West Edge subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'27: North Edge subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=1.0_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'28: East Edge subvolume poly')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.0_SRK,Y=-1.0_SRK)
  ASSERT(testPolyType%pointInside(point),'29: South Edge subvolume poly')
  CALL testGraph%clear()
  CALL testPolyType%clear()
  CALL point%clear()

  COMPONENT_TEST('Circle 4p')
  testCoord(:,1)=(/-0.564_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,0.564_SRK/)
  testCoord(:,3)=(/0.564_SRK,0.0_SRK/)
  testCoord(:,4)=(/0.0_SRK,-0.564_SRK/)
  c0=(/6.943559581994459E-018_SRK,1.388711916398892E-017_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1004
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
1005
      testCoord(:,2),c0,0.564_SRK)
1006
  CALL testGraph%defineEdge(testCoord(:,2), &
Graham, Aaron's avatar
Graham, Aaron committed
1007
      testCoord(:,3),c0,0.564_SRK)
1008
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
1009
      testCoord(:,4),c0,0.564_SRK)
1010
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
      testCoord(:,1),c0,0.564_SRK)
  CALL testPolyType%set(testGraph)
  CALL point%init(DIM=2,X=-0.264_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'circle')
  CALL point%clear()
  CALL point%init(DIM=2,X=0.264_SRK,Y=0.0_SRK)
  ASSERT(testPolyType%pointInside(point),'circle')
  CALL testPolyType%clear()

  COMPONENT_TEST('Sub-Sub-Region')
  testCoord(:,1)=(/-0.8_SRK,-0.8_SRK/)
  testCoord(:,2)=(/-0.8_SRK,0.8_SRK/)
  testCoord(:,3)=(/0.8_SRK,0.8_SRK/)
  testCoord(:,4)=(/0.8_SRK,-0.8_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%clear()
  CALL testPolyType%set(testGraph)
  CALL testGraph%clear()
  testCoord(:,1)=(/-0.5_SRK,-0.5_SRK/)
  testCoord(:,2)=(/-0.5_SRK,0.5_SRK/)
  testCoord(:,3)=(/0.5_SRK,0.5_SRK/)
  testCoord(:,4)=(/0.5_SRK,-0.5_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly2%clear()
  CALL testPoly2%set(testGraph)
  CALL testGraph%clear()
  testCoord(:,1)=(/-0.3_SRK,-0.3_SRK/)
  testCoord(:,2)=(/-0.3_SRK,0.3_SRK/)
  testCoord(:,3)=(/0.3_SRK,0.3_SRK/)
  testCoord(:,4)=(/0.3_SRK,-0.3_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly3%clear()
  CALL testPoly3%set(testGraph)
  CALL testGraph%clear()

  testPolyType%subRegions => testPoly2
  testPoly2%subRegions => testPoly3

  CALL point%clear()
  CALL point%init(COORD=(/-0.3_SRK,0.0_SRK/))
  ASSERT(.NOT.testPolyType%pointInside(point),'on Sub-Sub-Region surface')
  point%coord=(/-0.4_SRK,0.0_SRK/)
  ASSERT(.NOT.testPolyType%pointInside(point),'in Sub-Region')
  point%coord=(/-0.2_SRK,0.0_SRK/)
  ASSERT(.NOT.testPolyType%pointInside(point),'in Sub-Sub-Region')

  !Test failed control rodlet geometry
  c0=(/-0.64833500000000022_SRK,-0.72018071428571528_SRK/)
  testCoord(:,1)=(/-0.82359500000000019_SRK,-0.72018071428571528_SRK/)
  testCoord(:,2)=(/-0.64833500000000022_SRK,-0.54492071428571531_SRK/)
  testCoord(:,3)=(/-0.47307500000000025_SRK,-0.72018071428571528_SRK/)
  testCoord(:,4)=(/-0.64833500000000022_SRK,-0.89544071428571526_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1085
1086
1087
1088
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1),c0,0.17526000000000000_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108

  CALL testPolyType%clear()
  CALL testPolyType%set(testGraph)

  ASSERT(testPolyType%isInit,'%isInit')

  CALL point%clear()
  CALL point%init(COORD=(/-0.56070500000000034_SRK,-0.80781071428571538_SRK/))
  ASSERT(testPolyType%pointInside(point),'on vert line')

  !Test rodlet 2
  c0=(/-0.64833500000000022_SRK,0.33537071428571341_SRK/)
  testCoord(:,1)=(/-0.82359500000000019_SRK,0.33537071428571341_SRK/)
  testCoord(:,2)=(/-0.64833500000000022_SRK,0.51063071428571338_SRK/)
  testCoord(:,3)=(/-0.47307500000000025_SRK,0.33537071428571341_SRK/)
  testCoord(:,4)=(/-0.64833500000000022_SRK,0.16011071428571341_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1109
1110
1111
1112
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,0.17526000000000000_SRK)
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1),c0,0.17526000000000000_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1113
1114
1115
1116
1117
1118

  CALL testPolyType%clear()
  CALL testPolyType%set(testGraph)

  CALL point%clear()
  CALL point%init(COORD=(/-0.56070500000000023_SRK,0.24774071428571345_SRK/))
1119
  ASSERT(testPolyType%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1120
1121
1122
  ASSERT(testPolyType%pointInside(point),'slightly off vert line')

ENDSUBROUTINE testPointInside
1123
1124
!
!-------------------------------------------------------------------------------
Graham, Aaron's avatar
Graham, Aaron committed
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
SUBROUTINE testPolyInside()
  TYPE(PolygonType) :: testPolyType
  INTEGER(SIK) :: i
  REAL(SRK) :: testCoord(2,9),c0(2)
  TYPE(PointType) :: point
  TYPE(PolygonType) :: testPoly2,testPoly3

  !Setup test graph - isosceles triangle
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,-1.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,2.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPolyType%set(testGraph)
1143
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155

  CALL testGraph%clear()
  testCoord(:,1)=(/-0.5_SRK,-0.5_SRK/)
  testCoord(:,2)=(/0.5_SRK,-0.5_SRK/)
  testCoord(:,3)=(/0.0_SRK,1.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1156
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
  ASSERT(testPolyType%boundsPoly(testPoly2),'Small triangle in bigger one')
  ASSERT(.NOT.testPoly2%boundsPoly(testPolyType),'Big triangle not in smaller one')
  CALL testPoly2%clear()

  CALL testGraph%clear()
  testCoord(:,1)=(/-1.0_SRK,2.0_SRK/)
  testCoord(:,2)=(/1.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/0.0_SRK,-1.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1172
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
  ASSERT(.NOT.testPolyType%boundsPoly(testPoly2),'line-line intersection')
  ASSERT(.NOT.testPoly2%boundsPoly(testPolyType),'No points inside')
  CALL testPoly2%clear()

  !Setup test graph - quadralateral with quadratic edge
  CALL testGraph%clear()
  CALL testPolyType%clear()
  testCoord(:,1)=(/-3.0_SRK,3.0_SRK/)
  testCoord(:,2)=(/3.0_SRK,3.0_SRK/)
  testCoord(:,3)=(/3.0_SRK,0.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,5)=(/2.0_SRK,-2.0_SRK/)
  testCoord(:,6)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,7)=(/-2.0_SRK,2.0_SRK/)
  DO i=1,7
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,7),testCoord(:,1))
  c0=(/0.0_SRK,1.0_SRK/)
1194
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
1195
1196
      testCoord(:,2),c0,SQRT(13.0_SRK))
  c0=(/4.0_SRK,0.0_SRK/)
1197
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
1198
1199
      testCoord(:,5),c0,SQRT(8.0_SRK))
  c0=(/0.0_SRK,-4.0_SRK/)
1200
  CALL testGraph%defineEdge(testCoord(:,5), &
Graham, Aaron's avatar
Graham, Aaron committed
1201
1202
      testCoord(:,6),c0,SQRT(8.0_SRK))
  c0=(/-1.0_SRK,0.0_SRK/)
1203
  CALL testGraph%defineEdge(testCoord(:,6), &
Graham, Aaron's avatar
Graham, Aaron committed
1204
1205
      testCoord(:,7),c0,SQRT(5.0_SRK))
  CALL testPolyType%set(testGraph)
1206
  ASSERT(testPolyType%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217

  CALL testGraph%clear()
  !Setup test graph - square with a full circle
  testCoord(:,1)=(/-1.5_SRK,-1.5_SRK/)
  testCoord(:,2)=(/-1.5_SRK,1.5_SRK/)
  testCoord(:,3)=(/1.5_SRK,1.5_SRK/)
  testCoord(:,4)=(/1.5_SRK,-1.5_SRK/)
  c0=(/0.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1218
  CALL testGraph%defineEdge(testCoord(:,1), &
Graham, Aaron's avatar
Graham, Aaron committed
1219
      testCoord(:,2),c0,SQRT(4.5_SRK))
1220
  CALL testGraph%defineEdge(testCoord(:,2), &
Graham, Aaron's avatar
Graham, Aaron committed
1221
      testCoord(:,3),c0,SQRT(4.5_SRK))
1222
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
1223
      testCoord(:,4),c0,SQRT(4.5_SRK))
1224
  CALL testGraph%defineEdge(testCoord(:,4), &
Graham, Aaron's avatar
Graham, Aaron committed
1225
1226
      testCoord(:,1),c0,SQRT(4.5_SRK))
  CALL testPoly2%set(testGraph)
1227
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
  ASSERT(.NOT.testPolyType%boundsPoly(testPoly2),'circle-circle intersection')
  ASSERT(.NOT.testPoly2%boundsPoly(testPolyType),'No points inside')
  CALL testPoly2%clear()

  CALL testGraph%clear()
  !Setup test graph - square with a east face circle
  testCoord(:,1)=(/2.1_SRK,2.1_SRK/)
  testCoord(:,2)=(/2.1_SRK,2.5_SRK/)
  testCoord(:,3)=(/2.9_SRK,2.5_SRK/)
  testCoord(:,4)=(/2.9_SRK,2.1_SRK/)
  c0=(/2.8_SRK,2.3_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
1245
  CALL testGraph%defineEdge(testCoord(:,3), &
Graham, Aaron's avatar
Graham, Aaron committed
1246
1247
      testCoord(:,4),c0,SQRT(0.05_SRK))
  CALL testPoly2%set(testGraph)
1248
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
  ASSERT(.NOT.testPolyType%boundsPoly(testPoly2),'circle-line intersection')
  ASSERT(.NOT.testPoly2%boundsPoly(testPolyType),'No points inside')
  CALL testPoly2%clear()

  CALL testGraph%clear()
  !Setup test graph - square
  testCoord(:,1)=(/-1.5_SRK,-1.5_SRK/)
  testCoord(:,2)=(/-1.5_SRK,1.5_SRK/)
  testCoord(:,3)=(/1.5_SRK,1.5_SRK/)
  testCoord(:,4)=(/1.5_SRK,-1.5_SRK/)
  c0=(/0.0_SRK,0.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1268
  ASSERT(testPoly2%isinit,'%isinit')
Graham, Aaron's avatar
Graham, Aaron committed
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
  ASSERT(.NOT.testPolyType%boundsPoly(testPoly2),'line-circle intersection')
  ASSERT(.NOT.testPoly2%boundsPoly(testPolyType),'No points inside')
  CALL testPoly2%clear()

  CALL testGraph%clear()
  CALL testPolyType%clear()
  CALL point%clear()

  !Setup test graph -NW circle quadrant
  testCoord(:,1)=(/-0.5_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,0.5_SRK/)
  testCoord(:,3)=(/0.0_SRK,0.0_SRK/)
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  c0=(/0.0_SRK,0.0_SRK/)
1285
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.5_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1286
1287
1288
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPolyType%set(testGraph)
1289
  ASSERT(testPolyType%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1290
1291
1292
1293
1294
1295
1296
1297
1298
  !Setup smaller arc
  testCoord(:,1)=(/0.5_SRK*COS(7.0_SRK*PI/8.0_SRK),0.5_SRK*SIN(7.0_SRK*PI/8.0_SRK)/)
  testCoord(:,2)=(/0.5_SRK*COS(5.0_SRK*PI/8.0_SRK),0.5_SRK*SIN(5.0_SRK*PI/8.0_SRK)/)
  testCoord(:,3)=(/0.5_SRK*COS(5.0_SRK*PI/8.0_SRK),0.5_SRK*SIN(7.0_SRK*PI/8.0_SRK)/)
  CALL testGraph%clear()
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  c0=(/0.0_SRK,0.0_SRK/)
1299
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.5_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1300
1301
1302
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1303
  ASSERT(testPoly2%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
  CALL testGraph%clear()
  ASSERT(testPolyType%boundsPoly(testPoly2),'arc-arc coincident')
  ASSERT(.NOT. testPoly2%boundsPoly(testPolyType),'No points inside')
  !Setup triangle
  CALL testPoly2%clear()
  testCoord(:,1)=(/-0.15_SRK,0.15_SRK/)
  testCoord(:,2)=(/0.0_SRK,0.25_SRK/)
  testCoord(:,3)=(/0.0_SRK,0.05_SRK/)
  CALL testGraph%clear()
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1320
  ASSERT(testPoly2%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
  ASSERT(testPolyType%boundsPoly(testPoly2),'edge-edge coincident')
  ASSERT(.NOT. testPoly2%boundsPoly(testPolyType),'no points inside')
  CALL testPolyType%clear()
  CALL testPoly2%clear()
  !Setup rectangle-1 quad edge
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  c0=(/4.0_SRK,0.0_SRK/)
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
1337
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,SQRT(8.0_SRK))
Graham, Aaron's avatar
Graham, Aaron committed
1338
1339
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
1340
  ASSERT(testPolyType%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
  !Setup triangle intersecting quadratic edge
  testCoord(:,1)=(/1.0_SRK,0.0_SRK/)
  testCoord(:,2)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,-2.0_SRK/)
  CALL testGraph%clear()
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1353
  ASSERT(testPoly2%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
  ASSERT(.NOT. testPolyType%boundsPoly(testPoly2),'Intersect-arc')
  ASSERT(.NOT. testPoly2%boundsPoly(testPolyType),'Intersect-arc')
  CALL testPoly2%clear()

  !Setup triangle with all points on quadratic edge
  testCoord(:,1)=(/1.1715728752538097_SRK,0.0_SRK/)
  testCoord(:,2)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,-2.0_SRK/)
  CALL testGraph%clear()
  DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1370
  ASSERT(testPoly2%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
  ASSERT(.NOT. testPolyType%boundsPoly(testPoly2),'On quadratic edge')
  ASSERT(.NOT. testPoly2%boundsPoly(testPolyType),'No points inside')

  CALL testPoly2%clear()
  CALL testPolyType%clear()
  !setup rectangle
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,2.0_SRK/)
  testCoord(:,4)=(/2.0_SRK,-2.0_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPolyType%set(testGraph)
  !Setup arc segment
  c0=(/-3.0_SRK,-3.0_SRK/)
  testCoord(:,1)=(/-2.0_SRK,-2.0_SRK/)
  testCoord(:,2)=(/-2.0_SRK,-1.5_SRK/)
  testCoord(:,3)=(/-1.5_SRK,-2.0_SRK/)
  CALL testGraph%clear()
   DO i=1,3
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
1400
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,1.8027756377319946_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1401
1402
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1403
  ASSERT(testPoly2%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
  ASSERT(testPolyType%boundsPoly(testPoly2),'2 coincident edges')
  ASSERT(.NOT. testPoly2%boundsPoly(testPolyType),'no points inside')
  CALL testPoly2%clear()
  testCoord(:,1)=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,2)=(/-1.0_SRK,1.0_SRK/)
  testCoord(:,3)=(/1.0_SRK,1.0_SRK/)
  testCoord(:,4)=(/1.0_SRK,-1.0_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly2%set(testGraph)
1420
1421
  ASSERT(testPoly2%isInit,'%isInit')
  ASSERT(testPolyType%boundsPoly(testPoly2),'smaller square')
Graham, Aaron's avatar
Graham, Aaron committed
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
  CALL testPolyType%subtractSubVolume(testPoly2)
  ASSERT(ASSOCIATED(testPolyType%subRegions),'Subregion subtracted')
  CALL testGraph%clear()
  testCoord(:,1)=(/-1.0_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,1.0_SRK/)
  testCoord(:,3)=(/1.0_SRK,0.0_SRK/)
  testCoord(:,4)=(/0.0_SRK,-1.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2))
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3))
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4))
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1))
  CALL testPoly3%set(testGraph)
1437
  ASSERT(testPoly3%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
  ASSERT(testPoly2%boundsPoly(testPoly3),'inside subregion')
  ASSERT(.NOT. testPolyType%boundsPoly(testPoly3),'inside subregion')
  ASSERT(.NOT. testPoly3%boundsPoly(testPolyType),'no points inside')
  CALL testPoly3%clear()

  !Circle box-intersecting subregion
  c0=(/-1.0_SRK,-1.0_SRK/)
  testCoord(:,1)=(/-1.25_SRK,-1.0_SRK/)
  testCoord(:,2)=(/-1.0_SRK,-0.75_SRK/)
  testCoord(:,3)=(/-0.75_SRK,-1.0_SRK/)
  testCoord(:,4)=(/-1.0_SRK,-1.25_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1453
1454
1455
1456
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1),c0,0.25_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1457
  CALL testPoly3%set(testGraph)
1458
  ASSERT(testPoly3%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
  ASSERT(.NOT. testPolyType%boundsPoly(testPoly3),'verts on subRegions')
  ASSERT(.NOT. testPoly3%boundsPoly(testPolyType),'no points inside')
  CALL testPoly3%clear()

  !Circle-box intersecting subregions
  c0=(/-1.1_SRK,-1.1_SRK/)
  testCoord(:,1)=(/-1.35_SRK,-1.1_SRK/)
  testCoord(:,2)=(/-1.1_SRK,-0.85_SRK/)
  testCoord(:,3)=(/-0.85_SRK,-1.1_SRK/)
  testCoord(:,4)=(/-1.1_SRK,-1.35_SRK/)
  CALL testGraph%clear()
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1473
1474
1475
1476
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,0.25_SRK)
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1),c0,0.25_SRK)
Graham, Aaron's avatar
Graham, Aaron committed
1477
  CALL testPoly3%set(testGraph)
1478
  ASSERT(testPoly3%isInit,'%isInit')
Graham, Aaron's avatar
Graham, Aaron committed
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
  ASSERT(.NOT. testPolyType%boundsPoly(testPoly3),'intersects subRegions')
  ASSERT(.NOT. testPoly3%boundsPoly(testPolyType),'no points inside')


  CALL testPolyType%clear()
  CALL testPoly2%clear()
  CALL testPoly3%clear()
  CALL testGraph%clear()
  c0=(/0.0_SRK,0.0_SRK/)
  testCoord(:,1)=(/-2.0_SRK,0.0_SRK/)
  testCoord(:,2)=(/0.0_SRK,2.0_SRK/)
  testCoord(:,3)=(/2.0_SRK,0.0_SRK/)
  testCoord(:,4)=(/0.0_SRK,-2.0_SRK/)
  DO i=1,4
    CALL testGraph%insertVertex(testCoord(:,i))
  ENDDO
1495
1496
1497
1498
  CALL testGraph%defineEdge(testCoord(:,1),testCoord(:,2),c0,2.0_SRK)
  CALL testGraph%defineEdge(testCoord(:,2),testCoord(:,3),c0,2.0_SRK)
  CALL testGraph%defineEdge(testCoord(:,3),testCoord(:,4),c0,2.0_SRK)
  CALL testGraph%defineEdge(testCoord(:,4),testCoord(:,1),c0,2.0_SRK)