• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / vector_math.dart / 17181727464

04 Aug 2025 07:19PM UTC coverage: 26.702% (+0.3%) from 26.388%
17181727464

push

github

web-flow
Bump min SDK to 3.7, update dependencies, reformat (#348)

496 of 1182 new or added lines in 55 files covered. (41.96%)

18 existing lines in 8 files now uncovered.

4463 of 16714 relevant lines covered (26.7%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.16
/lib/src/vector_math/aabb2.dart
1
// Copyright (c) 2015, Google Inc. Please see the AUTHORS file for details.
2
// All rights reserved. Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4

5
part of '../../vector_math.dart';
6

7
/// Defines a 2-dimensional axis-aligned bounding box between a [min] and a
8
/// [max] position.
9
class Aabb2 {
10
  final Vector2 _min;
11
  final Vector2 _max;
12

13
  /// The minimum point defining the AABB.
14
  Vector2 get min => _min;
2✔
15

16
  /// The maximum point defining the AABB.
17
  Vector2 get max => _max;
2✔
18

19
  /// The center of the AABB.
20
  Vector2 get center =>
1✔
21
      _min.clone()
2✔
22
        ..add(_max)
2✔
23
        ..scale(0.5);
1✔
24

25
  /// Create a new AABB with [min] and [max] set to the origin.
26
  Aabb2() : _min = Vector2.zero(), _max = Vector2.zero();
3✔
27

28
  /// Create a new AABB as a copy of [other].
29
  Aabb2.copy(Aabb2 other)
×
NEW
30
    : _min = Vector2.copy(other._min),
×
NEW
31
      _max = Vector2.copy(other._max);
×
32

33
  /// Create a new AABB with a [min] and [max].
34
  Aabb2.minMax(Vector2 min, Vector2 max)
1✔
35
    : _min = Vector2.copy(min),
1✔
36
      _max = Vector2.copy(max);
1✔
37

38
  /// Create a new AABB with a [center] and [halfExtents].
39
  factory Aabb2.centerAndHalfExtents(Vector2 center, Vector2 halfExtents) =>
1✔
40
      Aabb2()..setCenterAndHalfExtents(center, halfExtents);
2✔
41

42
  /// Constructs [Aabb2] with a min/max storage that views given [buffer]
43
  /// starting at [offset]. [offset] has to be multiple of
44
  /// [Float32List.bytesPerElement].
45
  Aabb2.fromBuffer(ByteBuffer buffer, int offset)
×
NEW
46
    : _min = Vector2.fromBuffer(buffer, offset),
×
NEW
47
      _max = Vector2.fromBuffer(
×
48
        buffer,
NEW
49
        offset + Float32List.bytesPerElement * 2,
×
50
      );
51

52
  /// Set the AABB by a [center] and [halfExtents].
53
  void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) {
1✔
54
    _min
1✔
55
      ..setFrom(center)
1✔
56
      ..sub(halfExtents);
1✔
57
    _max
1✔
58
      ..setFrom(center)
1✔
59
      ..add(halfExtents);
1✔
60
  }
61

62
  /// Copy the [center] and the [halfExtents] of this.
63
  void copyCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) {
1✔
64
    center
65
      ..setFrom(_min)
2✔
66
      ..add(_max)
2✔
67
      ..scale(0.5);
1✔
68
    halfExtents
69
      ..setFrom(_max)
2✔
70
      ..sub(_min)
2✔
71
      ..scale(0.5);
1✔
72
  }
73

74
  /// Copy the [min] and [max] from [other] into this.
75
  void copyFrom(Aabb2 other) {
×
76
    _min.setFrom(other._min);
×
77
    _max.setFrom(other._max);
×
78
  }
79

80
  static final _center = Vector2.zero();
3✔
81
  static final _halfExtents = Vector2.zero();
3✔
82
  void _updateCenterAndHalfExtents() =>
1✔
83
      copyCenterAndHalfExtents(_center, _halfExtents);
3✔
84

85
  /// Transform this by the transform [t].
86
  void transform(Matrix3 t) {
1✔
87
    _updateCenterAndHalfExtents();
1✔
88
    t
89
      ..transform2(_center)
2✔
90
      ..absoluteRotate2(_halfExtents);
2✔
91
    _min
1✔
92
      ..setFrom(_center)
2✔
93
      ..sub(_halfExtents);
2✔
94
    _max
1✔
95
      ..setFrom(_center)
2✔
96
      ..add(_halfExtents);
2✔
97
  }
98

99
  /// Rotate this by the rotation matrix [t].
100
  void rotate(Matrix3 t) {
1✔
101
    _updateCenterAndHalfExtents();
1✔
102
    t.absoluteRotate2(_halfExtents);
2✔
103
    _min
1✔
104
      ..setFrom(_center)
2✔
105
      ..sub(_halfExtents);
2✔
106
    _max
1✔
107
      ..setFrom(_center)
2✔
108
      ..add(_halfExtents);
2✔
109
  }
110

111
  /// Create a copy of this that is transformed by the transform [t] and store
112
  /// it in [out].
NEW
113
  Aabb2 transformed(Matrix3 t, Aabb2 out) =>
×
114
      out
NEW
115
        ..copyFrom(this)
×
NEW
116
        ..transform(t);
×
117

118
  /// Create a copy of this that is rotated by the rotation matrix [t] and
119
  /// store it in [out].
NEW
120
  Aabb2 rotated(Matrix3 t, Aabb2 out) =>
×
121
      out
NEW
122
        ..copyFrom(this)
×
NEW
123
        ..rotate(t);
×
124

125
  /// Set the min and max of this so that this is a hull of this and
126
  /// [other].
127
  void hull(Aabb2 other) {
1✔
128
    Vector2.min(_min, other._min, _min);
4✔
129
    Vector2.max(_max, other._max, _max);
4✔
130
  }
131

132
  /// Set the min and max of this so that this contains [point].
133
  void hullPoint(Vector2 point) {
1✔
134
    Vector2.min(_min, point, _min);
3✔
135
    Vector2.max(_max, point, _max);
3✔
136
  }
137

138
  /// Return if this contains [other].
139
  bool containsAabb2(Aabb2 other) {
1✔
140
    final otherMax = other._max;
1✔
141
    final otherMin = other._min;
1✔
142

143
    return (_min.x < otherMin.x) &&
4✔
144
        (_min.y < otherMin.y) &&
4✔
145
        (_max.y > otherMax.y) &&
4✔
146
        (_max.x > otherMax.x);
4✔
147
  }
148

149
  /// Return if this contains [other].
150
  bool containsVector2(Vector2 other) =>
1✔
151
      (_min.x < other.x) &&
4✔
152
      (_min.y < other.y) &&
4✔
153
      (_max.x > other.x) &&
4✔
154
      (_max.y > other.y);
4✔
155

156
  /// Return if this intersects with [other].
157
  bool intersectsWithAabb2(Aabb2 other) {
1✔
158
    final otherMax = other._max;
1✔
159
    final otherMin = other._min;
1✔
160

161
    return (_min.x <= otherMax.x) &&
4✔
162
        (_min.y <= otherMax.y) &&
4✔
163
        (_max.x >= otherMin.x) &&
4✔
164
        (_max.y >= otherMin.y);
4✔
165
  }
166

167
  /// Return if this intersects with [other].
168
  bool intersectsWithVector2(Vector2 other) =>
1✔
169
      (_min.x <= other.x) &&
4✔
170
      (_min.y <= other.y) &&
4✔
171
      (_max.x >= other.x) &&
4✔
172
      (_max.y >= other.y);
4✔
173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc