Commit bf79c8a6 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Use round() [not roundf()] in RoundedIntPoint(const DoublePoint&)

This avoids the implicit conversion to float, which can lead to loss of
precision.

Bug: 836722
Change-Id: I66ea0f42823347b17e41e5d823aaf766429eacbf
Reviewed-on: https://chromium-review.googlesource.com/1027710Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#553543}
parent dc977694
......@@ -1797,6 +1797,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"fonts/symbols_iterator_test.cc",
"fonts/typesetting_features_test.cc",
"fonts/unicode_range_set_test.cc",
"geometry/double_point_test.cc",
"geometry/double_rect_test.cc",
"geometry/float_box_test.cc",
"geometry/float_box_test_helpers.cc",
......
......@@ -111,7 +111,7 @@ inline DoublePoint operator-(const DoublePoint& a, const DoubleSize& b) {
}
inline IntPoint RoundedIntPoint(const DoublePoint& p) {
return IntPoint(clampTo<int>(roundf(p.X())), clampTo<int>(roundf(p.Y())));
return IntPoint(clampTo<int>(round(p.X())), clampTo<int>(round(p.Y())));
}
inline IntPoint CeiledIntPoint(const DoublePoint& p) {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/geometry/double_point.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TEST(DoublePointTest, RoundedIntPoint) {
// Value not exactly representable as a float.
DoublePoint p1(16777217.0, -16777217.0);
IntPoint rounded_p1 = RoundedIntPoint(p1);
EXPECT_EQ(16777217, rounded_p1.X());
EXPECT_EQ(-16777217, rounded_p1.Y());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment