Int64Ratio
final class Int64Ratio implements RatioBackend<Frac, List<Frac>>
Exact ratio geometry in int64 rationals (Frac) in any integer metric of dimension 2 or 3. For lattices, connectors and layout, where exactness matters and coordinates are small; every operation is checked, and an overflow throws RatioOverflow rather than returning a wrong answer.
Constructors
Int64Ratio(List<int> metric)metric is the symmetric matrix, row-major (4 or 9 entries).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('exact spread of (1, 2), (3, 1): ${b.spread(b.vector([1, 2]), b.vector([3, 1]))}');
final l = Int64Ratio([1, 0, 0, -1]);
print('red (Lorentzian) Q(3, 5) = ${l.quadrance(l.vector([3, 5]))}');
}exact spread of (1, 2), (3, 1): 1/2 red (Lorentzian) Q(3, 5) = -16
Properties
final int dimensionString get namebool get exactMethods
Frac fromInt(int n)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('fromInt(7) = ${b.fromInt(7)}');
}fromInt(7) = 7
Frac add(Frac a, Frac b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final x = b.div(b.fromInt(1), b.fromInt(3)), y = b.div(b.fromInt(1), b.fromInt(6));
print('1/3 add 1/6 = ${b.add(x, y)}');
}1/3 add 1/6 = 1/2
Frac sub(Frac a, Frac b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final x = b.div(b.fromInt(1), b.fromInt(3)), y = b.div(b.fromInt(1), b.fromInt(6));
print('1/3 sub 1/6 = ${b.sub(x, y)}');
}1/3 sub 1/6 = 1/6
Frac mul(Frac a, Frac b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final x = b.div(b.fromInt(1), b.fromInt(3)), y = b.div(b.fromInt(1), b.fromInt(6));
print('1/3 mul 1/6 = ${b.mul(x, y)}');
}1/3 mul 1/6 = 1/18
Frac div(Frac a, Frac b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final x = b.div(b.fromInt(1), b.fromInt(3)), y = b.div(b.fromInt(1), b.fromInt(6));
print('1/3 div 1/6 = ${b.div(x, y)}');
}1/3 div 1/6 = 2
bool isZero(Frac a, Frac scale)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final x = b.sub(b.div(b.fromInt(1), b.fromInt(3)), b.div(b.fromInt(2), b.fromInt(6)));
print('1/3 − 2/6 is zero: ${b.isZero(x, b.fromInt(1))}');
}1/3 − 2/6 is zero: true
double? toDouble(Frac a)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.toDouble(b.div(b.fromInt(2), b.fromInt(3))));
}0.6666666666666666
List<Frac> vector(List<int> c)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.vector([3, 4]));
}[3, 4]
List<Frac> vadd(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.vadd(b.vector([3, 4]), b.vector([4, -3])));
}[7, 1]
List<Frac> vsub(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.vsub(b.vector([3, 4]), b.vector([4, -3])));
}[-1, 7]
List<Frac> vscale(Frac k, List<Frac> v)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.vscale(b.div(b.fromInt(1), b.fromInt(2)), b.vector([3, 4])));
}[3/2, 2]
Frac size(List<Frac> v)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('size of [3, 4]: ${b.size(b.vector([3, 4]))}');
}size of [3, 4]: 25
bool same(List<Frac> a, List<Frac> b, Frac scale)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.same(b.vscale(b.fromInt(2), b.vector([1, 2])), b.vadd(b.vector([1, 2]), b.vector([1, 2])), b.size(b.vector([1, 2]))));
}true
Frac dot(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('dot([3, 4], [1, 2]) = ${b.dot(b.vector([3, 4]), b.vector([1, 2]))}');
print('dot([3, 4], [4, -3]) = ${b.dot(b.vector([3, 4]), b.vector([4, -3]))}');
}dot([3, 4], [1, 2]) = 11 dot([3, 4], [4, -3]) = 0
Frac quadrance(List<Frac> a)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('Q([3, 4]) = ${b.quadrance(b.vector([3, 4]))}');
}Q([3, 4]) = 25
Frac spread(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('spread([3, 4], [1, 2]) = ${b.spread(b.vector([3, 4]), b.vector([1, 2]))}');
print('spread([3, 4], [4, -3]) = ${b.spread(b.vector([3, 4]), b.vector([4, -3]))}');
}spread([3, 4], [1, 2]) = 4/125 spread([3, 4], [4, -3]) = 1
Frac cross(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('cross([3, 4], [1, 2]) = ${b.cross(b.vector([3, 4]), b.vector([1, 2]))}');
print('cross([3, 4], [4, -3]) = ${b.cross(b.vector([3, 4]), b.vector([4, -3]))}');
}cross([3, 4], [1, 2]) = 121/125 cross([3, 4], [4, -3]) = 0
Frac twist(List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('twist([3, 4], [1, 2]) = ${b.twist(b.vector([3, 4]), b.vector([1, 2]))}');
print('twist([3, 4], [1, 3]) = ${b.twist(b.vector([3, 4]), b.vector([1, 3]))}');
}twist([3, 4], [1, 2]) = 4/121 twist([3, 4], [1, 3]) = 1/9
Frac solidSpread(List<Frac> a, List<Frac> b, List<Frac> c)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
// Three-dimensional quantities need a 3-D metric.
final b3 = Int64Ratio([1, 0, 0, 0, 1, 0, 0, 0, 1]);
print('solid spread of the axes: ${b3.solidSpread(b3.vector([1, 0, 0]), b3.vector([0, 1, 0]), b3.vector([0, 0, 1]))}');
print('of a flat triple: ${b3.solidSpread(b3.vector([1, 0, 0]), b3.vector([0, 1, 0]), b3.vector([1, 1, 0]))}');
}solid spread of the axes: 1 of a flat triple: 0
Frac dihedralSpread(List<Frac> c, List<Frac> a, List<Frac> b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
// Three-dimensional quantities need a 3-D metric.
final b3 = Int64Ratio([1, 0, 0, 0, 1, 0, 0, 0, 1]);
print('dihedral spread of the xz and yz planes along z: ${b3.dihedralSpread(b3.vector([0, 0, 1]), b3.vector([1, 0, 0]), b3.vector([1, 1, 0]))}');
}dihedral spread of the xz and yz planes along z: 1/2
Frac gramDeterminant(List<List<Frac>> vs)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print(b.gramDeterminant([b.vector([3, 4]), b.vector([1, 2])]));
}4
List<Frac> reflect(List<Frac> v, List<Frac> n)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
print('reflect [3, 4] in [1, 2]: ${b.reflect(b.vector([3, 4]), b.vector([1, 2]))}');
}reflect [3, 4] in [1, 2]: [-7/5, -24/5]
List<Frac> perpendicular(List<List<Frac>> vs)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final p = b.perpendicular([b.vector([3, 4])]);
print('$p, dot ${b.dot(p, b.vector([3, 4]))}');
}[-4, 3], dot 0
List<Frac> rotate(List<Frac> k, List<Frac> v)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final b = Int64Ratio([1, 0, 0, 1]);
final t = b.div(b.fromInt(1), b.fromInt(2));
print('rotate [3, 4] by t = 1/2: ${b.rotate([t], b.vector([3, 4]))}');
}rotate [3, 4] by t = 1/2: [5, 0]
RatioBatch
abstract interface class RatioBatch
Ratio geometry over arrays of single-precision vectors: the batched backend. Layouts are tightly packed floats (no float3 padding):
| Kernel | Input per item | Output per item |
|---|---|---|
spreadCross2 | ax ay bx by | spread, cross |
spreadCross3 | ax ay az bx by bz | spread, cross |
solidSpreads3 | a b c (9 floats) | solid spread |
dihedralSpreads3 | c a b (9 floats; planes meet along c) | dihedral spread |
cayleyRotate3 | gx gy gz vx vy vz | rotated v (3 floats) |
exactSpreads2 | ax ay bx by as int32, \operatorname{abs} < 2^{15} | (u \wedge v)^{2}, Q(u)Q(v) as int64: the spread, exactly |
Properties
String get nameMethods
void spreadCross2(Float32List pairs, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Float32List(4);
k.spreadCross2(Float32List.fromList([1, 0, 1, 1, 3, 4, 4, -3]), out);
print('(spread, cross) per pair: $out');
}(spread, cross) per pair: [0.5, 0.5, 1.0, 0.0]
void spreadCross3(Float32List pairs, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Float32List(2);
k.spreadCross3(Float32List.fromList([1, 0, 0, 1, 1, 0]), out);
print(out);
}[0.5, 0.5]
void solidSpreads3(Float32List triples, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Float32List(1);
k.solidSpreads3(Float32List.fromList([1, 0, 0, 0, 1, 0, 0, 0, 1]), out);
print('solid spread of the axes: ${out[0]}');
}solid spread of the axes: 1.0
void dihedralSpreads3(Float32List triples, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Float32List(1);
k.dihedralSpreads3(Float32List.fromList([0, 0, 1, 1, 0, 0, 1, 1, 0]), out);
print('dihedral spread: ${out[0]}');
}dihedral spread: 0.5
void cayleyRotate3(Float32List gv, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Float32List(3);
k.cayleyRotate3(Float32List.fromList([0, 0, 1, 1, 0, 0]), out);
print('x under g = (0, 0, 1): $out (a quarter turn)');
}x under g = (0, 0, 1): [0.0, 1.0, 0.0] (a quarter turn)
void exactSpreads2(Int32List pairs, Int64List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const RatioBatch k = CpuRatioBatch();
final out = Int64List(2);
k.exactSpreads2(Int32List.fromList([1, 2, 3, 1]), out);
print('spread = ${out[0]}/${out[1]}');
}spread = 25/50
CpuRatioBatch
final class CpuRatioBatch implements RatioBatch
RatioBatch on the CPU: each item through the float core (RatioF) in double, stored as float.
Constructors
const CpuRatioBatch()import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
print('backend: ${k.name}');
}backend: cpu f32 batch
Properties
String get nameMethods
void spreadCross2(Float32List p, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Float32List(4);
k.spreadCross2(Float32List.fromList([1, 0, 1, 1, 3, 4, 4, -3]), out);
print('(spread, cross) per pair: $out');
}(spread, cross) per pair: [0.5, 0.5, 1.0, 0.0]
void spreadCross3(Float32List p, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Float32List(2);
k.spreadCross3(Float32List.fromList([1, 0, 0, 1, 1, 0]), out);
print(out);
}[0.5, 0.5]
void solidSpreads3(Float32List p, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Float32List(1);
k.solidSpreads3(Float32List.fromList([1, 0, 0, 0, 1, 0, 0, 0, 1]), out);
print('solid spread of the axes: ${out[0]}');
}solid spread of the axes: 1.0
void dihedralSpreads3(Float32List p, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Float32List(1);
k.dihedralSpreads3(Float32List.fromList([0, 0, 1, 1, 0, 0, 1, 1, 0]), out);
print('dihedral spread: ${out[0]}');
}dihedral spread: 0.5
void cayleyRotate3(Float32List p, Float32List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Float32List(3);
k.cayleyRotate3(Float32List.fromList([0, 0, 1, 1, 0, 0]), out);
print('x under g = (0, 0, 1): $out (a quarter turn)');
}x under g = (0, 0, 1): [0.0, 1.0, 0.0] (a quarter turn)
void exactSpreads2(Int32List p, Int64List out)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const k = CpuRatioBatch();
final out = Int64List(2);
k.exactSpreads2(Int32List.fromList([1, 2, 3, 1]), out);
print('spread = ${out[0]}/${out[1]}');
}spread = 25/50
RatioBoundary
abstract final class RatioBoundary
The named adapters between ratio geometry and radians: the only place in the ratio layer that calls trigonometry. Use them where a platform API, a file format, a sensor or a person speaks in angles: gesture rotation, a field of view in a settings file, a bearing from a map service, an angle shown in the UI. Everything between two boundaries stays in spreads, turns and Cayley parameters.
Static
static double cayleyFromRadians(double radians)The Cayley parameter \tan(\frac{\theta}{2}) of an angle in radians.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('60° -> t = ${f(RatioBoundary.cayleyFromRadians(math.pi / 3))} (tan 30°)');
}60° -> t = 0.577350 (tan 30°)
static double radiansFromCayley(double t)The angle in radians, in (-\pi, \pi), of a Cayley parameter (2 \cdot \operatorname{atan} t; infinity gives \pi).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('t = 1 -> ${f(RatioBoundary.radiansFromCayley(1))} rad (π/2)');
}t = 1 -> 1.570796 rad (π/2)
static double radiansFromSpread(double spread)The acute angle in [0, \frac{\pi}{2}] with spread spread (\sin^{2}\theta = s), as \operatorname{atan2}(\sqrt{s}, \sqrt{1 - s}): accurate near 0 and near \frac{\pi}{2}, where \operatorname{asin}(\sqrt{s}) and \operatorname{acos}(\sqrt{1 - s}) lose digits.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('spread 1/2 -> ${f(RatioBoundary.radiansFromSpread(0.5))} rad (π/4)');
}spread 1/2 -> 0.785398 rad (π/4)
static double spreadFromRadians(double radians)\sin^{2}\theta.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print([for (final d in [0, 30, 45, 60, 90]) f(RatioBoundary.spreadFromRadians(d * math.pi / 180))]);
}[0.000000, 0.250000, 0.500000, 0.750000, 1.000000]
static Turn turnFromRadians(double radians)The turn by an angle in radians (\cos \theta, \sin \theta).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final t = RatioBoundary.turnFromRadians(math.pi / 6);
print('(${f(t.c)}, ${f(t.s)})');
}(0.866025, 0.500000)
static double radiansFromTurn(Turn t)The angle of a turn in (-\pi, \pi].
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(f(RatioBoundary.radiansFromTurn(Turn.unit(0, -1))));
}-1.570796
static double radiansFromDirection(double x, double y)The angle in (-\pi, \pi] of the direction (x, y) from the x axis, for APIs that report a heading in radians. Any positive multiple of (x, y) gives the same angle, so the direction need not be normalised (exact by construction).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(f(RatioBoundary.radiansFromDirection(-1, 1)));
}2.356194
static Turn turnFromDegrees(double degrees)The turn by an angle in degrees (maps, SVG, settings, a person's input).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final t = RatioBoundary.turnFromDegrees(90);
print('(${f(t.c)}, ${f(t.s)})');
}(0.000000, 1.000000)
static Turn turnFromFraction(double fraction)The turn by fraction of a whole turn (\frac{1}{n} for the step of a regular n-gon). Multiples of a quarter turn are exact (no rounding of \pi); any other fraction goes through radians once.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final t = RatioBoundary.turnFromFraction(1 / 8);
print('one eighth: (${f(t.c)}, ${f(t.s)})');
}one eighth: (0.707107, 0.707107)
static Quat quatFromAxisRadians(Vec3 axis, double radians)The rotation by radians about the unit axis (the platform form of Quat.axisAngle, kept here so call sites that receive radians name the boundary).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final q = RatioBoundary.quatFromAxisRadians(Vec3.unitZ, math.pi / 2);
final r = q.rotate(Vec3.unitX);
print('x -> (${f(r.x)}, ${f(r.y)}, ${f(r.z)})');
}x -> (0.000000, 1.000000, 0.000000)
static double radiansFromDegrees(double degrees)Degrees to radians and back, for formats that store degrees (maps, SVG, settings).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioBoundary.radiansFromDegrees(180));
}3.141592653589793
static double degreesFromRadians(double radians)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioBoundary.degreesFromRadians(math.pi / 4));
}45.0
Metric2
final class Metric2
A planar metric: the symmetric matrix B = \begin{bmatrix}a & b \\ b & c\end{bmatrix} with B(u, v) = u^{T}Bv (Wildberger, "Affine and projective universal geometry", arXiv:math/0612499). Blue is Euclidean, red is x^{2} - y^{2} (1 + 1 Minkowski), green is 2xy (the red metric in null coordinates). Every formula here is the general-metric form of the blue one, so a non-Euclidean geometry is a different constant, not different code.
Constructors
const Metric2(this.a, this.b, this.c)import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
for (final (n, m) in [('blue', blue), ('red', red), ('green', green)]) {
print('$n: Q(3, 4) = ${m.quadrance(3, 4)}');
}
}blue: Q(3, 4) = 25.0 red: Q(3, 4) = -7.0 green: Q(3, 4) = 24.0
Static
Properties
final double afinal double bfinal double cdouble get determinantbool get isBlueMethods
double dot(double ux, double uy, double vx, double vy)B(u, v).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
print('blue (1, 2)·(3, 4) = ${blue.dot(1, 2, 3, 4)}, red ${red.dot(1, 2, 3, 4)}, green ${green.dot(1, 2, 3, 4)}');
}blue (1, 2)·(3, 4) = 11.0, red -5.0, green 10.0
double quadrance(double x, double y)Q(v) = B(v, v).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
print('red quadrance of a null vector (1, 1): ${red.quadrance(1, 1)}');
}red quadrance of a null vector (1, 1): 0.0
double spread(double ux, double uy, double vx, double vy)s(u, v) = \det B \cdot \frac{(u \wedge v)^{2}}{Q(u)Q(v)} (Goh–Wildberger, arXiv:0911.1025, p. 7): no 1 - \operatorname{cross} cancellation.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
print('blue spread of (1, 0), (1, 1): ${blue.spread(1, 0, 1, 1)}');
print('perpendicular: ${blue.spread(1, 2, -2, 1)}');
}blue spread of (1, 0), (1, 1): 0.5 perpendicular: 1.0
double cross(double ux, double uy, double vx, double vy)c(u, v) = \frac{B(u, v)^{2}}{Q(u)Q(v)}.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
print('blue cross (1, 0) × (0, 1) = ${blue.cross(1, 0, 0, 1)}');
}blue cross (1, 0) × (0, 1) = 0.0
(double, double) perpendicular(double x, double y)A vector B-perpendicular to v: J \cdot Bv with J the quarter turn, so B(v, perp) = 0 in every metric.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
for (final (n, m) in [('blue', blue), ('red', red), ('green', green)]) {
final (px, py) = m.perpendicular(2, 1);
print('$n ⟂ of (2, 1): ($px, $py), dot ${m.dot(2, 1, px, py)}');
}
}blue ⟂ of (2, 1): (-1.0, 2.0), dot 0.0 red ⟂ of (2, 1): (1.0, 2.0), dot 0.0 green ⟂ of (2, 1): (-2.0, 1.0), dot 0.0
Float64List cayley(double t)The Cayley rotation R = (B - K)^{-1}(B + K), K = t \cdot \begin{bmatrix}0 & 1 \\ -1 & 0\end{bmatrix}: an isometry of this metric (R^{T}BR = B) with \det R = 1, rational in t (the blue case is the rational parametrisation of the circle). Row-major [r00, r01, r10, r11]. Throws when B - K is singular (t^{2} = -\det B).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const blue = Metric2(1, 0, 1), red = Metric2(1, 0, -1), green = Metric2(0, 1, 0);
final r = blue.cayley(0.5);
print('blue Cayley rotation at t = 1/2: $r');
final pts = [for (var k = -8; k <= 8; k++) (() { final m = blue.cayley(k / 4); return [m[0], m[2]]; })()];
}blue Cayley rotation at t = 1/2: [0.6000000000000001, 0.8, -0.8, 0.6000000000000001]
Metric3
final class Metric3
A metric on three-dimensional space: the symmetric matrix B with entries [xx, yy, zz, xy, xz, yz]. Euclidean is the identity; Minkowski 2 + 1 is \operatorname{diag}(1, 1, -1).
Constructors
const Metric3(this.xx, this.yy, this.zz, [this.xy = 0, this.xz = 0, this.yz = 0])import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print('Euclidean Q(1, 2, 2) = ${e.quadrance(1, 2, 2)}, Lorentzian ${l.quadrance(1, 2, 2)}');
}Euclidean Q(1, 2, 2) = 9.0, Lorentzian 1.0
Static
static const euclidean = Metric3(1, 1, 1)static const minkowski = Metric3(1, 1, -1)\operatorname{diag}(1, 1, -1): 2 + 1 Minkowski space (Wildberger's red metric in three dimensions).
Properties
final double xxfinal double yyfinal double zzfinal double xyfinal double xzfinal double yzbool get isEuclideandouble get determinantMethods
double dot(double ux, double uy, double uz, double vx, double vy, double vz)B(u, v).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print(e.dot(1, 2, 3, 4, 5, 6));
}32.0
double quadrance(double x, double y, double z)Q(v).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print('light-like (1, 0, 1) in the Lorentzian metric: ${l.quadrance(1, 0, 1)}');
}light-like (1, 0, 1) in the Lorentzian metric: 0.0
double adjQuadrance(double x, double y, double z)w^{T} \operatorname{adj}(B) w.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print(e.adjQuadrance(1, 2, 3));
print(l.adjQuadrance(1, 2, 3));
}14.0 4.0
double spread(double ux, double uy, double uz, double vx, double vy, double vz)s(u, v) = (u \times v)^{T} \operatorname{adj}(B) \frac{u \times v}{Q(u)Q(v)}: Lagrange's identity for a general metric (Notowidigdo–Wildberger, arXiv:1909.08814, Theorem 8, written with adj B), so no 1 - \operatorname{cross} cancellation.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print('spread between x and (1, 1, 0): ${e.spread(1, 0, 0, 1, 1, 0)}');
}spread between x and (1, 1, 0): 0.5
double cross(double ux, double uy, double uz, double vx, double vy, double vz)c(u, v) = \frac{B(u, v)^{2}}{Q(u)Q(v)}.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print(e.cross(1, 0, 0, 0, 1, 0));
}0.0
(double, double, double) vectorProduct(double ux, double uy, double uz, double vx, double vy, double vz)The B-vector product \operatorname{adj}(B)(u \times v): B-perpendicular to u and v (Notowidigdo–Wildberger, arXiv:1903.08330).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
print('Euclidean x × y = ${e.vectorProduct(1, 0, 0, 0, 1, 0)}');
print('Lorentzian x × y = ${l.vectorProduct(1, 0, 0, 0, 1, 0)}');
}Euclidean x × y = (0.0, 0.0, 1.0) Lorentzian x × y = (0.0, 0.0, 1.0)
Float64List cayley(double gx, double gy, double gz)The Cayley rotation R = (B - K)^{-1}(B + K) with K = gₓ (the skew matrix of g): an isometry of this metric with \det R = 1, rational in g; for the Euclidean metric it is Euler–Rodrigues with Gibbs vector g. Row-major 3 \times 3. Throws when B - K is singular.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
const e = Metric3(1, 1, 1), l = Metric3(1, 1, -1);
final r = e.cayley(0, 0, 1); // Gibbs vector along z
print('rotation (row-major): $r');
}rotation (row-major): [0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
RatioMsl
abstract final class RatioMsl
The batched ratio kernels in Metal Shading Language: the GPU backend of RatioBatch, item for item the same formulas and layouts as CpuRatioBatch. A plain string so any GPU path can compile it (Riptide's gpu.library(source), a Metal harness, an Evelyn GPU compute shader port).
Every planar 2 \times 2 determinant (each wedge and each component of a vector product) uses Kahan's FMA form, which is correct to about one ulp even for nearly parallel vectors, so f32 spreads keep their digits where acos and atan2 don't.
Static
static const sourceRatioF
abstract final class RatioF
Rational Trigonometry on doubles. No sin, cos or \pi.
Static
static double quadrance2(double x, double y)Q(x, y) = x^{2} + y^{2}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('quadrance2(3, 4) = ${RatioF.quadrance2(3, 4)}');
}quadrance2(3, 4) = 25.0
static double wedge2(double ax, double ay, double bx, double by)The wedge u \wedge v = u_{x}v_{y} - u_{yv_{x}} (twice the signed area).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('wedge2(1, 0, 1, 1) = ${RatioF.wedge2(1, 0, 1, 1)}');
}wedge2(1, 0, 1, 1) = 1.0
static double spread2(double ax, double ay, double bx, double by)s(u, v) = \frac{(u \wedge v)^{2}}{Q(u)Q(v)}. NaN when either vector is zero.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('spread2(1, 0, 1, 1) = ${RatioF.spread2(1, 0, 1, 1)}');
}spread2(1, 0, 1, 1) = 0.5
static double cross2(double ax, double ay, double bx, double by)c(u, v) = \frac{(u \cdot v)^{2}}{Q(u)Q(v)}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('cross2(1, 0, 1, 1) = ${RatioF.cross2(1, 0, 1, 1)}');
}cross2(1, 0, 1, 1) = 0.5
static double wedge2Accurate(double ax, double ay, double bx, double by)The wedge as if computed in twice the precision (Ogita–Rump–Oishi Dot2 with Dekker's exact products; Raya has no FMA, so Veltkamp splitting stands in for Kahan's FMA form): correct to about one ulp even for nearly parallel vectors, where the plain wedge keeps only the digits the inputs' difference has. About 25 flops.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('wedge2Accurate(1e8 + 1, 1e8, 1e8, 1e8 - 1) = ${RatioF.wedge2Accurate(1e8 + 1, 1e8, 1e8, 1e8 - 1)}');
}wedge2Accurate(1e8 + 1, 1e8, 1e8, 1e8 - 1) = -1.0
static double spread2Accurate(double ax, double ay, double bx, double by)spread2 from wedge2Accurate: about one ulp at every angle.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('spread2Accurate(1, 1e-9, 1, 0) = ${RatioF.spread2Accurate(1, 1e-9, 1, 0)}');
}spread2Accurate(1, 1e-9, 1, 0) = 1e-18
static double spread3Accurate(double ax, double ay, double az, double bx, double by, double bz)spread3 with each component of u \times v from wedge2Accurate.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('spread3Accurate(1, 1e-9, 0, 1, 0, 0) = ${RatioF.spread3Accurate(1, 1e-9, 0, 1, 0, 0)}');
}spread3Accurate(1, 1e-9, 0, 1, 0, 0) = 1e-18
static double twist2(double ax, double ay, double bx, double by)t(u, v) = \frac{(u \wedge v)^{2}}{(u \cdot v)^{2}}. Infinite for perpendicular vectors.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('twist2(1, 0, 1, 1) = ${RatioF.twist2(1, 0, 1, 1)}');
}twist2(1, 0, 1, 1) = 1.0
static double quadrance3(double x, double y, double z)Q(x, y, z) = x^{2} + y^{2} + z^{2}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('quadrance3(1, 2, 2) = ${RatioF.quadrance3(1, 2, 2)}');
}quadrance3(1, 2, 2) = 9.0
static double spread3(double ax, double ay, double az, double bx, double by, double bz)s(u, v) = \frac{Q(u \times v)}{Q(u)Q(v)} (Lagrange's identity; no cancellation for nearly parallel vectors).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('spread3(1, 0, 0, 1, 1, 1) = ${RatioF.spread3(1, 0, 0, 1, 1, 1)}');
}spread3(1, 0, 0, 1, 1, 1) = 0.6666666666666666
static double cross3(double ax, double ay, double az, double bx, double by, double bz)c(u, v) = \frac{(u \cdot v)^{2}}{Q(u)Q(v)}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('cross3(1, 0, 0, 1, 1, 1) = ${RatioF.cross3(1, 0, 0, 1, 1, 1)}');
}cross3(1, 0, 0, 1, 1, 1) = 0.3333333333333333
static double twist3(double ax, double ay, double az, double bx, double by, double bz)t(u, v) = \frac{Q(u \times v)}{(u \cdot v)^{2}}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('twist3(1, 0, 0, 1, 1, 1) = ${RatioF.twist3(1, 0, 0, 1, 1, 1)}');
}twist3(1, 0, 0, 1, 1, 1) = 2.0
static double det3(double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz)Det[a b c] (the triple product a \cdot (b \times c)).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('det3(1, 0, 0, 0, 1, 0, 0, 0, 1) = ${RatioF.det3(1, 0, 0, 0, 1, 0, 0, 0, 1)}');
}det3(1, 0, 0, 0, 1, 0, 0, 0, 1) = 1.0
static double solidSpread3(double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz)The solid spread \det\frac{[a b c]^{2}}{Q(a)Q(b)Q(c)} (Notowidigdo–Wildberger): 0 for coplanar vectors, 1 for mutually perpendicular ones; the rational analogue of the solid angle at a corner.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('solidSpread3(1, 0, 0, 0, 1, 0, 1, 1, 1) = ${RatioF.solidSpread3(1, 0, 0, 0, 1, 0, 1, 1, 1)}');
}solidSpread3(1, 0, 0, 0, 1, 0, 1, 1, 1) = 0.3333333333333333
static double dihedralSpread3(double cx, double cy, double cz, double ax, double ay, double az, double bx, double by, double bz)The dihedral spread between the planes \operatorname{span}(c, a) and \operatorname{span}(c, b), which meet along c: Q(c) \cdot \frac{\det[c a b]^{2}}{Q(c \times a) \cdot Q(c \times b)} (Notowidigdo–Wildberger, Theorem 12). 0 for one plane, 1 for perpendicular planes. NaN when a or b is parallel to c.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('dihedralSpread3(0, 0, 1, 1, 0, 0, 1, 1, 0) = ${RatioF.dihedralSpread3(0, 0, 1, 1, 0, 0, 1, 1, 0)}');
}dihedralSpread3(0, 0, 1, 1, 0, 0, 1, 1, 0) = 0.5
static double linePlaneSpread3(double vx, double vy, double vz, double ax, double ay, double az, double bx, double by, double bz)The spread between the line through v and the plane \operatorname{span}(a, b): \frac{(v \cdot (a \times b))^{2}}{Q(v) \cdot Q(a \times b)}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('linePlaneSpread3(1, 1, 1, 1, 0, 0, 0, 1, 0) = ${RatioF.linePlaneSpread3(1, 1, 1, 1, 0, 0, 0, 1, 0)}');
}linePlaneSpread3(1, 1, 1, 1, 0, 0, 0, 1, 0) = 0.3333333333333333
static double reflectFactor(double xDotN, double nQuadrance)The factor k of a reflection x \mapsto x - k \cdot n in the line or plane B-perpendicular to n: k = \frac{2B(x, n)}{Q(n)}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('reflectFactor(3, 2) = ${RatioF.reflectFactor(3, 2)}');
}reflectFactor(3, 2) = 3.0
static double cayleyCos(double t)The planar Cayley rotation with parameter t (classically t = \tan(\frac{\theta}{2})): \cos = \frac{1 - t^{2}}{1 + t^{2}}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('cayleyCos(0.5) = ${RatioF.cayleyCos(0.5)}');
}cayleyCos(0.5) = 0.6
static double cayleySin(double t)\sin = \frac{2t}{1 + t^{2}}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('cayleySin(0.5) = ${RatioF.cayleySin(0.5)}');
}cayleySin(0.5) = 0.8
static double cayleyFactor3(double gx, double gy, double gz)The factor \frac{2}{1 + g \cdot g} of the 3-D Cayley rotation with Gibbs vector g (g = \tan(\frac{\theta}{2}) \cdot \mathrm{axis}): R v = v + k \cdot (g \times v + g \times (g \times v)), rational in g (Euler–Rodrigues). Composition is composeGibbs.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('cayleyFactor3(0, 0, 1) = ${RatioF.cayleyFactor3(0, 0, 1)}');
}cayleyFactor3(0, 0, 1) = 1.0
static double twistParameter(double x, double y, double z, double w, double ax, double ay, double az)The Cayley parameter of the twist of a unit quaternion (x, y, z, w) about the unit axis a (swing–twist decomposition): t = \frac{v \cdot a}{w}, the tangent of half the twist angle, read off the quaternion with one division. ±infinity at a half turn. It is monotonic in the angle on (-\pi, \pi), so it compares against limits directly.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print('twistParameter(0, 0, 0.7071067811865476, 0.7071067811865476, 0, 0, 1) = ${RatioF.twistParameter(0, 0, 0.7071067811865476, 0.7071067811865476, 0, 0, 1)}');
}twistParameter(0, 0, 0.7071067811865476, 0.7071067811865476, 0, 0, 1) = 1.0
Turn
extension type const Turn._raw(Float64x2 v)
A planar rotation (blue metric) held as its unit vector (c, s) = (\cos \theta, \sin \theta), never as \theta. An extension type over Float64x2, so the VM keeps it in a register like Vec2: composing, inverting and applying turns allocate nothing and call no trigonometry. Counter-clockwise for positive s. Made from a rational Cayley parameter, from a direction, or between two directions; radians only through RatioBoundary.
Constructors
Turn.unit(double c, double s)The turn with unit vector (c, s); the caller guarantees c^{2} + s^{2} = 1 (use Turn.direction otherwise).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.unit(0.6, 0.8);
print('c = ${t.c}, s = ${t.s}');
print('applied to (1, 0): ${t.apply(1, 0)}');
}c = 0.6, s = 0.8 applied to (1, 0): (0.6, 0.8)
factory Turn.cayley(double t)The rotation with Cayley parameter t (classically \tan(\frac{\theta}{2})): \frac{((1 - t^{2}), 2t)}{1 + t^{2}}. Rational in t, so exact rational t gives an exact rational turn (a Pythagorean triple); every turn but the half turn arises once.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final pts = [for (var k = -10; k <= 10; k++) Turn.cayley(k / 4)];
print('t = 1/2: (${f(Turn.cayley(0.5).c)}, ${f(Turn.cayley(0.5).s)}) = (3/5, 4/5)');
}t = 1/2: (0.6000, 0.8000) = (3/5, 4/5)
factory Turn.direction(double x, double y)The turn taking the x axis to the direction (x, y) (one square root). The zero vector gives identity.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.direction(3, 4);
print('direction (3, 4): c = ${t.c}, s = ${t.s}');
}direction (3, 4): c = 0.6000000000000001, s = 0.8
factory Turn.between(double ax, double ay, double bx, double by)The turn taking the direction of a to the direction of b: \frac{(a \cdot b, a \wedge b)}{\sqrt{Q(a)Q(b)}}.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.between(1, 0, 0, 1);
print('from x to y: c = ${f(t.c)}, s = ${f(t.s)}');
}from x to y: c = 0.0000, s = 1.0000
factory Turn.phase(double turns)The rational circle point at turns whole turns: periodic with period 1, exactly on the unit circle, exact at every quarter turn, with continuous velocity (C^{1}), and no trigonometry. It is the clock for anything periodic in time (a bob, a pulse, a wave, an orbit drawn at a steady rate): Turn.phase(t / period).s swings between -1 and 1 with the period and amplitude of a sine, without one.
Each quarter is the Cayley rotation by m = \frac{v(22 - v^{2})}{28 - 7v^{2}} of the quarter's own phase v in [0, 1): m runs from 0 to 1, so the point runs from one axis to the next, and m'(1) = \frac{11}{7} = 2m'(0) makes the speed 2m'/(1 + m^{2}) the same on both sides of every axis. The point leads or lags the uniform one by at most 1.5 \cdot 10^{-4} rad (0.008^{\circ}).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final xs = [for (var i = 0; i <= 64; i++) i / 64];
print('phase(1/4) = (${f(Turn.phase(0.25).c)}, ${f(Turn.phase(0.25).s)})');
}phase(1/4) = (0.0000, 1.0000)
factory Turn.random(math.Random random)A direction drawn uniformly from the circle with random: a point drawn uniformly from the unit disk (rejection from the square, \frac{\pi}{4} accepted) and scaled to unit length. Every direction is equally likely, as with a uniform angle, and no angle is drawn. Takes two or more draws (2.55 on average).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final r = math.Random(1);
final ts = [for (var i = 0; i < 60; i++) Turn.random(r)];
print('all unit: ${ts.every((t) => (t.c * t.c + t.s * t.s - 1).abs() < 1e-12)}');
}all unit: true
Static
static final identitystatic double gaussian(math.Random random)A standard normal sample (mean 0, variance 1) by Marsaglia's polar method: the uniform disk point of Turn.random scaled by \sqrt{-2 \ln q / q}. Box–Muller without its cosine of a uniform angle.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final r = math.Random(2);
final g = [for (var i = 0; i < 4000; i++) Turn.gaussian(r)];
final mean = g.reduce((a, b) => a + b) / g.length;
final v = g.map((x) => (x - mean) * (x - mean)).reduce((a, b) => a + b) / g.length;
print('mean ${f(mean)}, variance ${f(v)}');
}mean 0.0053, variance 0.9945
Properties
double get cdouble get sTurn get inversedouble get cayleyParameterThe Cayley parameter \frac{s}{1 + c} (\tan(\frac{\theta}{2})); infinite for the half turn.
Turn get halvedThe turn by half this turn's angle (the angle taken in (-\pi, \pi], so the half lies in (-\frac{\pi}{2}, \frac{\pi}{2}]): the direction of (1 + c, s), or of (s, 1 - c) when c < 0, where that sum would cancel. One square root, no angle.
Methods
Turn power(int n)This turn applied n times (n \ge 0) by repeated squaring: the multiple-angle formulas without angles.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.cayley(0.2);
final pts = [for (var n = 0; n <= 12; n++) t.power(n)];
print('t^5 = (${f(t.power(5).c)}, ${f(t.power(5).s)})');
}t^5 = (-0.3923, 0.9198)
(double, double) apply(double x, double y)(x, y) turned.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.unit(0, 1);
print('quarter turn of (2, 1): ${t.apply(2, 1)}');
}quarter turn of (2, 1): (-1.0, 2.0)
Vec2 rotate(Vec2 p)p turned.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.cayley(0.3);
final sq = [Vec2(0, 0), Vec2(1, 0), Vec2(1, 1), Vec2(0, 1)];
final r = [for (final p in sq) t.rotate(p)];
print('(1, 0) -> (${f(r[1].x)}, ${f(r[1].y)})');
}(1, 0) -> (0.8349, 0.5505)
Turn fraction(double t)This turn's angle (taken in (-\pi, \pi]) times t, for any real t: the whole part of t is a power, the fraction is composed from successive halved turns, one per binary digit of the fraction (at most 53). Square roots only, exact to rounding; the interpolation slerp needs, with no angle.
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final t = Turn.unit(0, 1); // a quarter turn
final pts = [for (var i = 0; i <= 8; i++) t.fraction(i / 8)];
print('half of a quarter turn: (${f(t.fraction(0.5).c)}, ${f(t.fraction(0.5).s)})');
}half of a quarter turn: (0.7071, 0.7071)
Turn renormalized()Restores c^{2} + s^{2} = 1 after a long chain of products (one square root).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
var t = Turn.cayley(0.1);
for (var i = 0; i < 100000; i++) {
t = t * Turn.cayley(1e-3);
}
print('drift before: ${(t.c * t.c + t.s * t.s - 1).toStringAsExponential(2)}');
final r = t.renormalized();
print('after: ${(r.c * r.c + r.s * r.s - 1).abs() < 1e-15}');
}drift before: 2.21e-12 after: true
Operators
Turn operator *(Turn o)This after o (complex multiplication).
import 'package:riptide_math/riptide_math.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio.ray';
String f(double d) => (d.abs() < 5e-6 ? 0.0 : d).toStringAsFixed(4);
String v3(Vec3 v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
String d3(Vec3d v) => '(${f(v.x)}, ${f(v.y)}, ${f(v.z)})';
void main() {
final a = Turn.cayley(0.5), b = Turn.cayley(1 / 3);
final p = a * b;
print('(3/5, 4/5)·(4/5, 3/5) = (${f(p.c)}, ${f(p.s)}) = (0, 1)');
}(3/5, 4/5)·(4/5, 3/5) = (0.0000, 1.0000) = (0, 1)
RatioVec2
extension RatioVec2 on Vec2
Ratio geometry on Vec2 (blue metric). Named …With because Vec2.cross is already the wedge.
Properties
double get quadranceMethods
double spreadWith(Vec2 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec2(3, 4), b = Vec2(4, 3);
print('spread ${f(a.spreadWith(b))}');
}spread 0.078400
double crossWith(Vec2 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec2(3, 4), b = Vec2(4, 3);
print('cross ${f(a.crossWith(b))}');
}cross 0.921600
double twistWith(Vec2 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec2(3, 4), b = Vec2(4, 3);
print('twist ${f(a.twistWith(b))}');
}twist 0.085069
Vec2 reflectIn(Vec2 n)The reflection in the line through the origin perpendicular to n.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec2(3, 4), b = Vec2(4, 3);
final r = a.reflectIn(Vec2(0, 1));
print('reflect a in the y axis direction: (${f(r.x)}, ${f(r.y)})');
}reflect a in the y axis direction: (3.000000, -4.000000)
RatioVec3
extension RatioVec3 on Vec3
Ratio geometry on Vec3 (Euclidean metric). Named …With because Vec3.cross is the vector product.
Properties
double get quadranceMethods
double spreadWith(Vec3 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
print(f(a.spreadWith(b)));
}0.500000
double crossWith(Vec3 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
print(f(a.crossWith(b)));
}0.500000
double twistWith(Vec3 o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
print(f(a.twistWith(b)));
}1.000000
double solidSpreadWith(Vec3 b, Vec3 c)The solid spread of this, b and c.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
print(f(a.solidSpreadWith(b, c)));
}0.500000
double dihedralSpreadAlong(Vec3 a, Vec3 b)The dihedral spread between the planes span(this, a) and span(this, b), which meet along this.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
print(f(c.dihedralSpreadAlong(a, b)));
}0.500000
Vec3 reflectIn(Vec3 n)The reflection in the plane through the origin perpendicular to n.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final a = Vec3(1, 0, 0), b = Vec3(1, 1, 0), c = Vec3(0, 0, 1);
final r = Vec3(1, 2, 3).reflectIn(c);
print('(${f(r.x)}, ${f(r.y)}, ${f(r.z)})');
}(1.000000, 2.000000, -3.000000)
RatioVec3d
extension RatioVec3d on Vec3d
Ratio geometry on Vec3d (Euclidean metric, double storage), the twin of RatioVec3 for simulation state.
Properties
double get quadranceMethods
double spreadWith(Vec3d o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(a.spreadWith(b));
}0.5
double crossWith(Vec3d o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(a.crossWith(b));
}0.5
double twistWith(Vec3d o)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(a.twistWith(b));
}1.0
double solidSpreadWith(Vec3d b, Vec3d c)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(a.solidSpreadWith(b, c));
}0.5
double dihedralSpreadAlong(Vec3d a, Vec3d b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(c.dihedralSpreadAlong(a, b));
}0.5
Vec3d reflectIn(Vec3d n)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
const a = Vec3d(1, 0, 0), b = Vec3d(1, 1, 0), c = Vec3d(0, 0, 1);
print(const Vec3d(1, 2, 3).reflectIn(c));
}Vec3d(1.0, 2.0, -3.0)
RatioQuat
abstract final class RatioQuat
Rotations without angles, as Quats: from a Gibbs (Cayley) vector, between two directions (two reflections), and the twist about an axis (swing–twist). The radians constructor Quat.axisAngle stays for platform input.
Static
static Quat fromCayley(Vec3 g)The rotation with Gibbs vector g = \tan(\frac{\theta}{2}) \cdot \mathrm{axis}: \frac{(g, 1)}{\sqrt{1 + g \cdot g}}. One square root, no trigonometry.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final q = RatioQuat.fromCayley(Vec3(0, 0, 1)); // g = tan(θ/2)·axis: θ = 90°
final r = q.rotate(Vec3.unitX);
print('x -> (${f(r.x)}, ${f(r.y)}, ${f(r.z)})');
}x -> (0.000000, 1.000000, 0.000000)
static Vec3 cayleyRotate(Vec3 g, Vec3 v)v rotated by the Cayley rotation with Gibbs vector g, rationally: v + k(g \times v + g \times (g \times v)), k = \frac{2}{1 + g \cdot g}. Exact for exact inputs; exact by construction.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final pts = [for (var i = -6; i <= 6; i++) RatioQuat.cayleyRotate(Vec3(0, 0, i / 3), Vec3.unitX)];
print('g = (0, 0, 1/3): ${f(pts[7].x)}, ${f(pts[7].y)}');
}g = (0, 0, 1/3): 0.800000, 0.600000
static Vec3 composeCayley(Vec3 g1, Vec3 g2)The Gibbs vector of the rotation g_{1} after g_{2} (g_{2} applied first): \frac{g_{1} + g_{2} + g_{1} \times g_{2}}{1 - g_{1} \cdot g_{2}}. Rational; infinite when the composite is a half turn.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final g = RatioQuat.composeCayley(Vec3(0, 0, 1), Vec3(0, 0, 1));
print('two quarter turns: g = (${f(g.x)}, ${f(g.y)}, ${f(g.z)}) (a half turn has g = ∞, so this is huge)');
final h = RatioQuat.composeCayley(Vec3(0, 0, 0.5), Vec3(0, 0, 0.5));
print('tan composes: ${f(h.z)} = 2·0.5/(1 − 0.25)');
}two quarter turns: g = (NaN, NaN, Infinity) (a half turn has g = ∞, so this is huge) tan composes: 1.333333 = 2·0.5/(1 − 0.25)
static Quat between(Vec3 a, Vec3 b)The shortest rotation taking the direction of a to the direction of b: the composition of the reflections in a⊥ and (a + b)⊥ (Cartan–Dieudonné), as the quaternion (a \times b, \sqrt{Q(a)Q(b)} + a \cdot b) normalised. One square root and one normalisation; no atan2, sin or cos. For opposite directions, a half turn about an axis ⊥ a.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final q = RatioQuat.between(Vec3.unitX, Vec3(1, 1, 0).normalized());
final r = q.rotate(Vec3.unitX);
print('x -> (${f(r.x)}, ${f(r.y)}, ${f(r.z)})');
}x -> (0.707107, 0.707107, 0.000000)
static Quat twist(Quat q, Vec3 axis)The twist of q about the unit axis (swing–twist decomposition): (\mathrm{axis} \cdot (v \cdot \mathrm{axis}), w) normalised. The identity when q is a pure swing (v ⊥ axis and w = 0 cannot both hold for a unit q unless it is a half-turn swing).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final q = Quat.axisAngle(Vec3(1, 1, 0).normalized(), 1.0);
final t = RatioQuat.twist(q, Vec3.unitZ);
print('twist about z: (${f(t.x)}, ${f(t.y)}, ${f(t.z)}, ${f(t.w)})');
}twist about z: (0.000000, 0.000000, 0.000000, 1.000000)
static double twistParameter(Quat q, Vec3 axis)The Cayley parameter of the twist of q about the unit axis: \tan(\frac{\operatorname{twist}}{2}) = \frac{v \cdot \mathrm{axis}}{w}.
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(f(RatioQuat.twistParameter(Quat.axisAngle(Vec3.unitZ, math.pi / 2), Vec3.unitZ)));
}1.000000
RatioQuatd
abstract final class RatioQuatd
Static
static Quatd fromCayley(Vec3d g)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.fromCayley(const Vec3d(0, 0, 1)));
}Quatd(0.0, 0.0, 0.7071067811865475, 0.7071067811865475)
static Vec3d cayleyRotate(Vec3d g, Vec3d v)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.cayleyRotate(const Vec3d(0, 0, 0.5), Vec3d.unitX));
}Vec3d(0.6, 0.8, 0.0)
static Vec3d composeCayley(Vec3d g1, Vec3d g2)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.composeCayley(const Vec3d(0, 0, 0.5), const Vec3d(0, 0, 0.5)));
}Vec3d(0.0, 0.0, 1.3333333333333333)
static Quatd between(Vec3d a, Vec3d b)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.between(Vec3d.unitX, Vec3d.unitY).rotate(Vec3d.unitX));
}Vec3d(2.220446049250313e-16, 0.9999999999999998, 0.0)
static Quatd twist(Quatd q, Vec3d axis)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.twist(Quatd.axisAngle(const Vec3d(1, 0, 1), 0.8), Vec3d.unitZ));
}Quatd(0.0, 0.0, 0.28643356194042396, 0.9581001067707493)
static double twistParameter(Quatd q, Vec3d axis)import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
print(RatioQuatd.twistParameter(Quatd.axisAngle(Vec3d.unitZ, 1), Vec3d.unitZ));
}0.5463024898437905
RatioLaws
final class RatioLaws<S, V>
The laws of Rational Trigonometry as checks any RatioBackend must pass: one suite for every number system, so a new backend (a field, a precision, a GPU) is correct when this returns no failures. Inputs are random integer vectors (the same seed gives every backend the same cases). Null vectors (Q = 0, which exist in the red, green and Minkowski metrics and over finite fields) are skipped where a law divides by a quadrance.
| Law | Check |
|---|---|
| \operatorname{spread} + \operatorname{cross} = 1 | s(a, b) + c(a, b) = 1 |
| twist | t(a, b) \cdot c(a, b) = s(a, b) |
| Gram | s(a, b) = \det \frac{G(a, b)}{Q(a)Q(b)} |
| Triple spread | (s_{1} + s_{2} + s_{3})^{2} = 2(s_{1}^{2} + s_{2}^{2} + s_{3}^{2}) + 4s_{1}s_{2}s_{3} for three coplanar directions |
| Spread law | \frac{s_{1}}{Q_{1}} = \frac{s_{2}}{Q_{2}} = \frac{s_{3}}{Q_{3}} in a triangle |
| Cross law | (Q_{1} + Q_{2} - Q_{3})^{2} = 4Q_{1}Q_{2}(1 - s_{3}) |
| Reflections | isometries and involutions |
| Cayley rotations | isometries: B(Ra, Rb) = B(a, b) |
| Cartan–Dieudonné | every Cayley rotation is two reflections: R = \sigma_{u} \sigma_{n}, u = Rv - v, n \perp v (and ⊥ the axis) |
| Solid spread (3-D) | \det \frac{G(a, b, c)}{Q(a)Q(b)Q(c)}; 0 for coplanar vectors |
| Dihedral spread (3-D) | equals the spread of the B-normals of the two planes |
Constructors
RatioLaws(this.b, {this.seed = 1, this.range = 9})import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio_laws.ray';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final failures = RatioLaws(Int64Ratio([1, 0, 0, 1]), seed: 3).run(cases: 50);
print('exact backend: ${failures.isEmpty ? 'every law holds' : failures.take(3).toList()}');
}exact backend: every law holds
Properties
final RatioBackend<S, V> bfinal int seedint skippedCases abandoned in the last run because an exact backend overflowed (never a float backend).
Methods
List<String> run({int cases = 200})Runs cases random cases of every law; returns the failures (empty when the backend is correct).
import 'package:riptide_math/riptide_math.ray';
import 'package:riptide_math/ratio.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';
import 'package:riptide_math/ratio_laws.ray';
String f(double d) => (d.abs() < 5e-9 ? 0.0 : d).toStringAsFixed(6);
void main() {
final exact = RatioLaws(Int64Ratio([1, 0, 0, -1])).run(cases: 40);
final float = RatioLaws(FloatRatio2(const Metric2(1, 0, -1))).run(cases: 40);
print('red metric, int64: ${exact.length} failures; float: ${float.length} failures');
}red metric, int64: 0 failures; float: 0 failures