Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gfx / range / range_f.h
blob49bc7601e32cd9062993e6c4903eead96c4b38d1
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.
5 #ifndef UI_GFX_RANGE_RANGE_F_H_
6 #define UI_GFX_RANGE_RANGE_F_H_
8 #include <ostream>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "ui/gfx/gfx_export.h"
14 namespace gfx {
16 // A float version of Range. RangeF is made of a start and end position; when
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();
24 // Initializes the range with a start and end.
25 RangeF(float start, float end);
27 // Initializes the range with the same start and end positions.
28 explicit RangeF(float position);
30 // Returns a range that is invalid, which is {float_max,float_max}.
31 static const RangeF InvalidRange();
33 // Checks if the range is valid through comparison to InvalidRange().
34 bool IsValid() const;
36 // Getters and setters.
37 float start() const { return start_; }
38 void set_start(float start) { start_ = start; }
40 float end() const { return end_; }
41 void set_end(float end) { end_ = end; }
43 // Returns the absolute value of the length.
44 float length() const {
45 const float length = end() - start();
46 return length >= 0 ? length : -length;
49 bool is_reversed() const { return start() > end(); }
50 bool is_empty() const { return start() == end(); }
52 // Returns the minimum and maximum values.
53 float GetMin() const;
54 float GetMax() const;
56 bool operator==(const RangeF& other) const;
57 bool operator!=(const RangeF& other) const;
58 bool EqualsIgnoringDirection(const RangeF& other) const;
60 // Returns true if this range intersects the specified |range|.
61 bool Intersects(const RangeF& range) const;
63 // Returns true if this range contains the specified |range|.
64 bool Contains(const RangeF& range) const;
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;
71 std::string ToString() const;
73 private:
74 float start_;
75 float end_;
78 GFX_EXPORT std::ostream& operator<<(std::ostream& os, const RangeF& range);
80 } // namespace gfx
82 #endif // UI_GFX_RANGE_RANGE_F_H_