Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_GFX_RANGE_RANGE_F_H_ | |
| 6 #define UI_GFX_RANGE_RANGE_F_H_ | |
| 7 | |
| 8 #include <ostream> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "ui/gfx/gfx_export.h" | |
| 13 | |
| 14 namespace gfx { | |
| 15 | |
| 16 // A floating version of Range. RangeF is made of a start and end position; when | |
|
Robert Sesek
2015/02/12 16:52:37
floating -> float
ckocagil
2015/02/13 18:47:47
Done.
| |
| 17 // they are the same, the range is empty. Note that |start_| can be greater | |
| 18 // than |end_| to respect the directionality of the range. | |
| 19 class GFX_EXPORT RangeF { | |
| 20 public: | |
| 21 // Creates an empty range {0,0}. | |
| 22 RangeF(); | |
| 23 | |
| 24 // Initializes the range with a start and end. | |
| 25 RangeF(float start, float end); | |
| 26 | |
| 27 // Initializes the range with the same start and end positions. | |
| 28 explicit RangeF(float position); | |
| 29 | |
| 30 // Returns a range that is invalid, which is {NaN,NaN}. | |
| 31 static const RangeF InvalidRange(); | |
| 32 | |
| 33 // The range is valid if neither field is NaN. | |
|
msw
2015/02/12 21:01:04
nit: Duplicate the comment from Range: "// Checks
ckocagil
2015/02/13 18:47:47
We can't compare to InvalidRange() so I improved t
| |
| 34 bool IsValid() const; | |
| 35 | |
| 36 // Getters and setters. | |
| 37 float start() const { return start_; } | |
| 38 void set_start(float start) { start_ = start; } | |
| 39 | |
| 40 float end() const { return end_; } | |
| 41 void set_end(float end) { end_ = end; } | |
| 42 | |
| 43 // Returns the absolute value of the length. | |
| 44 float length() const { | |
| 45 const float length = end() - start(); | |
| 46 return length >= 0 ? length : -length; | |
| 47 } | |
| 48 | |
| 49 bool is_reversed() const { return start() > end(); } | |
| 50 bool is_empty() const { return !IsValid() || start() == end(); } | |
| 51 | |
| 52 // Returns the minimum and maximum values. | |
| 53 float GetMin() const; | |
| 54 float GetMax() const; | |
| 55 | |
| 56 bool operator==(const RangeF& other) const; | |
| 57 bool operator!=(const RangeF& other) const; | |
| 58 bool EqualsIgnoringDirection(const RangeF& other) const; | |
| 59 | |
| 60 // Returns true if this range intersects the specified |range|. | |
| 61 bool Intersects(const RangeF& range) const; | |
| 62 | |
| 63 // Returns true if this range contains the specified |range|. | |
| 64 bool Contains(const RangeF& range) const; | |
| 65 | |
| 66 // Computes the intersection of this range with the given |range|. | |
| 67 // If they don't intersect, it returns an InvalidRange(). | |
| 68 // The returned range is always empty or forward (never reversed). | |
| 69 RangeF Intersect(const RangeF& range) const; | |
| 70 | |
| 71 std::string ToString() const; | |
| 72 | |
| 73 private: | |
| 74 float start_; | |
| 75 float end_; | |
| 76 }; | |
| 77 | |
| 78 GFX_EXPORT std::ostream& operator<<(std::ostream& os, const RangeF& range); | |
| 79 | |
| 80 } // namespace gfx | |
| 81 | |
| 82 #endif // UI_GFX_RANGE_RANGE_F_H_ | |
| OLD | NEW |