X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flibnr%2Fnr-rect.cpp;h=1e1f3610443513441fea885abae7ebd4bf600d0c;hb=e5d48f600ce8a65ae81353fd39860227b2ef6e60;hp=72bced37bb048ca9337d8c03658710f412c2dd81;hpb=257feedb11b8dd66267acceba30e4c50992c04d5;p=inkscape.git diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index 72bced37b..1e1f36104 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -17,7 +17,7 @@ NRRect::NRRect(NR::Rect const &rect) x1(rect.max()[NR::X]), y1(rect.max()[NR::Y]) {} -NRRect::NRRect(NR::Maybe const &rect) { +NRRect::NRRect(boost::optional const &rect) { if (rect) { x0 = rect->min()[NR::X]; y0 = rect->min()[NR::Y]; @@ -28,14 +28,33 @@ NRRect::NRRect(NR::Maybe const &rect) { } } -NR::Maybe NRRect::upgrade() const { - if (nr_rect_d_test_empty(this)) { - return NR::Nothing(); +NRRect::NRRect(Geom::OptRect const &rect) { + if (rect) { + x0 = rect->min()[Geom::X]; + y0 = rect->min()[Geom::Y]; + x1 = rect->max()[Geom::X]; + y1 = rect->max()[Geom::Y]; + } else { + nr_rect_d_set_empty(this); + } +} + +boost::optional NRRect::upgrade() const { + if (nr_rect_d_test_empty_ptr(this)) { + return boost::optional(); } else { return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1)); } } +Geom::OptRect NRRect::upgrade_2geom() const { + if (nr_rect_d_test_empty_ptr(this)) { + return Geom::OptRect(); + } else { + return Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)); + } +} + /** * \param r0 Rectangle. * \param r1 Another rectangle. @@ -204,7 +223,7 @@ nr_rect_d_matrix_transform(NRRect *d, NRRect const *const s, NR::Matrix const &m using NR::X; using NR::Y; - if (nr_rect_d_test_empty(s)) { + if (nr_rect_d_test_empty_ptr(s)) { nr_rect_d_set_empty(d); } else { NR::Point const c00(NR::Point(s->x0, s->y0) * m); @@ -224,7 +243,7 @@ nr_rect_d_matrix_transform(NRRect *d, NRRect const *const s, NR::Matrix const &m } NRRect * -nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NRMatrix const *m) +nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const *m) { return nr_rect_d_matrix_transform(d, s, *m); } @@ -266,6 +285,18 @@ Point Rect::midpoint() const { return ( _min + _max ) / 2; } +Point Rect::cornerFarthestFrom(Point const &p) const { + Point m = midpoint(); + unsigned i = 0; + if (p[X] < m[X]) { + i = 1; + } + if (p[Y] < m[Y]) { + i = 3 - i; + } + return corner(i); +} + /** returns a vector from topleft to bottom right. */ Point Rect::dimensions() const { return _max - _min; @@ -296,17 +327,17 @@ void Rect::growBy(double size) { } /** Returns the set of points shared by both rectangles. */ -Maybe intersection(Maybe const & a, Maybe const & b) { +boost::optional intersection(boost::optional const & a, boost::optional const & b) { if ( !a || !b ) { - return Nothing(); + return boost::optional(); } else { Rect r; for ( int i=0 ; i < 2 ; i++ ) { r._min[i] = std::max(a->_min[i], b->_min[i]); r._max[i] = std::min(a->_max[i], b->_max[i]); if ( r._min[i] > r._max[i] ) { - return Nothing(); - } + return boost::optional(); + } } return r; }