• 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

0.0
/lib/src/vector_math_64/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_64.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;
×
15

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

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

25
  /// Create a new AABB with [min] and [max] set to the origin.
NEW
26
  Aabb2() : _min = Vector2.zero(), _max = Vector2.zero();
×
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)
×
NEW
35
    : _min = Vector2.copy(min),
×
NEW
36
      _max = Vector2.copy(max);
×
37

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

42
  /// Constructs [Aabb2] with a min/max storage that views given [buffer]
43
  /// starting at [offset]. [offset] has to be multiple of
44
  /// [Float64List.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 + Float64List.bytesPerElement * 2,
×
50
      );
51

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

62
  /// Copy the [center] and the [halfExtents] of this.
63
  void copyCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) {
×
64
    center
65
      ..setFrom(_min)
×
66
      ..add(_max)
×
67
      ..scale(0.5);
×
68
    halfExtents
69
      ..setFrom(_max)
×
70
      ..sub(_min)
×
71
      ..scale(0.5);
×
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();
×
81
  static final _halfExtents = Vector2.zero();
×
82
  void _updateCenterAndHalfExtents() =>
×
83
      copyCenterAndHalfExtents(_center, _halfExtents);
×
84

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

99
  /// Rotate this by the rotation matrix [t].
100
  void rotate(Matrix3 t) {
×
101
    _updateCenterAndHalfExtents();
×
102
    t.absoluteRotate2(_halfExtents);
×
103
    _min
×
104
      ..setFrom(_center)
×
105
      ..sub(_halfExtents);
×
106
    _max
×
107
      ..setFrom(_center)
×
108
      ..add(_halfExtents);
×
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) {
×
128
    Vector2.min(_min, other._min, _min);
×
129
    Vector2.max(_max, other._max, _max);
×
130
  }
131

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

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

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

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

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

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

167
  /// Return if this intersects with [other].
168
  bool intersectsWithVector2(Vector2 other) =>
×
169
      (_min.x <= other.x) &&
×
170
      (_min.y <= other.y) &&
×
171
      (_max.x >= other.x) &&
×
172
      (_max.y >= other.y);
×
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