diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-11-24 13:09:09 +0200 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-29 07:22:05 -0400 |
commit | 59ce8663f9a20f8bd7a16620b8bccaa23357be36 (patch) | |
tree | 40914fea1a3ac744d1da3590914627785d5cfd85 /libs/canvas/rectangle.cc | |
parent | 6e335ca5d90ddc62b0af9a60a6b156ed74ac8eb1 (diff) |
add Rectangle::vertical_fraction() as a convenience method
Conflicts:
libs/canvas/rectangle.cc
Diffstat (limited to 'libs/canvas/rectangle.cc')
-rw-r--r-- | libs/canvas/rectangle.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libs/canvas/rectangle.cc b/libs/canvas/rectangle.cc index 07288d5d33..4bb21c42e6 100644 --- a/libs/canvas/rectangle.cc +++ b/libs/canvas/rectangle.cc @@ -266,3 +266,23 @@ Rectangle::set_outline_what (What what) end_visual_change (); } } + +double +Rectangle::vertical_fraction (double y) const +{ + /* y is in canvas coordinates */ + + Duple i (canvas_to_item (Duple (0, y))); + boost::optional<Rect> r = bounding_box(); + if (!r) { + return 0; /* not really correct, but what else can we do? */ + } + + Rect bbox (r.get()); + + if (i.y < bbox.y0 || i.y >= bbox.y1) { + return 0; + } + + return (i.y - bbox.y0) / bbox.height(); +} |