Commit 48fbea25 authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Fix integer truncation in Region::Area, and return uint64_t.

Bug: 581518
Change-Id: Icaaf62a88941961421f64454a06e9a53c4c39eee
Reviewed-on: https://chromium-review.googlesource.com/c/1349849Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Steve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610677}
parent f4459c69
......@@ -100,8 +100,8 @@ bool Region::Intersects(const Region& region) const {
region.shape_);
}
double Region::Area() const {
double area = 0.0;
uint64_t Region::Area() const {
uint64_t area = 0;
for (Shape::SpanIterator span = shape_.SpansBegin(), end = shape_.SpansEnd();
span != end && span + 1 != end; ++span) {
int height = (span + 1)->y - span->y;
......@@ -110,7 +110,7 @@ double Region::Area() const {
end = shape_.SegmentsEnd(span);
segment != end && segment + 1 != end; segment += 2) {
int width = *(segment + 1) - *segment;
area += height * width;
area += (uint64_t)height * (uint64_t)width;
}
}
return area;
......
......@@ -71,7 +71,7 @@ class PLATFORM_EXPORT Region {
// Returns true if the query region intersects any part of this region.
bool Intersects(const Region&) const;
double Area() const;
uint64_t Area() const;
#ifndef NDEBUG
void Dump() const;
......
......@@ -383,19 +383,22 @@ TEST(RegionTest, unite) {
TEST(RegionTest, Area) {
Region r;
EXPECT_EQ(0.0, r.Area());
EXPECT_EQ(0u, r.Area());
r.Unite(IntRect(10, 20, 30, 10));
EXPECT_EQ(300.0, r.Area());
EXPECT_EQ(300u, r.Area());
r.Unite(IntRect(20, 10, 10, 30));
EXPECT_EQ(500.0, r.Area());
EXPECT_EQ(500u, r.Area());
r.Unite(IntRect(10, 10, 30, 30));
EXPECT_EQ(900.0, r.Area());
EXPECT_EQ(900u, r.Area());
r.Subtract(IntRect(20, 20, 10, 10));
EXPECT_EQ(800.0, r.Area());
EXPECT_EQ(800u, r.Area());
r.Unite(IntRect(0, 0, 50000, 50000));
EXPECT_EQ(2500000000u, r.Area());
}
} // 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