The segments: from a(:, i) to b(:, i) (frame coordinates), colored color_a(:, i) at a and color_b(:, i) at b ([r, g, b] or [r, g, b, a] columns; one of them for both ends; neither: the frame's color). Setting the same segments again changes nothing (no upload).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(CustomLineSegments), | intent(inout) | :: | self | |||
| real(kind=wp), | intent(in) | :: | a(:,:) |
(3, n): first endpoints (frame coordinates) |
||
| real(kind=wp), | intent(in) | :: | b(:,:) |
(3, n): second endpoints (frame coordinates) |
||
| real(kind=wp), | intent(in), | optional | :: | color_a(:,:) |
(3 or 4, n): colors at a, [r, g, b(, a)] (0 to 1) |
|
| real(kind=wp), | intent(in), | optional | :: | color_b(:,:) |
(3 or 4, n): colors at b, [r, g, b(, a)] (0 to 1) |
subroutine set_segments(self, a, b, color_a, color_b) class(CustomLineSegments), intent(inout) :: self real(wp), intent(in) :: a(:,:) !! (3, n): first endpoints (frame coordinates) real(wp), intent(in) :: b(:,:) !! (3, n): second endpoints (frame coordinates) real(wp), intent(in), optional :: color_a(:,:) !! (3 or 4, n): colors at a, [r, g, b(, a)] (0 to 1) real(wp), intent(in), optional :: color_b(:,:) !! (3 or 4, n): colors at b, [r, g, b(, a)] (0 to 1) real(c_float), allocatable :: ca(:,:), cb(:,:) integer :: n n = min(size(a, 2), size(b, 2)) if (present(color_a) .or. present(color_b)) then allocate(ca(4, n), cb(4, n)) if (present(color_a)) then call rgba(color_a, ca) else call rgba(color_b, ca) end if if (present(color_b)) then call rgba(color_b, cb) else cb = ca end if end if if (n == self%n .and. same(a(:, 1:n), self%a) .and. same(b(:, 1:n), self%b) .and. & (allocated(ca) .eqv. allocated(self%color_a))) then if (.not. allocated(ca)) return if (all(ca == self%color_a) .and. all(cb == self%color_b)) return end if self%n = n self%a = a(1:3, 1:n) self%b = b(1:3, 1:n) if (allocated(ca)) then call move_alloc(ca, self%color_a) call move_alloc(cb, self%color_b) else if (allocated(self%color_a)) deallocate(self%color_a, self%color_b) end if self%changed = .true. contains !> True if x(1:3, :) and y have the same points. pure logical function same(x, y) real(wp), intent(in) :: x(:,:), y(:,:) !! points by column (x: 3 or more rows, y: 3) same = size(x, 2) == size(y, 2) if (same) same = all(x(1:3, :) == y) end function same end subroutine set_segments