Skip to content

chore: Lay the cross section and the particle lines with vector operations - #126

Merged
kous500 merged 1 commit into
mainfrom
chore/vector-math-20261114
Nov 14, 2026
Merged

kous500 merged 1 commit into
mainfrom
chore/vector-math-20261114

Conversation

@kous500

@kous500 kous500 commented Nov 14, 2026

Copy link
Copy Markdown
Owner

What and why

Some of the math of //bc and of the particle preview went through angles or wrote each coordinate out, which hid what it computes. This writes it with vector operations.

  • Cross section of //bc: CurveLayout turned the direction of the curve into an angle with atan2 and back with cos(-angle) and sin(-angle) to lay the cross section across the curve. It now turns the direction a quarter turn on the xz plane (the way that takes +z to +x) and scales it to length 1. A curve that does not move on the xz plane still gets +x. Sample keeps this vector instead of the angle.
  • BezierSegment.direction: gives the direction of the curve (the derivative divided by 3) as a vector. angle, whose only caller was CurveLayout, is removed.
  • Cross of a handle: each line goes from a corner of the block towards its center, corner + (center - corner) * i / density, instead of 0.5 * x + (density * x + (-x * 2 + 1) * i) / density * 0.5 for each coordinate.
  • Handle line: start + (handle - point) * t instead of each coordinate.
  • Distances: BezierSegment.length and CurveLayout use Vector3.distance instead of writing the square root out; the result is the same to the bit.

How it was tested

  • Where //bc places the blocks beside the curve was compared with the angle version on 20,000 random curves (68 million positions): 2 differ, both at exactly .5, where the rounding went the other way by about 1e-15.
  • ./gradlew build :curvebuilding-fabric:26.3:runGameTest checkCodeStyle --warning-mode all: the build and unit tests pass, with no Gradle, javac or Checkstyle warnings. The game tests pass on the six versions that build runs them on.
  • Tests: BezierSegmentTest checks direction (the ends go towards their handles, the weights at t = 0.5, and no direction at an end without a handle) instead of angle, and a new CurveLayoutTest checks that the cross section is laid across a curve along z, as the existing one does along x.
  • IntelliJ IDEA's inspections report no warnings in the changed files.
  • Not checked: //bc and the particle preview in the game.
  • Minecraft version: the versions of the game tests
  • Server software / loader: Fabric (game tests)
  • WorldEdit / FastAsyncWorldEdit version: the versions in the build

Notes

  • No changes for players or server owners beyond the rounding described above.

…tions

- //bc turns the direction of the curve a quarter turn on the xz plane
  to lay its cross section across it, instead of turning it into an
  angle and back with cos and sin. BezierSegment.direction gives that
  direction, and angle, which nothing else used, is removed.
- The cross of a handle goes from each corner of the block towards its
  center, and the handle line from the point towards the handle,
  written with vectors instead of each coordinate.
- The length of a segment and the distance along it use
  Vector3.distance.
@kous500
kous500 enabled auto-merge (squash) November 14, 2026 13:52
@kous500
kous500 merged commit 2b0f6b0 into main Nov 14, 2026
28 checks passed
@kous500
kous500 deleted the chore/vector-math-20261114 branch November 14, 2026 13:56
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.

1 participant