This commit is contained in:
Andras Schmelczer 2026-05-18 08:11:52 +01:00
commit 15e99380b5
84 changed files with 1659 additions and 4726 deletions

View file

@ -16,15 +16,13 @@ interface LineSegment {
}
interface BrushParameterSettings extends BrushSettings {
devicePixelRatio?: number;
pixelRatio?: number;
selectedColorIndex: number;
}
export const getSafeDevicePixelRatio = (devicePixelRatio: number | undefined): number =>
typeof devicePixelRatio === 'number' &&
Number.isFinite(devicePixelRatio) &&
devicePixelRatio > 0
? devicePixelRatio
export const getSafePixelRatio = (pixelRatio: number | undefined): number =>
typeof pixelRatio === 'number' && Number.isFinite(pixelRatio) && pixelRatio > 0
? pixelRatio
: 1;
export const setBrushUniformValues = (
@ -43,13 +41,13 @@ export const setBrushUniformValues = (
brushGrainMinStrength,
brushGrainMaxStrength,
selectedColorIndex,
devicePixelRatio,
pixelRatio,
}: BrushParameterSettings
): void => {
const pixelRatio = getSafeDevicePixelRatio(devicePixelRatio);
const brushRadius = (brushSize * pixelRatio) / 2;
const safePixelRatio = getSafePixelRatio(pixelRatio);
const brushRadius = (brushSize * safePixelRatio) / 2;
const brushRadiusVariation = Math.floor(brushRadius * brushSizeVariation);
const brushMinimumFeatherPixels = brushMinimumFeather * pixelRatio;
const brushMinimumFeatherPixels = brushMinimumFeather * safePixelRatio;
const brushFeather = Math.max(
brushMinimumFeatherPixels,
brushRadius * brushFeatherRatio
@ -65,8 +63,8 @@ export const setBrushUniformValues = (
target[5] = selectedColorIndex === 1 ? 1 : 0;
target[6] = selectedColorIndex === 2 ? 1 : 0;
target[7] = brushAlpha;
target[8] = brushCoarseNoiseScale * pixelRatio;
target[9] = brushGrainNoiseScale * pixelRatio;
target[8] = brushCoarseNoiseScale * safePixelRatio;
target[9] = brushGrainNoiseScale * safePixelRatio;
target[10] = brushGrainNoiseOffsetX;
target[11] = brushGrainNoiseOffsetY;
target[12] = brushDiscardThreshold;