hex_line Function

public pure function hex_line(A, B) result(line)

Draw a line between A and B, in hex space

Arguments

Type IntentOptional Attributes Name
type(hex), intent(in) :: A
type(hex), intent(in) :: B

Return Value type(hex), allocatable, (:)


Calls

proc~~hex_line~~CallsGraph proc~hex_line hex_geometries::hex_line proc~hex_distance hex_coordinates::hex_distance proc~hex_line->proc~hex_distance proc~hex_insert hex_geometries::hex_insert proc~hex_line->proc~hex_insert proc~hex_round hex_geometries::hex_round proc~hex_line->proc~hex_round proc~linear_interpolation hex_geometries::linear_interpolation proc~hex_line->proc~linear_interpolation proc~hex_norm hex_coordinates::hex_norm proc~hex_distance->proc~hex_norm

Source Code

   pure function hex_line(A,B) result(line)
      !! Draw a line between A and B, in hex space
      type(hex),intent(in)  :: A,B
      type(hex),allocatable :: line(:)
      real(8),dimension(3)  :: lntrp
      integer,dimension(3)  :: ai,bi
      real(8),dimension(3)  :: ar,br
      real(8)               :: step
      integer               :: dist,i
      dist = hex_distance(A,B)
      step = 1d0 / max(dist,1) ! handle A==B :)
      do i = 0,dist
         ! Unpack
         ai = [A%q,A%r,A%s]
         bi = [B%q,B%r,B%s]
         ! Cast
         ar = real(ai,8)
         br = real(bi,8)
         ! Nudge
         ar(1:2) = ar(1:2) + 1d-6
         ar(3)   = ar(3)   - 2d-6
         br(1:2) = br(1:2) + 1d-6
         br(3)   = br(3)   - 2d-6
         ! Interpolate
         lntrp = linear_interpolation(ar,br,step*i)
         ! Grow the vect
         call hex_insert(line,hex_round(lntrp))
      enddo
   end function hex_line