LCOV - code coverage report
Current view: top level - src - helpers.jl (source / functions) Hit Total Coverage
Test: on branch nothing Lines: 2 18 11.1 %
Date: 2025-07-10 13:29:30 Functions: 0 0 -

          Line data    Source code
       1             : """
       2             : Default type for representing RBG and RBGA colors in 32 bit.
       3             : """
       4             : const RGBA = ColorTypes.RGBA{FixedPointNumbers.N0f8}
       5             : 
       6           6 : Base.copy(rgba::RGBA) = rgba # required by PMeshAttributes
       7             : 
       8             : # identity
       9           0 : convert_to(p::T, ::T) where {T} = p
      10             : 
      11             : # real types
      12           0 : convert_to(p::T, ::S) where {T<:Real, S<:Real} = S(p)
      13             : 
      14             : 
      15             : # vectors: same size, different real types
      16       20624 : convert_to(p::SVector{N, T}, ::SVector{N, S}) where {N, T, S} = S.(p)
      17             : 
      18             : 
      19             : # 2d -> 3d: append 0
      20           0 : convert_to(p::SVector{2, T}, ::SVector{3, S}) where {T, S} =
      21             :     SVector(S.(p...), S(0))
      22             : 
      23             : # 2d -> 4d append 0, 1 (homogeneous coordinate)
      24           0 : convert_to(p::SVector{2, T}, ::SVector{4, S}) where {T, S} =
      25             :     SVector(S.(p...), S(0), S(1))
      26             : 
      27             : 
      28             : # 3d -> 4d: append 1 (homogeneous coordinate)
      29           0 : convert_to(p::SVector{3, T}, ::SVector{4, S}) where {T, S} = SVector(S.(p...), S(1))
      30             : 
      31             : # 3d -> 2d: drop last coordinate
      32           0 : convert_to(p::SVector{3, T}, ::SVector{2, S}) where {T, S} = SVector(S(p[1]), S(p[2]))
      33             : 
      34             : # 4d -> 3d: divide by homogeneous coordinate
      35           0 : function convert_to(p::SVector{4,T}, ::SVector{3,S}) where {T,S}
      36           0 :     if p[4] == 0
      37           0 :         SVector(S(p[1]), S(p[2]), S(p[3]))
      38             :     else
      39           0 :         SVector(S(p[1]), S(p[2]), S(p[3])) / S(p[4])
      40             :     end
      41             : end
      42             : 
      43             : # 3d to RGBA color
      44           0 : convert_to(p::SVector{3, T}, ::ColorTypes.RGBA{S}) where {T, S} =
      45             :     ColorTypes.RGBA{S}(S.(p)..., S(1))
      46             : 
      47             : # 4d to RGBA color
      48           0 : convert_to(p::SVector{4, T}, ::ColorTypes.RGBA{S}) where {T, S} =
      49             :     ColorTypes.RGBA{S}(S.(p)...)
      50             : 
      51             : # 3d to RGB color
      52           0 : convert_to(p::SVector{3, T}, ::ColorTypes.RGB{S}) where {T, S} =
      53             :     ColorTypes.RGB{S}(S.(p)..., S(1))
      54             : 
      55             : # 4d to RGB color
      56           0 : convert_to(p::SVector{4, T}, ::ColorTypes.RGB{S}) where {T, S} =
      57             :     ColorTypes.RGB{S}(S(p[1]), S(p[2]), S(p[3]))
      58             : 
      59             : # 3d to RGB color
      60           0 : convert_to(p::SVector{3, T}, ::ColorTypes.RGB24) where {T} =
      61             :     ColorTypes.RGB24(p...)
      62             : 
      63             : # 4d to RGB color
      64           0 : convert_to(p::SVector{4, T}, ::ColorTypes.RGB24) where {T} =
      65             :     ColorTypes.RGB24(p[1], p[2], p[3])
      66             : 
      67             : """
      68             :     vu :: typeof(u) = convert_to(v, u)
      69             : 
      70             : Helper that converts (vector) types, possibly "appending" missing
      71             : dimensions or "truncating" dimensions with reasonable default choices.
      72             : 
      73             : - `(x, y) -> (x, y, 0)`
      74             : - `(x, y) -> (x, y, 0, 1)
      75             : - `(x, y, z) -> (x, y, z, 1)`
      76             : - `(x, y, z) -> (x, y)`
      77             : - `(x, y, z, w) -> (x/w, y/w, z/w)`
      78             : - `(r, g, r)` -> RBG24 | RGBA`
      79             : - `(r, g, r, a)` -> RBG24 | RGBA`
      80             : 
      81             : """ convert_to

Generated by: LCOV version 1.16