Skip to content

Fix ShapeGenerator::getHexagonAngle index calculation and side 2 pattern#586

Merged
chrxh merged 1 commit intofeatures/ConstructionSequencesfrom
copilot/fix-hexagon-angle-calculation
Apr 8, 2026
Merged

Fix ShapeGenerator::getHexagonAngle index calculation and side 2 pattern#586
chrxh merged 1 commit intofeatures/ConstructionSequencesfrom
copilot/fix-hexagon-angle-calculation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

getHexagonAngle produced incorrect angles for hexagon construction due to wrong indexing and a flipped pattern on side 2.

Changes

  • Index calculation: Removed the --n decrement that shifted to 0-based indexing. Now uses 1-based formula firstIndex = 1 + 3*(k-1)*k and ring-finding starts at k=1 with 1 + 3*k*(k+1) <= n.
  • Side 2, odd k: Was [-120, +60, alternating...] — corrected to [alternating -120/+120..., +60, +120] where the special values are at positions k-2 and k-1 (end of side), not positions 0 and 1 (start).

Before (side 2, odd k):

if (pos == 0) return -120.0f;
if (pos == 1) return  60.0f;
return (pos % 2 == 0) ? 120.0f : -120.0f;

After:

if (pos == k - 2) return  60.0f;
if (pos == k - 1) return 120.0f;
return (pos % 2 == 0) ? -120.0f : 120.0f;

- Use 1-based indexing with firstIndex = 1 + 3*(k-1)*k instead of --n
- Fix ring-finding loop to start at k=1 with condition 1 + 3*k*(k+1) <= n
- Fix side 2 for odd k: alternating -120/+120 with last two values +60, +120

Agent-Logs-Url: https://github.com/chrxh/alien/sessions/5baa12cc-b860-4ab1-8d9e-d91dd10a8aec

Co-authored-by: chrxh <73127001+chrxh@users.noreply.github.com>
@chrxh chrxh marked this pull request as ready for review April 8, 2026 14:11
@chrxh chrxh merged commit 1125cde into features/ConstructionSequences Apr 8, 2026
@chrxh chrxh deleted the copilot/fix-hexagon-angle-calculation branch April 8, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants