Given two types, find a type that can represent the values of both.
| 292 | |
| 293 | // Given two types, find a type that can represent the values of both. |
| 294 | Dimension::Type PointLayout::resolveType(Dimension::Type t1, |
| 295 | Dimension::Type t2) |
| 296 | { |
| 297 | using namespace Dimension; |
| 298 | if (t1 == Type::None && t2 != Type::None) |
| 299 | return t2; |
| 300 | if (t2 == Type::None && t1 != Type::None) |
| 301 | return t1; |
| 302 | if (t1 == t2) |
| 303 | return t1; |
| 304 | if (base(t1) == base(t2)) |
| 305 | return (std::max)(t1, t2); |
| 306 | //Prefer floating to non-floating. |
| 307 | if (base(t1) == BaseType::Floating && base(t2) != BaseType::Floating) |
| 308 | return t1; |
| 309 | if (base(t2) == BaseType::Floating && base(t1) != BaseType::Floating) |
| 310 | return t2; |
| 311 | // Now we're left with cases of a signed/unsigned mix. |
| 312 | // If the unsigned type is smaller, take the signed type. |
| 313 | if (base(t1) == BaseType::Unsigned && size(t1) < size(t2)) |
| 314 | return t2; |
| 315 | if (base(t2) == BaseType::Unsigned && size(t2) < size(t1)) |
| 316 | return t1; |
| 317 | // Signed type is smaller or the the sizes are equal. |
| 318 | switch ((std::max)(size(t1), size(t2))) |
| 319 | { |
| 320 | case 1: |
| 321 | return Type::Signed16; |
| 322 | case 2: |
| 323 | return Type::Signed32; |
| 324 | case 4: |
| 325 | return Type::Signed64; |
| 326 | default: |
| 327 | return Type::Double; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | MetadataNode PointLayout::toMetadata() const |
| 332 | { |