# 四分木

このページでは、 ユーティリティ ライブラリ をご覧ください

## 四分木を追加して指定領域の点を検索する

### Swift

```import GoogleMapsUtils

private let gqtPoint : GQTPoint

init(point : GQTPoint) {
self.gqtPoint = point
}

func point() -> GQTPoint {
return gqtPoint
}

/// Function demonstrating how to create and use a quadtree
private func test() {

// Create a quadtree with bounds of [-2, -2] to [2, 2].
let bounds = GQTBounds(minX: -2, minY: -2, maxX: 2, maxY: 2)
guard let tree = GQTPointQuadTree(bounds: bounds) else {
return
}

// Add 4 points to the tree.

// Search for items within the rectangle with lower corner of (-1.5, -1.5)
// and upper corner of (1.5, 1.5).
let searchBounds = GQTBounds(minX: -1.5, minY: -1.5, maxX: 1.5, maxY: 1.5)
for item in tree.search(with: searchBounds) as! [QuadTreeItem] {
print("(\(item.point().x), \(item.point().y))");
}
}
}
```

### Objective-C

```@import GoogleMapsUtils;

- (instancetype)initWithPoint:(GQTPoint)point;
@end

GQTPoint _point;
}

- (instancetype)initWithPoint:(GQTPoint)point {
if ((self = [super init])) {
_point = point;
}
return self;
}

- (GQTPoint)point {
return _point;
}

/// Function demonstrating how to create and use a quadtree
- (void)test {
// Create a quadtree with bounds of [-2, -2] to [2, 2].
GQTBounds bounds = {-2, -2, 2, 2};

// Add 4 points to the tree.

// Search for items within the rectangle with lower corner of (-1.5, -1.5)
// and upper corner of (1.5, 1.5).
NSArray *foundItems = [tree searchWithBounds:(GQTBounds){-1.5, -1.5, 1.5, 1.5}];

for (QuadTreeItem *item in foundItems) {
NSLog(@"(%lf, %lf)", item.point.x, item.point.y);
}
}

@end
```
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"必要な情報がない" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"複雑すぎる / 手順が多すぎる" },{ "type": "thumb-down", "id": "outOfDate", "label":"最新ではない" },{ "type": "thumb-down", "id": "translationIssue", "label":"翻訳に関する問題" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"サンプル / コードに問題がある" },{ "type": "thumb-down", "id": "otherDown", "label":"その他" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"わかりやすい" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"問題の解決に役立った" },{ "type": "thumb-up", "id": "otherUp", "label":"その他" }]
{"lastModified": "\u6700\u7d42\u66f4\u65b0\u65e5 2024-09-11 UTC\u3002"}