summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 85fed18)
raw | patch | inline | side by side (parent: 85fed18)
author | mental <mental@users.sourceforge.net> | |
Fri, 9 Mar 2007 00:25:51 +0000 (00:25 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Fri, 9 Mar 2007 00:25:51 +0000 (00:25 +0000) |
avoid some copies
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index 21d3f470ad129e1d60b5def6035b06a16084f4ee..9047e4e1c53faa2762b0bffe5b22aeea695800df 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
}
/** Returns the set of points shared by both rectangles. */
-Maybe<Rect> Rect::intersection(Maybe<Rect> const &a, Maybe<Rect> const &b) {
+Maybe<Rect> intersection(Maybe<Rect const &> a, Maybe<Rect const &> b) {
if ( !a || !b ) {
return Nothing();
} else {
}
/** returns the smallest rectangle containing both rectangles */
-Rect Rect::union_bounds(Rect const &a, Rect const &b) {
+Rect union_bounds(Rect const &a, Rect const &b) {
Rect r;
for ( int i=0 ; i < 2 ; i++ ) {
r._min[i] = MIN(a._min[i], b._min[i]);
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index dd7caa897ea100c4a59704df33943926033ada89..5e2332bf278315765af1a0d850e628f04e0275fc 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
_max[NR::Y] += by;
}
- /** Returns the set of points shared by both rectangles. */
- static Maybe<Rect> intersection(Maybe<Rect> const &a, Maybe<Rect> const &b);
-
- /** Returns the smallest rectangle that encloses both rectangles. */
- static Maybe<Rect> union_bounds(Maybe<Rect> const &a, Maybe<Rect> const &b)
- {
- if (!a) {
- return b;
- } else if (!b) {
- return a;
- } else {
- return union_bounds(*a, *b);
- }
- }
- static Rect union_bounds(Maybe<Rect> const &a, Rect const &b) {
- if (a) {
- return union_bounds(*a, b);
- } else {
- return b;
- }
- }
- static Rect union_bounds(Rect const &a, Maybe<Rect> const &b) {
- if (b) {
- return union_bounds(a, *b);
- } else {
- return a;
- }
- }
- static Rect union_bounds(Rect const &a, Rect const &b);
-
/** Scales the rect by s, with origin at 0, 0 */
inline Rect operator*(double const s) const {
return Rect(s * min(), s * max());
friend inline std::ostream &operator<<(std::ostream &out_file, NR::Rect const &in_rect);
private:
+ Rect(Nothing) : _min(1, 1), _max(-1, -1) {}
+
static double _inf() {
return std::numeric_limits<double>::infinity();
}
Point _min, _max;
- /* evil, but temporary */
- friend class Maybe<Rect>;
+ friend class MaybeStorage<Rect>;
};
+template <>
+class MaybeStorage<Rect> {
+public:
+ MaybeStorage() : _rect(Nothing()) {}
+ MaybeStorage(Rect const &rect) : _rect(rect) {}
+
+ bool is_nothing() const {
+ return _rect._min[X] > _rect._max[X];
+ }
+ Rect const &value() const { return _rect; }
+ Rect &value() { return _rect; }
+
+private:
+ Rect _rect;
+};
+
+/** Returns the set of points shared by both rectangles. */
+Maybe<Rect> intersection(Maybe<Rect const &> a, Maybe<Rect const &> b);
+
+/** Returns the smallest rectangle that encloses both rectangles. */
+Rect union_bounds(Rect const &a, Rect const &b);
+inline Rect union_bounds(Maybe<Rect const &> a, Rect const &b) {
+ if (a) {
+ return union_bounds(*a, b);
+ } else {
+ return b;
+ }
+}
+inline Rect union_bounds(Rect const &a, Maybe<Rect const &> b) {
+ if (b) {
+ return union_bounds(a, *b);
+ } else {
+ return a;
+ }
+}
+inline Maybe<Rect> union_bounds(Maybe<Rect const &> a, Maybe<Rect const &> b)
+{
+ if (!a) {
+ return b;
+ } else if (!b) {
+ return a;
+ } else {
+ return union_bounds(*a, *b);
+ }
+}
+
/** A function to print out the rectange if sent to an output
stream. */
inline std::ostream
index 57fa6bb848b9a7486bef57376a5bfb67349996c7..a65c9b2900bfc2c54ab91a17979034b30c0a5276 100644 (file)
NR::Maybe<NR::Rect> r = NR::Nothing();
for (GSList const *i = items; i; i = i->next) {
- r = NR::Rect::union_bounds(r, sp_item_bbox_desktop((SPItem *) i->data));
+ r = NR::union_bounds(r, sp_item_bbox_desktop((SPItem *) i->data));
}
return r;
}
diff --git a/src/selection.cpp b/src/selection.cpp
index 5c60e5f41e76652079dab454d900d697e5583815..49934cfd39ccb16591d2bcf00d1eae3ca84a542f 100644 (file)
--- a/src/selection.cpp
+++ b/src/selection.cpp
NR::Maybe<NR::Rect> bbox = NR::Nothing();
for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox = NR::Rect::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
+ bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
}
// TODO: return NR::Maybe<NR::Rect>
index 78e706a259647d819354a2f9a2d3d8c45506950f..f386aefcce57e575905f56b19e3676b46537c147 100644 (file)
NR::Rect const viewbox = _svg_canvas.spobj()->getViewbox();
/* Viewbox is always included into scrollable region */
- carea = NR::Rect::union_bounds(carea, viewbox);
+ carea = NR::union_bounds(carea, viewbox);
Gtk::Adjustment *adj = _bottom_scrollbar.get_adjustment();
adj->set_value(viewbox.min()[NR::X]);
index eb813a2a2dba7a1a69c10d5af42daef735199935..76313f7719240e41900072baf39b1bd01e313e35 100644 (file)
NR::Rect viewbox = dtw->canvas->getViewbox();
/* Viewbox is always included into scrollable region */
- carea = NR::Rect::union_bounds(carea, viewbox);
+ carea = NR::union_bounds(carea, viewbox);
set_adjustment(dtw->hadj, carea.min()[NR::X], carea.max()[NR::X],
viewbox.dimensions()[NR::X],