rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SkBBoxHierarchy_DEFINED |
| 10 | #define SkBBoxHierarchy_DEFINED |
| 11 | |
| 12 | #include "SkRect.h" |
| 13 | #include "SkTDArray.h" |
| 14 | |
| 15 | /** |
| 16 | * Interface for a spatial data structure that associates user data pointers with axis-aligned |
| 17 | * bounding boxes, and allows efficient retrieval of intersections with query rectangles. |
| 18 | */ |
| 19 | class SkBBoxHierarchy { |
| 20 | public: |
| 21 | virtual ~SkBBoxHierarchy() { } |
| 22 | |
| 23 | /** |
| 24 | * Insert a data pointer and corresponding bounding box |
| 25 | * @param data The data pointer, may be NULL |
| 26 | * @param bounds The bounding box, should not be empty |
| 27 | * @param defer Whether or not it is acceptable to delay insertion of this element (building up |
| 28 | * an entire spatial data structure at once is often faster and produces better |
| 29 | * structures than repeated inserts) until flushDeferredInserts is called or the first |
| 30 | * search. |
| 31 | */ |
| 32 | virtual void insert(void* data, const SkIRect& bounds, bool defer = false) = 0; |
| 33 | |
| 34 | /** |
| 35 | * If any insertions have been deferred, this forces them to be inserted |
| 36 | */ |
| 37 | virtual void flushDeferredInserts() = 0; |
| 38 | |
| 39 | /** |
| 40 | * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query' |
| 41 | */ |
| 42 | virtual void search(const SkIRect& query, SkTDArray<void*>* results) = 0; |
| 43 | |
| 44 | virtual void clear() = 0; |
| 45 | |
| 46 | /** |
| 47 | * Gets the number of insertions |
| 48 | */ |
| 49 | virtual int getCount() const = 0; |
| 50 | }; |
| 51 | |
| 52 | #endif |
| 53 | |