| Index: ui/gfx/range/range.cc
|
| diff --git a/ui/gfx/range/range.cc b/ui/gfx/range/range.cc
|
| index 1c3968aa6e2f82d561f068434abba3d52869a999..16083e82a9a3275866e1c8c4a108bc87a60e99f6 100644
|
| --- a/ui/gfx/range/range.cc
|
| +++ b/ui/gfx/range/range.cc
|
| @@ -1,87 +1,60 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 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 "ui/gfx/range/range.h"
|
|
|
| -#include <algorithm>
|
| -#include <limits>
|
| -
|
| -#include "base/format_macros.h"
|
| -#include "base/logging.h"
|
| -#include "base/strings/stringprintf.h"
|
| +#include "base/float_util.h"
|
|
|
| namespace gfx {
|
|
|
| -Range::Range()
|
| - : start_(0),
|
| - end_(0) {
|
| -}
|
| -
|
| -Range::Range(size_t start, size_t end)
|
| - : start_(start),
|
| - end_(end) {
|
| -}
|
| -
|
| -Range::Range(size_t position)
|
| - : start_(position),
|
| - end_(position) {
|
| -}
|
| -
|
| -// static
|
| -const Range Range::InvalidRange() {
|
| - return Range(std::numeric_limits<size_t>::max());
|
| -}
|
| +namespace internal {
|
|
|
| -bool Range::IsValid() const {
|
| - return *this != InvalidRange();
|
| +template <>
|
| +TRangeBase<size_t> InvalidRange<size_t>() {
|
| + return TRangeBase<size_t>(std::numeric_limits<size_t>::max(),
|
| + std::numeric_limits<size_t>::max());
|
| }
|
|
|
| -size_t Range::GetMin() const {
|
| - return std::min(start(), end());
|
| +template <>
|
| +TRangeBase<float> InvalidRange<float>() {
|
| + return TRangeBase<float>(std::numeric_limits<double>::quiet_NaN(),
|
| + std::numeric_limits<double>::quiet_NaN());
|
| }
|
|
|
| -size_t Range::GetMax() const {
|
| - return std::max(start(), end());
|
| +bool IsValidRange(const TRangeBase<size_t>& range) {
|
| + return range != InvalidRange<size_t>();
|
| }
|
|
|
| -bool Range::operator==(const Range& other) const {
|
| - return start() == other.start() && end() == other.end();
|
| +bool IsValidRange(const TRangeBase<float>& range) {
|
| + return !base::IsNaN(range.start()) && !base::IsNaN(range.end());
|
| }
|
|
|
| -bool Range::operator!=(const Range& other) const {
|
| - return !(*this == other);
|
| +size_t RangeLength(const TRangeBase<size_t>& range) {
|
| + ptrdiff_t length = range.end() - range.start();
|
| + return length >= 0 ? length : -length;
|
| }
|
|
|
| -bool Range::EqualsIgnoringDirection(const Range& other) const {
|
| - return GetMin() == other.GetMin() && GetMax() == other.GetMax();
|
| +float RangeLength(const TRangeBase<float>& range) {
|
| + float length = range.end() - range.start();
|
| + return length >= 0 ? length : -length;
|
| }
|
|
|
| -bool Range::Intersects(const Range& range) const {
|
| - return IsValid() && range.IsValid() &&
|
| - !(range.GetMax() < GetMin() || range.GetMin() >= GetMax());
|
| +bool RangeIsEmpty(const TRangeBase<size_t>& range) {
|
| + return range.start() == range.end();
|
| }
|
|
|
| -bool Range::Contains(const Range& range) const {
|
| - return IsValid() && range.IsValid() &&
|
| - GetMin() <= range.GetMin() && range.GetMax() <= GetMax();
|
| +bool RangeIsEmpty(const TRangeBase<float>& range) {
|
| + return !range.IsValid() || range.start() == range.end();
|
| }
|
|
|
| -Range Range::Intersect(const Range& range) const {
|
| - size_t min = std::max(GetMin(), range.GetMin());
|
| - size_t max = std::min(GetMax(), range.GetMax());
|
| -
|
| - if (min >= max) // No intersection.
|
| - return InvalidRange();
|
| -
|
| - return Range(min, max);
|
| -}
|
| +} // namespace internal
|
|
|
| -std::string Range::ToString() const {
|
| - return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end());
|
| +std::ostream& operator<<(std::ostream& os, const Range& range) {
|
| + return os << range.ToString();
|
| }
|
|
|
| -std::ostream& operator<<(std::ostream& os, const Range& range) {
|
| +std::ostream& operator<<(std::ostream& os, const RangeF& range) {
|
| return os << range.ToString();
|
| }
|
|
|
|
|