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

google / vector_math.dart / 12224890780

08 Dec 2024 08:11PM UTC coverage: 26.372%. Remained the same
12224890780

Pull #337

github

web-flow
Merge 1b1108c78 into 433fb6c82
Pull Request #337: Partial fix for benchmarks.

4325 of 16400 relevant lines covered (26.37%)

1.2 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.
20
  Vector2 get center => _min.clone()
×
21
    ..add(_max)
×
22
    ..scale(0.5);
×
23

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

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

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

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

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

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

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

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

79
  static final _center = Vector2.zero();
×
80
  static final _halfExtents = Vector2.zero();
×
81
  void _updateCenterAndHalfExtents() =>
×
82
      copyCenterAndHalfExtents(_center, _halfExtents);
×
83

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

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

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

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

122
  /// Set the min and max of this so that this is a hull of this and
123
  /// [other].
124
  void hull(Aabb2 other) {
×
125
    Vector2.min(_min, other._min, _min);
×
126
    Vector2.max(_max, other._max, _max);
×
127
  }
128

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

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

140
    return (_min.x < otherMin.x) &&
×
141
        (_min.y < otherMin.y) &&
×
142
        (_max.y > otherMax.y) &&
×
143
        (_max.x > otherMax.x);
×
144
  }
145

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

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

158
    return (_min.x <= otherMax.x) &&
×
159
        (_min.y <= otherMax.y) &&
×
160
        (_max.x >= otherMin.x) &&
×
161
        (_max.y >= otherMin.y);
×
162
  }
163

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