• 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_geometry/generators/cylinder_generator.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_geometry.dart';
6

7
class CylinderGenerator extends GeometryGenerator {
8
  late double _topRadius;
9
  late double _bottomRadius;
10
  late double _height;
11
  late int _segments;
12

13
  @override
×
14
  int get vertexCount => ((_segments + 1) * 2) + (_segments * 2);
×
15

16
  @override
×
17
  int get indexCount => (_segments * 6) + ((_segments - 2) * 6);
×
18

NEW
19
  MeshGeometry createCylinder(
×
20
    num topRadius,
21
    num bottomRadius,
22
    num height, {
23
    int segments = 16,
24
    GeometryGeneratorFlags? flags,
25
    List<GeometryFilter>? filters,
26
  }) {
27
    _topRadius = topRadius.toDouble();
×
28
    _bottomRadius = bottomRadius.toDouble();
×
29
    _height = height.toDouble();
×
30
    _segments = segments;
×
31

32
    return createGeometry(flags: flags, filters: filters);
×
33
  }
34

35
  @override
×
36
  void generateIndices(Uint16List indices) {
37
    var i = 0;
38

39
    // Sides
40
    var base1 = 0;
41
    final base2 = _segments + 1;
×
42
    for (var x = 0; x < _segments; ++x) {
×
43
      indices[i++] = base1 + x;
×
44
      indices[i++] = base1 + x + 1;
×
45
      indices[i++] = base2 + x;
×
46

47
      indices[i++] = base1 + x + 1;
×
48
      indices[i++] = base2 + x + 1;
×
49
      indices[i++] = base2 + x;
×
50
    }
51

52
    // Top cap
53
    base1 = (_segments + 1) * 2;
×
54
    for (var x = 1; x < _segments - 1; ++x) {
×
55
      indices[i++] = base1;
×
56
      indices[i++] = base1 + x + 1;
×
57
      indices[i++] = base1 + x;
×
58
    }
59

60
    // Bottom cap
61
    base1 = (_segments + 1) * 2 + _segments;
×
62
    for (var x = 1; x < _segments - 1; ++x) {
×
63
      indices[i++] = base1;
×
64
      indices[i++] = base1 + x;
×
65
      indices[i++] = base1 + x + 1;
×
66
    }
67
  }
68

69
  @override
×
70
  void generateVertexPositions(Vector3List positions, Uint16List indices) {
71
    var i = 0;
72

73
    // Top
74
    for (var x = 0; x <= _segments; ++x) {
×
75
      final u = x / _segments;
×
76

NEW
77
      positions[i++] = Vector3(
×
NEW
78
        _topRadius * math.cos(u * math.pi * 2.0),
×
NEW
79
        _height * 0.5,
×
NEW
80
        _topRadius * math.sin(u * math.pi * 2.0),
×
81
      );
82
    }
83

84
    // Bottom
85
    for (var x = 0; x <= _segments; ++x) {
×
86
      final u = x / _segments;
×
87

NEW
88
      positions[i++] = Vector3(
×
NEW
89
        _bottomRadius * math.cos(u * math.pi * 2.0),
×
NEW
90
        _height * -0.5,
×
NEW
91
        _bottomRadius * math.sin(u * math.pi * 2.0),
×
92
      );
93
    }
94

95
    // Top cap
96
    for (var x = 0; x < _segments; ++x) {
×
97
      final u = x / _segments;
×
98

NEW
99
      positions[i++] = Vector3(
×
NEW
100
        _topRadius * math.cos(u * math.pi * 2.0),
×
NEW
101
        _height * 0.5,
×
NEW
102
        _topRadius * math.sin(u * math.pi * 2.0),
×
103
      );
104
    }
105

106
    // Bottom cap
107
    for (var x = 0; x < _segments; ++x) {
×
108
      final u = x / _segments;
×
109

NEW
110
      positions[i++] = Vector3(
×
NEW
111
        _bottomRadius * math.cos(u * math.pi * 2.0),
×
NEW
112
        _height * -0.5,
×
NEW
113
        _bottomRadius * math.sin(u * math.pi * 2.0),
×
114
      );
115
    }
116
  }
117

118
  @override
×
119
  void generateVertexTexCoords(
120
    Vector2List texCoords,
121
    Vector3List positions,
122
    Uint16List indices,
123
  ) {
124
    var i = 0;
125

126
    // Cylinder top
127
    for (var x = 0; x <= _segments; ++x) {
×
128
      final u = 1.0 - (x / _segments);
×
129
      texCoords[i++] = Vector2(u, 0.0);
×
130
    }
131

132
    // Cylinder bottom
133
    for (var x = 0; x <= _segments; ++x) {
×
134
      final u = 1.0 - (x / _segments);
×
135
      texCoords[i++] = Vector2(u, 1.0);
×
136
    }
137

138
    // Top cap
139
    for (var x = 0; x < _segments; ++x) {
×
140
      final r = (x / _segments) * math.pi * 2.0;
×
NEW
141
      texCoords[i++] = Vector2(
×
NEW
142
        math.cos(r) * 0.5 + 0.5,
×
NEW
143
        math.sin(r) * 0.5 + 0.5,
×
144
      );
145
    }
146

147
    // Bottom cap
148
    for (var x = 0; x < _segments; ++x) {
×
149
      final r = (x / _segments) * math.pi * 2.0;
×
NEW
150
      texCoords[i++] = Vector2(
×
NEW
151
        math.cos(r) * 0.5 + 0.5,
×
NEW
152
        math.sin(r) * 0.5 + 0.5,
×
153
      );
154
    }
155
  }
156
}
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