|
1 | 1 | // Copyright 2012 Daniel Connelly. All rights reserved. |
2 | 2 | // Use of this source code is governed by a BSD-style |
3 | 3 | // license that can be found in the LICENSE file. |
| 4 | +// 为了简单表述,下面注释中把所有包络框或者叫边界框,叫做最小外接矩形边框 |
4 | 5 |
|
5 | 6 | package rtreego |
6 | 7 |
|
@@ -142,7 +143,8 @@ func (p Point) minMaxDist(r Rect) float64 { |
142 | 143 | // Rect represents a subset of n-dimensional Euclidean space of the form |
143 | 144 | // [a1, b1] x [a2, b2] x ... x [an, bn], where ai < bi for all 1 <= i <= n. |
144 | 145 | type Rect struct { |
145 | | - p, q Point // Enforced by NewRect: p[i] <= q[i] for all i. |
| 146 | + p, q Point // Enforced by NewRect: p[i] <= q[i] for all i. |
| 147 | + parent *node |
146 | 148 | } |
147 | 149 |
|
148 | 150 | // PointCoord returns the coordinate of the point of the rectangle at i |
@@ -181,6 +183,23 @@ func (r Rect) String() string { |
181 | 183 | return strings.Join(s, "x") |
182 | 184 | } |
183 | 185 |
|
| 186 | +func (r Rect) SetParent(parent *node) Spatial { |
| 187 | + r.parent = parent |
| 188 | + return r |
| 189 | +} |
| 190 | + |
| 191 | +func (r Rect) GetParent() *node { |
| 192 | + return r.parent |
| 193 | +} |
| 194 | + |
| 195 | +func (r Rect) Bounds() Rect { |
| 196 | + return r |
| 197 | +} |
| 198 | + |
| 199 | +func (r Rect) StartEnd() []Point { |
| 200 | + return []Point{r.p, r.q} |
| 201 | +} |
| 202 | + |
184 | 203 | // NewRect constructs and returns a pointer to a Rect given a corner point and |
185 | 204 | // the lengths of each dimension. The point p should be the most-negative point |
186 | 205 | // on the rectangle (in every dimension) and every length should be positive. |
@@ -227,6 +246,8 @@ func NewRectFromPoints(minPoint, maxPoint Point) (r Rect, err error) { |
227 | 246 | } |
228 | 247 |
|
229 | 248 | // Size computes the measure of a rectangle (the product of its side lengths). |
| 249 | +// |
| 250 | +// 返回矩形的测度如面积/体积等。 |
230 | 251 | func (r Rect) Size() float32 { |
231 | 252 | size := float32(1.0) |
232 | 253 | for i, a := range r.p { |
@@ -345,10 +366,12 @@ func (p Point) ToRect(tol float32) Rect { |
345 | 366 | a[i] = p[i] - tol |
346 | 367 | b[i] = p[i] + tol |
347 | 368 | } |
348 | | - return Rect{a, b} |
| 369 | + return Rect{a, b, nil} |
349 | 370 | } |
350 | 371 |
|
351 | 372 | // boundingBox constructs the smallest rectangle containing both r1 and r2. |
| 373 | +// |
| 374 | +// 构建出同时包含 r1 和 r2 的最小矩形。 |
352 | 375 | func boundingBox(r1, r2 Rect) (bb Rect) { |
353 | 376 | dim := len(r1.p) |
354 | 377 | bb.p = make([]float32, dim) |
|
0 commit comments