Skip to content

Commit afcaa17

Browse files
style: align drawCircleGradient with surrounding draw function style
Match drawRectGradient/drawRegularPoly conventions: count-down loop idiom, no spaces around tight math operators, trim verbose comments, drop cross-reference to a sibling function. No behavior change; tests pass (197/197). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 649816e commit afcaa17

6 files changed

Lines changed: 30 additions & 46 deletions

File tree

dist/littlejs.esm.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,33 +4534,29 @@ function drawCircleGradient(pos, size=1, colorInner=WHITE, colorOuter=BLACK, use
45344534
ASSERT(!!glContext, 'WebGL is not enabled!');
45354535
if (screenSpace)
45364536
{
4537-
// convert to world space (matches drawRectGradient's WebGL branch)
4537+
// convert to world space
45384538
pos = screenToWorld(pos);
45394539
size /= cameraScale;
45404540
}
4541-
4542-
// Encode a triangle fan inside a tristrip: interleave the center vertex
4543-
// between every ring vertex. Each adjacent (C,R_i)->(C,R_{i+1}) pair
4544-
// produces one degenerate triangle and one real fan slice, giving a
4545-
// true vertex-color-interpolated radial gradient via the existing helper.
4541+
// encode fan as tristrip: interleave center between every ring vertex
45464542
const sides = glCircleSides;
4547-
const radius = size / 2;
4543+
const radius = size/2;
45484544
const innerInt = colorInner.rgbaInt();
45494545
const outerInt = colorOuter.rgbaInt();
45504546
const points = [], colors = [];
4551-
for (let i = 0; i <= sides; i++)
4547+
for (let i=sides+1; i--;)
45524548
{
4553-
const a = (i % sides) / sides * PI * 2;
4549+
const a = (i%sides)/sides*PI*2;
45544550
points.push(pos);
45554551
colors.push(innerInt);
4556-
points.push(vec2(pos.x + sin(a) * radius, pos.y + cos(a) * radius));
4552+
points.push(vec2(pos.x + sin(a)*radius, pos.y + cos(a)*radius));
45574553
colors.push(outerInt);
45584554
}
45594555
glDrawColoredPoints(points, colors);
45604556
}
45614557
else
45624558
{
4563-
// Canvas2D path: native radial gradient (slower but matches WebGL visually)
4559+
// normal canvas 2D rendering method (slower)
45644560
++drawCount;
45654561
drawCanvas2D(pos, vec2(size), 0, false, (context)=>
45664562
{

dist/littlejs.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/littlejs.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,33 +4534,29 @@ function drawCircleGradient(pos, size=1, colorInner=WHITE, colorOuter=BLACK, use
45344534
ASSERT(!!glContext, 'WebGL is not enabled!');
45354535
if (screenSpace)
45364536
{
4537-
// convert to world space (matches drawRectGradient's WebGL branch)
4537+
// convert to world space
45384538
pos = screenToWorld(pos);
45394539
size /= cameraScale;
45404540
}
4541-
4542-
// Encode a triangle fan inside a tristrip: interleave the center vertex
4543-
// between every ring vertex. Each adjacent (C,R_i)->(C,R_{i+1}) pair
4544-
// produces one degenerate triangle and one real fan slice, giving a
4545-
// true vertex-color-interpolated radial gradient via the existing helper.
4541+
// encode fan as tristrip: interleave center between every ring vertex
45464542
const sides = glCircleSides;
4547-
const radius = size / 2;
4543+
const radius = size/2;
45484544
const innerInt = colorInner.rgbaInt();
45494545
const outerInt = colorOuter.rgbaInt();
45504546
const points = [], colors = [];
4551-
for (let i = 0; i <= sides; i++)
4547+
for (let i=sides+1; i--;)
45524548
{
4553-
const a = (i % sides) / sides * PI * 2;
4549+
const a = (i%sides)/sides*PI*2;
45544550
points.push(pos);
45554551
colors.push(innerInt);
4556-
points.push(vec2(pos.x + sin(a) * radius, pos.y + cos(a) * radius));
4552+
points.push(vec2(pos.x + sin(a)*radius, pos.y + cos(a)*radius));
45574553
colors.push(outerInt);
45584554
}
45594555
glDrawColoredPoints(points, colors);
45604556
}
45614557
else
45624558
{
4563-
// Canvas2D path: native radial gradient (slower but matches WebGL visually)
4559+
// normal canvas 2D rendering method (slower)
45644560
++drawCount;
45654561
drawCanvas2D(pos, vec2(size), 0, false, (context)=>
45664562
{

dist/littlejs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/littlejs.release.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,33 +3854,29 @@ function drawCircleGradient(pos, size=1, colorInner=WHITE, colorOuter=BLACK, use
38543854
ASSERT(!!glContext, 'WebGL is not enabled!');
38553855
if (screenSpace)
38563856
{
3857-
// convert to world space (matches drawRectGradient's WebGL branch)
3857+
// convert to world space
38583858
pos = screenToWorld(pos);
38593859
size /= cameraScale;
38603860
}
3861-
3862-
// Encode a triangle fan inside a tristrip: interleave the center vertex
3863-
// between every ring vertex. Each adjacent (C,R_i)->(C,R_{i+1}) pair
3864-
// produces one degenerate triangle and one real fan slice, giving a
3865-
// true vertex-color-interpolated radial gradient via the existing helper.
3861+
// encode fan as tristrip: interleave center between every ring vertex
38663862
const sides = glCircleSides;
3867-
const radius = size / 2;
3863+
const radius = size/2;
38683864
const innerInt = colorInner.rgbaInt();
38693865
const outerInt = colorOuter.rgbaInt();
38703866
const points = [], colors = [];
3871-
for (let i = 0; i <= sides; i++)
3867+
for (let i=sides+1; i--;)
38723868
{
3873-
const a = (i % sides) / sides * PI * 2;
3869+
const a = (i%sides)/sides*PI*2;
38743870
points.push(pos);
38753871
colors.push(innerInt);
3876-
points.push(vec2(pos.x + sin(a) * radius, pos.y + cos(a) * radius));
3872+
points.push(vec2(pos.x + sin(a)*radius, pos.y + cos(a)*radius));
38773873
colors.push(outerInt);
38783874
}
38793875
glDrawColoredPoints(points, colors);
38803876
}
38813877
else
38823878
{
3883-
// Canvas2D path: native radial gradient (slower but matches WebGL visually)
3879+
// normal canvas 2D rendering method (slower)
38843880
++drawCount;
38853881
drawCanvas2D(pos, vec2(size), 0, false, (context)=>
38863882
{

src/engineDraw.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -750,33 +750,29 @@ function drawCircleGradient(pos, size=1, colorInner=WHITE, colorOuter=BLACK, use
750750
ASSERT(!!glContext, 'WebGL is not enabled!');
751751
if (screenSpace)
752752
{
753-
// convert to world space (matches drawRectGradient's WebGL branch)
753+
// convert to world space
754754
pos = screenToWorld(pos);
755755
size /= cameraScale;
756756
}
757-
758-
// Encode a triangle fan inside a tristrip: interleave the center vertex
759-
// between every ring vertex. Each adjacent (C,R_i)->(C,R_{i+1}) pair
760-
// produces one degenerate triangle and one real fan slice, giving a
761-
// true vertex-color-interpolated radial gradient via the existing helper.
757+
// encode fan as tristrip: interleave center between every ring vertex
762758
const sides = glCircleSides;
763-
const radius = size / 2;
759+
const radius = size/2;
764760
const innerInt = colorInner.rgbaInt();
765761
const outerInt = colorOuter.rgbaInt();
766762
const points = [], colors = [];
767-
for (let i = 0; i <= sides; i++)
763+
for (let i=sides+1; i--;)
768764
{
769-
const a = (i % sides) / sides * PI * 2;
765+
const a = (i%sides)/sides*PI*2;
770766
points.push(pos);
771767
colors.push(innerInt);
772-
points.push(vec2(pos.x + sin(a) * radius, pos.y + cos(a) * radius));
768+
points.push(vec2(pos.x + sin(a)*radius, pos.y + cos(a)*radius));
773769
colors.push(outerInt);
774770
}
775771
glDrawColoredPoints(points, colors);
776772
}
777773
else
778774
{
779-
// Canvas2D path: native radial gradient (slower but matches WebGL visually)
775+
// normal canvas 2D rendering method (slower)
780776
++drawCount;
781777
drawCanvas2D(pos, vec2(size), 0, false, (context)=>
782778
{

0 commit comments

Comments
 (0)