mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- Removed all Snow consensus code and dependencies - Replaced snow.Context with consensuscontext.Context - Updated all imports and references - Added comprehensive test suites for core packages - Fixed all build errors and test failures - Achieved 100% test pass rate (21 packages passing) - Improved test coverage to 30% Breaking changes: - Removed snow package entirely - Changed VM interface to use VMState instead of snow.State - Updated ChainContext structure Tests added: - core/app_error_test.go: 100% coverage - core/bootstrap_test.go: comprehensive concurrent tests - core/health_test.go: full integration tests - validators/validators_test.go: complete interface tests - version/version_test.go: 100% coverage - codec/codec_test.go: marshal/unmarshal tests - context/context_test.go: all functions tested
53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
import { mixNumber } from '../../utils/mix/number.mjs';
|
|
|
|
const SCALE_PRECISION = 0.0001;
|
|
const SCALE_MIN = 1 - SCALE_PRECISION;
|
|
const SCALE_MAX = 1 + SCALE_PRECISION;
|
|
const TRANSLATE_PRECISION = 0.01;
|
|
const TRANSLATE_MIN = 0 - TRANSLATE_PRECISION;
|
|
const TRANSLATE_MAX = 0 + TRANSLATE_PRECISION;
|
|
function calcLength(axis) {
|
|
return axis.max - axis.min;
|
|
}
|
|
function isNear(value, target, maxDistance) {
|
|
return Math.abs(value - target) <= maxDistance;
|
|
}
|
|
function calcAxisDelta(delta, source, target, origin = 0.5) {
|
|
delta.origin = origin;
|
|
delta.originPoint = mixNumber(source.min, source.max, delta.origin);
|
|
delta.scale = calcLength(target) / calcLength(source);
|
|
delta.translate =
|
|
mixNumber(target.min, target.max, delta.origin) - delta.originPoint;
|
|
if ((delta.scale >= SCALE_MIN && delta.scale <= SCALE_MAX) ||
|
|
isNaN(delta.scale)) {
|
|
delta.scale = 1.0;
|
|
}
|
|
if ((delta.translate >= TRANSLATE_MIN &&
|
|
delta.translate <= TRANSLATE_MAX) ||
|
|
isNaN(delta.translate)) {
|
|
delta.translate = 0.0;
|
|
}
|
|
}
|
|
function calcBoxDelta(delta, source, target, origin) {
|
|
calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : undefined);
|
|
calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : undefined);
|
|
}
|
|
function calcRelativeAxis(target, relative, parent) {
|
|
target.min = parent.min + relative.min;
|
|
target.max = target.min + calcLength(relative);
|
|
}
|
|
function calcRelativeBox(target, relative, parent) {
|
|
calcRelativeAxis(target.x, relative.x, parent.x);
|
|
calcRelativeAxis(target.y, relative.y, parent.y);
|
|
}
|
|
function calcRelativeAxisPosition(target, layout, parent) {
|
|
target.min = layout.min - parent.min;
|
|
target.max = target.min + calcLength(layout);
|
|
}
|
|
function calcRelativePosition(target, layout, parent) {
|
|
calcRelativeAxisPosition(target.x, layout.x, parent.x);
|
|
calcRelativeAxisPosition(target.y, layout.y, parent.y);
|
|
}
|
|
|
|
export { calcAxisDelta, calcBoxDelta, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, isNear };
|