Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1259)

Unified Diff: ui/gfx/range/range_f.h

Issue 876873003: Add float version of gfx::Range (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed 2 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/range/range.h ('k') | ui/gfx/range/range_f.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/range/range_f.h
diff --git a/ui/gfx/range/range_f.h b/ui/gfx/range/range_f.h
new file mode 100644
index 0000000000000000000000000000000000000000..49bc7601e32cd9062993e6c4903eead96c4b38d1
--- /dev/null
+++ b/ui/gfx/range/range_f.h
@@ -0,0 +1,82 @@
+// 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.
+
+#ifndef UI_GFX_RANGE_RANGE_F_H_
+#define UI_GFX_RANGE_RANGE_F_H_
+
+#include <ostream>
+#include <string>
+
+#include "base/basictypes.h"
+#include "ui/gfx/gfx_export.h"
+
+namespace gfx {
+
+// A float version of Range. RangeF is made of a start and end position; when
+// they are the same, the range is empty. Note that |start_| can be greater
+// than |end_| to respect the directionality of the range.
+class GFX_EXPORT RangeF {
+ public:
+ // Creates an empty range {0,0}.
+ RangeF();
+
+ // Initializes the range with a start and end.
+ RangeF(float start, float end);
+
+ // Initializes the range with the same start and end positions.
+ explicit RangeF(float position);
+
+ // Returns a range that is invalid, which is {float_max,float_max}.
+ static const RangeF InvalidRange();
+
+ // Checks if the range is valid through comparison to InvalidRange().
+ bool IsValid() const;
+
+ // Getters and setters.
+ float start() const { return start_; }
+ void set_start(float start) { start_ = start; }
+
+ float end() const { return end_; }
+ void set_end(float end) { end_ = end; }
+
+ // Returns the absolute value of the length.
+ float length() const {
+ const float length = end() - start();
+ return length >= 0 ? length : -length;
+ }
+
+ bool is_reversed() const { return start() > end(); }
+ bool is_empty() const { return start() == end(); }
+
+ // Returns the minimum and maximum values.
+ float GetMin() const;
+ float GetMax() const;
+
+ bool operator==(const RangeF& other) const;
+ bool operator!=(const RangeF& other) const;
+ bool EqualsIgnoringDirection(const RangeF& other) const;
+
+ // Returns true if this range intersects the specified |range|.
+ bool Intersects(const RangeF& range) const;
+
+ // Returns true if this range contains the specified |range|.
+ bool Contains(const RangeF& range) const;
+
+ // Computes the intersection of this range with the given |range|.
+ // If they don't intersect, it returns an InvalidRange().
+ // The returned range is always empty or forward (never reversed).
+ RangeF Intersect(const RangeF& range) const;
+
+ std::string ToString() const;
+
+ private:
+ float start_;
+ float end_;
+};
+
+GFX_EXPORT std::ostream& operator<<(std::ostream& os, const RangeF& range);
+
+} // namespace gfx
+
+#endif // UI_GFX_RANGE_RANGE_F_H_
« no previous file with comments | « ui/gfx/range/range.h ('k') | ui/gfx/range/range_f.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698