Title: [115384] branches/subpixellayout/Source/WebCore/css/CSSPrimitiveValue.h
- Revision
- 115384
- Author
- [email protected]
- Date
- 2012-04-26 15:57:54 -0700 (Thu, 26 Apr 2012)
Log Message
Fixing roundForImpreciseConversion for the float case with template specialization.
Modified Paths
Diff
Modified: branches/subpixellayout/Source/WebCore/css/CSSPrimitiveValue.h (115383 => 115384)
--- branches/subpixellayout/Source/WebCore/css/CSSPrimitiveValue.h 2012-04-26 22:53:35 UTC (rev 115383)
+++ branches/subpixellayout/Source/WebCore/css/CSSPrimitiveValue.h 2012-04-26 22:57:54 UTC (rev 115384)
@@ -42,15 +42,26 @@
struct Length;
+// Dimension calculations are imprecise, often resulting in values of e.g.
+// 44.99998. We need to go ahead and round if we're really close to the
+// next integer value.
template<typename T> inline T roundForImpreciseConversion(double value)
{
- // Dimension calculations are imprecise, often resulting in values of e.g.
- // 44.99998. We need to go ahead and round if we're really close to the
- // next integer value.
value += (value < 0) ? -0.01 : +0.01;
return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_limits<T>::min())) ? 0 : static_cast<T>(value);
}
+template<> inline float roundForImpreciseConversion(double value)
+{
+ double ceiledValue = ceil(value);
+ double proximityToNextInt = ceiledValue - value;
+ if (proximityToNextInt <= 0.01 && value > 0)
+ value = ceiledValue;
+ else if (proximityToNextInt >= 0.99 && value < 0)
+ value = floor(value);
+ return ((value > std::numeric_limits<float>::max()) || (value < std::numeric_limits<float>::min())) ? 0 : static_cast<float>(value);
+}
+
class CSSPrimitiveValue : public CSSValue {
public:
enum UnitTypes {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes