• 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/frustum.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 frustum constructed out of six [Plane]s.
8
class Frustum {
9
  final Plane _plane0;
10
  final Plane _plane1;
11
  final Plane _plane2;
12
  final Plane _plane3;
13
  final Plane _plane4;
14
  final Plane _plane5;
15

16
  /// The first plane that defines the bounds of this frustum.
17
  Plane get plane0 => _plane0;
×
18

19
  /// The second plane that defines the bounds of this frustum.
20
  Plane get plane1 => _plane1;
×
21

22
  /// The third plane that defines the bounds of this frustum.
23
  Plane get plane2 => _plane2;
×
24

25
  /// The fourth plane that defines the bounds of this frustum.
26
  Plane get plane3 => _plane3;
×
27

28
  /// The fifth plane that defines the bounds of this frustum.
29
  Plane get plane4 => _plane4;
×
30

31
  /// The sixed plane that defines the bounds of this frustum.
32
  Plane get plane5 => _plane5;
×
33

34
  /// Create a new frustum without initializing its bounds.
35
  Frustum()
×
NEW
36
    : _plane0 = Plane(),
×
NEW
37
      _plane1 = Plane(),
×
NEW
38
      _plane2 = Plane(),
×
NEW
39
      _plane3 = Plane(),
×
NEW
40
      _plane4 = Plane(),
×
NEW
41
      _plane5 = Plane();
×
42

43
  /// Create a new frustum as a copy of [other].
44
  factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other);
×
45

46
  /// Create a new furstum from a [matrix].
47
  factory Frustum.matrix(Matrix4 matrix) => Frustum()..setFromMatrix(matrix);
×
48

49
  /// Copy the [other] frustum into this.
50
  void copyFrom(Frustum other) {
×
51
    _plane0.copyFrom(other._plane0);
×
52
    _plane1.copyFrom(other._plane1);
×
53
    _plane2.copyFrom(other._plane2);
×
54
    _plane3.copyFrom(other._plane3);
×
55
    _plane4.copyFrom(other._plane4);
×
56
    _plane5.copyFrom(other._plane5);
×
57
  }
58

59
  /// Set this from [matrix].
60
  void setFromMatrix(Matrix4 matrix) {
×
61
    final me = matrix.storage;
×
62
    final me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
×
63
    final me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
×
64
    final me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
×
65
    final me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
×
66

67
    _plane0
×
68
      ..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12)
×
69
      ..normalize();
×
70
    _plane1
×
71
      ..setFromComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12)
×
72
      ..normalize();
×
73
    _plane2
×
74
      ..setFromComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13)
×
75
      ..normalize();
×
76
    _plane3
×
77
      ..setFromComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13)
×
78
      ..normalize();
×
79
    _plane4
×
80
      ..setFromComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14)
×
81
      ..normalize();
×
82
    _plane5
×
83
      ..setFromComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14)
×
84
      ..normalize();
×
85
  }
86

87
  /// Check if this contains a [point].
88
  bool containsVector3(Vector3 point) {
×
89
    if (_plane0.distanceToVector3(point) < 0.0) {
×
90
      return false;
91
    }
92

93
    if (_plane1.distanceToVector3(point) < 0.0) {
×
94
      return false;
95
    }
96

97
    if (_plane2.distanceToVector3(point) < 0.0) {
×
98
      return false;
99
    }
100

101
    if (_plane3.distanceToVector3(point) < 0.0) {
×
102
      return false;
103
    }
104

105
    if (_plane4.distanceToVector3(point) < 0.0) {
×
106
      return false;
107
    }
108

109
    if (_plane5.distanceToVector3(point) < 0.0) {
×
110
      return false;
111
    }
112

113
    return true;
114
  }
115

116
  /// Check if this intersects with [aabb].
117
  bool intersectsWithAabb3(Aabb3 aabb) {
×
118
    if (_intersectsWithAabb3CheckPlane(aabb, _plane0)) {
×
119
      return false;
120
    }
121

122
    if (_intersectsWithAabb3CheckPlane(aabb, _plane1)) {
×
123
      return false;
124
    }
125

126
    if (_intersectsWithAabb3CheckPlane(aabb, _plane2)) {
×
127
      return false;
128
    }
129

130
    if (_intersectsWithAabb3CheckPlane(aabb, _plane3)) {
×
131
      return false;
132
    }
133

134
    if (_intersectsWithAabb3CheckPlane(aabb, _plane4)) {
×
135
      return false;
136
    }
137

138
    if (_intersectsWithAabb3CheckPlane(aabb, _plane5)) {
×
139
      return false;
140
    }
141

142
    return true;
143
  }
144

145
  /// Check if this intersects with [sphere].
146
  bool intersectsWithSphere(Sphere sphere) {
×
147
    final negativeRadius = -sphere.radius;
×
148
    final center = sphere.center;
×
149

150
    if (_plane0.distanceToVector3(center) < negativeRadius) {
×
151
      return false;
152
    }
153

154
    if (_plane1.distanceToVector3(center) < negativeRadius) {
×
155
      return false;
156
    }
157

158
    if (_plane2.distanceToVector3(center) < negativeRadius) {
×
159
      return false;
160
    }
161

162
    if (_plane3.distanceToVector3(center) < negativeRadius) {
×
163
      return false;
164
    }
165

166
    if (_plane4.distanceToVector3(center) < negativeRadius) {
×
167
      return false;
168
    }
169

170
    if (_plane5.distanceToVector3(center) < negativeRadius) {
×
171
      return false;
172
    }
173

174
    return true;
175
  }
176

177
  /// Calculate the corners of this and write them into [corner0] to
178
  // [corner7].
179
  void calculateCorners(
×
180
    Vector3 corner0,
181
    Vector3 corner1,
182
    Vector3 corner2,
183
    Vector3 corner3,
184
    Vector3 corner4,
185
    Vector3 corner5,
186
    Vector3 corner6,
187
    Vector3 corner7,
188
  ) {
189
    Plane.intersection(_plane0, _plane2, _plane4, corner0);
×
190
    Plane.intersection(_plane0, _plane3, _plane4, corner1);
×
191
    Plane.intersection(_plane0, _plane3, _plane5, corner2);
×
192
    Plane.intersection(_plane0, _plane2, _plane5, corner3);
×
193
    Plane.intersection(_plane1, _plane2, _plane4, corner4);
×
194
    Plane.intersection(_plane1, _plane3, _plane4, corner5);
×
195
    Plane.intersection(_plane1, _plane3, _plane5, corner6);
×
196
    Plane.intersection(_plane1, _plane2, _plane5, corner7);
×
197
  }
198

199
  bool _intersectsWithAabb3CheckPlane(Aabb3 aabb, Plane plane) {
×
200
    double outPx, outPy, outPz, outNx, outNy, outNz;
201

202
    if (plane._normal.x < 0.0) {
×
203
      outPx = aabb.min.x;
×
204
      outNx = aabb.max.x;
×
205
    } else {
206
      outPx = aabb.max.x;
×
207
      outNx = aabb.min.x;
×
208
    }
209

210
    if (plane._normal.y < 0.0) {
×
211
      outPy = aabb.min.y;
×
212
      outNy = aabb.max.y;
×
213
    } else {
214
      outPy = aabb.max.y;
×
215
      outNy = aabb.min.y;
×
216
    }
217

218
    if (plane._normal.z < 0.0) {
×
219
      outPz = aabb.min.z;
×
220
      outNz = aabb.max.z;
×
221
    } else {
222
      outPz = aabb.max.z;
×
223
      outNz = aabb.min.z;
×
224
    }
225

226
    final d1 =
NEW
227
        plane._normal.x * outPx +
×
228
        plane._normal.y * outPy +
×
229
        plane._normal.z * outPz +
×
230
        plane.constant;
×
231
    final d2 =
NEW
232
        plane._normal.x * outNx +
×
233
        plane._normal.y * outNy +
×
234
        plane._normal.z * outNz +
×
235
        plane.constant;
×
236

237
    return d1 < 0 && d2 < 0;
×
238
  }
239
}
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