Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ui / gfx / range / range_f.h
blobf7f9442e895351deaeb561f1eb89ea996a333453
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"
13 #include "ui/gfx/range/range.h"
15 namespace gfx {
17 // A float version of Range. RangeF is made of a start and end position; when
18 // they are the same, the range is empty. Note that |start_| can be greater
19 // than |end_| to respect the directionality of the range.
20 class GFX_EXPORT RangeF {
21 public:
22 // Creates an empty range {0,0}.
23 RangeF();
25 // Initializes the range with a start and end.
26 RangeF(float start, float end);
28 // Initializes the range with the same start and end positions.
29 explicit RangeF(float position);
31 // Returns a range that is invalid, which is {float_max,float_max}.
32 static const RangeF InvalidRange();
34 // Checks if the range is valid through comparison to InvalidRange().
35 bool IsValid() const;
37 // Getters and setters.
38 float start() const { return start_; }
39 void set_start(float start) { start_ = start; }
41 float end() const { return end_; }
42 void set_end(float end) { end_ = end; }
44 // Returns the absolute value of the length.
45 float length() const {
46 const float length = end() - start();
47 return length >= 0 ? length : -length;
50 bool is_reversed() const { return start() > end(); }
51 bool is_empty() const { return start() == end(); }
53 // Returns the minimum and maximum values.
54 float GetMin() const;
55 float GetMax() const;
57 bool operator==(const RangeF& other) const;
58 bool operator!=(const RangeF& other) const;
59 bool EqualsIgnoringDirection(const RangeF& other) const;
61 // Returns true if this range intersects the specified |range|.
62 bool Intersects(const RangeF& range) const;
64 // Returns true if this range contains the specified |range|.
65 bool Contains(const RangeF& range) const;
67 // Computes the intersection of this range with the given |range|.
68 // If they don't intersect, it returns an InvalidRange().
69 // The returned range is always empty or forward (never reversed).
70 RangeF Intersect(const RangeF& range) const;
71 RangeF Intersect(const Range& range) const;
73 // Floor/Ceil/Round the start and end values of the given RangeF.
74 Range Floor() const;
75 Range Ceil() const;
76 Range Round() const;
78 std::string ToString() const;
80 private:
81 float start_;
82 float end_;
85 GFX_EXPORT std::ostream& operator<<(std::ostream& os, const RangeF& range);
87 } // namespace gfx
89 #endif // UI_GFX_RANGE_RANGE_F_H_