Skip to content

Commit 96a2789

Browse files
committed
增加获取直系子节点和获取父节点计算边界框的功能
1 parent 991b79d commit 96a2789

5 files changed

Lines changed: 153 additions & 36 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
**/.idea/
2+
.local

geom.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2012 Daniel Connelly. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
4+
// 为了简单表述,下面注释中把所有包络框或者叫边界框,叫做最小外接矩形边框
45

56
package rtreego
67

@@ -142,7 +143,8 @@ func (p Point) minMaxDist(r Rect) float64 {
142143
// Rect represents a subset of n-dimensional Euclidean space of the form
143144
// [a1, b1] x [a2, b2] x ... x [an, bn], where ai < bi for all 1 <= i <= n.
144145
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
146148
}
147149

148150
// PointCoord returns the coordinate of the point of the rectangle at i
@@ -181,6 +183,23 @@ func (r Rect) String() string {
181183
return strings.Join(s, "x")
182184
}
183185

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+
184203
// NewRect constructs and returns a pointer to a Rect given a corner point and
185204
// the lengths of each dimension. The point p should be the most-negative point
186205
// 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) {
227246
}
228247

229248
// Size computes the measure of a rectangle (the product of its side lengths).
249+
//
250+
// 返回矩形的测度如面积/体积等。
230251
func (r Rect) Size() float32 {
231252
size := float32(1.0)
232253
for i, a := range r.p {
@@ -345,10 +366,12 @@ func (p Point) ToRect(tol float32) Rect {
345366
a[i] = p[i] - tol
346367
b[i] = p[i] + tol
347368
}
348-
return Rect{a, b}
369+
return Rect{a, b, nil}
349370
}
350371

351372
// boundingBox constructs the smallest rectangle containing both r1 and r2.
373+
//
374+
// 构建出同时包含 r1 和 r2 的最小矩形。
352375
func boundingBox(r1, r2 Rect) (bb Rect) {
353376
dim := len(r1.p)
354377
bb.p = make([]float32, dim)

geom_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestMinDistZero(t *testing.T) {
345345

346346
func TestMinDistPositive(t *testing.T) {
347347
p := Point{1, 2, 3}
348-
r := Rect{Point{-1, -4, 7}, Point{2, -2, 9}}
348+
r := Rect{Point{-1, -4, 7}, Point{2, -2, 9}, nil}
349349
expected := float32((-2-2)*(-2-2) + (7-3)*(7-3))
350350
if d := p.minDist(r); math.Abs(d-float64(expected)) > EPS {
351351
t.Errorf("Expected %v.minDist(%v) == %v, got %v", p, r, expected, d)
@@ -354,7 +354,7 @@ func TestMinDistPositive(t *testing.T) {
354354

355355
func TestMinMaxdist(t *testing.T) {
356356
p := Point{-3, -2, -1}
357-
r := Rect{Point{0, 0, 0}, Point{1, 2, 3}}
357+
r := Rect{Point{0, 0, 0}, Point{1, 2, 3}, nil}
358358

359359
// furthest points from p on the faces closest to p in each dimension
360360
q1 := Point{0, 2, 3}

0 commit comments

Comments
 (0)