| 18 | } // namespace |
| 19 | |
| 20 | uint32_t DoubleToUint32(double x, double min, double max, uint8_t coordBits) |
| 21 | { |
| 22 | ASSERT_LESS_OR_EQUAL(min, max, ()); |
| 23 | |
| 24 | double const coordSize = CoordSize(coordBits); |
| 25 | |
| 26 | // Expand checks to avoid NANs when min == max. |
| 27 | double d; |
| 28 | if (x <= min) |
| 29 | d = 0; |
| 30 | else if (x >= max) |
| 31 | d = coordSize; |
| 32 | else |
| 33 | d = (x - min) / (max - min) * coordSize; |
| 34 | |
| 35 | // Check in case of NANs. |
| 36 | ASSERT(d >= 0 && d <= coordSize, (d, x, min, max, coordBits)); |
| 37 | return static_cast<uint32_t>(0.5 + d); |
| 38 | } |
| 39 | |
| 40 | double Uint32ToDouble(uint32_t x, double min, double max, uint8_t coordBits) |
| 41 | { |
no test coverage detected