Go to the documentation of this file.
20 #ifndef GNASH_SNAPPINGRANGE_H
21 #define GNASH_SNAPPINGRANGE_H
74 template<
typename T>
inline bool snaptest(
75 const geometry::Range2d<T>& range1,
76 const geometry::Range2d<T>& range2,
const float snapFactor);
87 template<
typename U>
friend std::ostream&
operator<<(std::ostream& os,
100 template <
typename U>
126 assert(factor > 1.0
f);
127 _snapFactor = factor;
146 _rangesLimit = limit;
156 _snapFactor = from._snapFactor;
157 _singleMode = from._singleMode;
167 _snapFactor(snapFactor)
171 if (snaptest(
r, _rt, _snapFactor)) {
179 const float _snapFactor;
196 GrowBy(
const float factor) : _factor(factor) {}
256 if (range.
isNull())
return;
259 if (_ranges.empty()) _ranges.resize(1);
260 _ranges[0].expandTo(range);
264 ExpandToIfSnap exp(range, _snapFactor);
265 if (
visit(exp))
return;
268 _ranges.push_back(range);
284 std::for_each(_ranges.begin(), _ranges.end(), GrowBy(amount));
293 std::for_each(_ranges.begin(), _ranges.end(), Scale(factor));
306 _ranges[0].setWorld();
311 return ((
size()==1) && (_ranges.front().isWorld()));
316 return _ranges.empty();
322 return _ranges.size();
328 assert(index<
size());
329 return _ranges[index];
339 int rcount = _ranges.size();
341 for (
int rno=0; rno<rcount; rno++)
356 return std::find_if(_ranges.begin(), _ranges.end(), IntersectsRange(
r))
364 return std::find_if(_ranges.begin(), _ranges.end(), ContainsPoint(
x,
y))
376 return std::find_if(_ranges.begin(), _ranges.end(), ContainsRange(
r))
395 if (
isNull() )
return false;
396 if (
o.isNull() )
return false;
406 for (
unsigned rno=0, rcount=
o.size(); rno<rcount; rno++)
432 if (
o.isWorld())
return;
438 std::vector<SnappingRanges2d<T> > list;
439 list.reserve(
o.size());
442 for (
unsigned rno=0, rcount=
o.size(); rno<rcount; rno++) {
445 list.push_back(*
this);
448 list.back().intersect(
o.getRange(rno));
454 for (
auto& range : list) {
481 if (
r.isWorld())
return;
484 for (
int rno=_ranges.size()-1; rno>=0; rno--) {
489 _ranges.erase(_ranges.begin() + rno);
491 _ranges[rno] = newrange;
500 if (_singleMode)
return;
508 int rcount = _ranges.size();
512 for (
int i=0;
i<rcount;
i++) {
514 for (
int j=
i+1;
j<rcount;
j++) {
516 if (snaptest(_ranges[
i], _ranges[
j], _snapFactor)) {
518 _ranges[
i].expandTo(_ranges[
j]);
520 _ranges.erase(_ranges.begin() +
j);
533 if (_ranges.size() > _rangesLimit) {
557 template<
class V>
inline bool visit(
V& visitor)
const
559 typename RangeList::iterator it,
e;
560 for (it = _ranges.begin(),
e = _ranges.end(); it !=
e; ++it) {
561 if (!visitor(*it))
break;
563 return it != _ranges.end();
573 template<
class V>
inline void visitAll(
V& visitor)
const
575 for_each(_ranges.begin(), _ranges.end(), visitor);
583 void combineRangesLazy()
const {
589 void finalize()
const {
617 if (
r.isNull() )
return os <<
"NULL";
618 if (
r.isWorld() )
return os <<
"WORLD";
622 const R& ranges =
r._ranges;
624 std::copy(ranges.begin(), ranges.end(),
625 std::ostream_iterator<typename R::value_type>(os,
","));
Definition: snappingrange.h:81
2d Range template class
Definition: Range2d.h:78
@ R
Definition: GnashKey.h:130
SnappingRanges2d(const SnappingRanges2d< U > &from)
Templated copy constructor, for casting between range types.
Definition: snappingrange.h:101
RangeList::size_type size_type
Definition: snappingrange.h:85
void combineRanges() const
Definition: snappingrange.h:497
@ T
Definition: GnashKey.h:132
geometry::Range2d< T > RangeType
Definition: snappingrange.h:83
std::int32_t y
Definition: BitmapData_as.cpp:435
@ i
Definition: GnashKey.h:155
AddTo(SnappingRanges2d< T > &us)
Definition: snappingrange.h:207
Definition: snappingrange.h:183
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
bool contains(const RangeType &r) const
Returns true if any of the ranges contains the range.
Definition: snappingrange.h:373
void operator()(RangeType &r)
Definition: snappingrange.h:186
ContainsRange(const RangeType &range)
Definition: snappingrange.h:240
bool getSingleMode() const
Definition: snappingrange.h:139
bool isWorld() const
Returns true, when the ranges equal world range.
Definition: snappingrange.h:310
Definition: snappingrange.h:238
Range2d< T > & expandTo(T x, T y)
Expand this Range2d to enclose the given point.
Definition: Range2d.h:297
bool isNull() const
Returns true, when there is no range.
Definition: snappingrange.h:315
Scale(const float scale)
Definition: snappingrange.h:185
bool operator()(const RangeType &us)
Definition: snappingrange.h:219
bool isNull() const
Returns true if this is the NULL Range2d.
Definition: Range2d.h:181
void inheritConfig(const SnappingRanges2d< T > &from)
Definition: snappingrange.h:155
Definition: snappingrange.h:205
void add(const SnappingRanges2d< T > &other)
combines two snapping ranges
Definition: snappingrange.h:274
Range2d< T > Intersection(const Range2d< T > &r1, const Range2d< T > &r2)
Return a rectangle being the intersetion of the two rectangles.
Definition: Range2d.h:762
ExpandToIfSnap(const RangeType &rt, const float snapFactor)
Definition: snappingrange.h:164
void visitAll(V &visitor) const
Visit the current Ranges set.
Definition: snappingrange.h:573
@ r
Definition: GnashKey.h:164
bool isWorld() const
Returns true if this is the WORLD Range2d.
Definition: Range2d.h:200
GrowBy(const float factor)
Definition: snappingrange.h:196
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
bool intersects(const RangeType &r) const
Returns true if any of the ranges intersect the given range.
Definition: snappingrange.h:353
geometry::SnappingRanges2d< std::int32_t > InvalidatedRanges
Standard snapping 2d ranges type for invalidated bounds calculation
Definition: snappingrange.h:655
bool operator()(const RangeType &us)
Definition: snappingrange.h:241
void setSnapFactor(const float factor)
Definition: snappingrange.h:125
float getSnapFactor() const
Definition: snappingrange.h:130
void intersect(const SnappingRanges2d< T > &o)
Definition: snappingrange.h:425
void setSingleMode(const bool mode)
if mode==true, then the snapping ranges will act like a normal Range2d
Definition: snappingrange.h:135
size_type getRangeCountLimit() const
Definition: snappingrange.h:149
bool operator()(const RangeType &us)
Definition: snappingrange.h:230
bool operator()(RangeType &r)
Definition: snappingrange.h:170
void intersect(const RangeType &r)
Definition: snappingrange.h:463
Merge two ranges based on snaptest.
Definition: snappingrange.h:162
bool intersects(const Range2d< T > &other) const
Return true if this rectangle intersects the point with given coordinates (boundaries are inclusive).
Definition: Range2d.h:281
RangeType getFullArea() const
Definition: snappingrange.h:334
Definition: snappingrange.h:227
size_type size() const
Returns the number of ranges in the list.
Definition: snappingrange.h:320
@ j
Definition: GnashKey.h:156
Definition: snappingrange.h:194
bool contains(U x, U y) const
Return true if this rectangle contains the point with given coordinates (boundaries are inclusive).
Definition: Range2d.h:241
void add(const RangeType &range)
Add a Range to the set, merging when possible and appropriate.
Definition: snappingrange.h:250
void setNull()
Resets to NULL range.
Definition: snappingrange.h:298
bool visit(V &visitor) const
Visit the current Ranges set.
Definition: snappingrange.h:557
@ V
Definition: GnashKey.h:134
@ f
Definition: GnashKey.h:152
SnappingRanges2d()
Definition: snappingrange.h:90
void growBy(const T amount)
Grows all ranges by the specified amount.
Definition: snappingrange.h:280
std::vector< RangeType > RangeList
Definition: snappingrange.h:84
friend std::ostream & operator<<(std::ostream &os, const SnappingRanges2d< U > &r)
bool contains(T x, T y) const
Returns true if any of the ranges contains the point.
Definition: snappingrange.h:361
detail::Promote< T >::type getArea() const
Get area (width*height)
Definition: Range2d.h:643
void setRangeCountLimit(const size_type limit)
Definition: snappingrange.h:145
bool contains(const SnappingRanges2d< T > &o) const
Returns true if all ranges in the given SnappingRanges2d are contained in at least one of the ranges ...
Definition: snappingrange.h:388
Definition: snappingrange.h:216
Range2d< T > & setNull()
Set the Range2d to the NULL value.
Definition: Range2d.h:190
const RangeType & getRange(size_type index) const
Returns the range at the specified index.
Definition: snappingrange.h:326
@ o
Definition: GnashKey.h:161
void operator()(RangeType &r)
Definition: snappingrange.h:197
void operator()(const RangeType &r)
Definition: snappingrange.h:208
std::int32_t x
Definition: BitmapData_as.cpp:434
void scale(const float factor)
Scale all ranges by the specified factor.
Definition: snappingrange.h:289
@ e
Definition: GnashKey.h:151
IntersectsRange(const RangeType &range)
Definition: snappingrange.h:218
std::ostream & operator<<(std::ostream &os, const Point2d &p)
Output operator.
Definition: Point2d.h:136
void setWorld()
Resets to one range with world flags.
Definition: snappingrange.h:303
ContainsPoint(const T x, const T y)
Definition: snappingrange.h:229