Draw a line between A and B, in hex space
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hex), | intent(in) | :: | A | |||
type(hex), | intent(in) | :: | B |
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