560
561 class(MethodDisvType), intent(inout) :: this
562 type(CellDefnType), pointer, intent(inout) :: defn
563
564 integer(I4B) :: npolyverts
565 integer(I4B) :: m
566 integer(I4B) :: m0
567 integer(I4B) :: m1
568 integer(I4B) :: m2
569 integer(I4B) :: ic
570 integer(I4B) :: num90
571 integer(I4B) :: num180
572 real(DP) :: x0
573 real(DP) :: y0
574 real(DP) :: x1
575 real(DP) :: y1
576 real(DP) :: x2
577 real(DP) :: y2
578 real(DP) :: epsang
579 real(DP) :: s0x
580 real(DP) :: s0y
581 real(DP) :: &
582 s0mag, s2x, s2y, s2mag, sinang, cosang, dotprod
583 logical(LGP) last180
584 logical(LGP) offmid
585
586 ic = defn%icell
587 npolyverts = defn%npolyverts
588
589 if (size(defn%ispv180) < npolyverts + 3) &
590 call expandarray(defn%ispv180, npolyverts + 1)
591
592 defn%ispv180(1:npolyverts + 1) = .false.
593 defn%can_be_rect = .false.
594 defn%can_be_quad = .false.
595 epsang = 1d-5
596 num90 = 0
597 num180 = 0
598 last180 = .false.
599 offmid = .false.
600
601
602 do m = 1, npolyverts
603 m1 = m
604 if (m1 .eq. 1) then
605 m0 = npolyverts
606 m2 = 2
607 else if (m1 .eq. npolyverts) then
608 m0 = npolyverts - 1
609 m2 = 1
610 else
611 m0 = m1 - 1
612 m2 = m1 + 1
613 end if
614 x0 = defn%polyvert(1, m0)
615 y0 = defn%polyvert(2, m0)
616 x1 = defn%polyvert(1, m1)
617 y1 = defn%polyvert(2, m1)
618 x2 = defn%polyvert(1, m2)
619 y2 = defn%polyvert(2, m2)
620 s0x = x0 - x1
621 s0y = y0 - y1
622 s0mag = dsqrt(s0x * s0x + s0y * s0y)
623 s2x = x2 - x1
624 s2y = y2 - y1
625 s2mag = dsqrt(s2x * s2x + s2y * s2y)
626 sinang = (s0x * s2y - s0y * s2x) / (s0mag * s2mag)
627 cosang = dsqrt(dabs(done - (sinang * sinang)))
628 if (dabs(sinang) .lt. epsang) then
629 dotprod = s0x * s2x + s0y * s2y
630 if (dotprod .lt. dzero) then
631 num180 = num180 + 1
632 last180 = .true.
633 defn%ispv180(m) = .true.
634 if (dabs(s0mag - s2mag) > epsang * (s0mag + s2mag)) &
635 offmid = .true.
636 end if
637 else
638 if (dabs(cosang) .lt. epsang) num90 = num90 + 1
639 last180 = .false.
640 end if
641 end do
642
643
644 defn%ispv180(npolyverts + 1) = defn%ispv180(1)
645
646
647
648 if (num90 .eq. 4) then
649 if (num180 .eq. 0) then
650 defn%can_be_rect = .true.
651 else if (.not. offmid .and. &
652 .not. any(defn%ispv180(1:npolyverts) .and. &
653 defn%ispv180(2:npolyverts + 1))) then
654 defn%can_be_quad = .true.
655 end if
656 end if