Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

3.2 KB
Raw Blame
import { describe, it, expect } from 'vitest';
import { BUILTIN_BRUSHES, getBuiltinBrushConfig } from '../presetBrushes';
import {
  buildNativeBrushConfigPayload,
  canNativeEngineHandleBrush,
} from '../nativeEngineBridge';
import {
  DEFAULT_BRISTLE_SETTINGS,
  DEFAULT_IMPASTO_SETTINGS,
  DEFAULT_NATURAL_PAINT_SETTINGS,
  type BrushSettings,
} from '../../types/editor';

describe('Phase 5: 100% Native Rust + wgpu Brush Routing & Serialization', () => {
  const rasterLayer = { type: 'raster' as const, locked: false, visible: true };
  const vectorLayer = { type: 'vector' as const, locked: false, visible: true };

  it('routes 100% of built-in brush presets natively on raster layers and mask mode', () => {
    expect(BUILTIN_BRUSHES.map((b) => b.id)).toEqual([
      'g-pen',
      'real-g-pen',
      'textured-pen',
      'rough-pen',
      'dot-pen',
      'calligraphy',
    ]);
    for (const preset of BUILTIN_BRUSHES) {
      const cfg = getBuiltinBrushConfig(preset.id);
      const bs: BrushSettings = {
        size: 24,
        minSizeFactor: 0.2,
        color: '#112233',
        opacity: 1,
        flow: 1,
        spacing: 0.1,
        hardness: 0.9,
        usePressure: true,
        smoothing: true,
        stabilization: 0,
        preset: preset.id,
        ...cfg,
      };
      const tool = preset.id.startsWith('eraser') ? 'eraser' : 'brush';
      expect(canNativeEngineHandleBrush(tool, bs, rasterLayer, false)).toBe(true);
      expect(canNativeEngineHandleBrush(tool, bs, rasterLayer, true)).toBe(true);
      expect(canNativeEngineHandleBrush(tool, bs, vectorLayer, false)).toBe(false);
    }
  });

  it('serializes all Phase 5 Natural Paint, Bristle, Impasto, Ribbon, and Color Mixing fields for ink-engine', async () => {
    const cfg = getBuiltinBrushConfig('g-pen');

    const bs: BrushSettings = {
      size: 64,
      minSizeFactor: 0.15,
      color: '#1d4ed8',
      opacity: 0.95,
      flow: 0.9,
      spacing: 0.08,
      hardness: 0.8,
      usePressure: true,
      smoothing: true,
      stabilization: 4,
      preset: 'g-pen',
      ...cfg,
      renderMode: 'bristle-ribbon',
      bristle: { ...DEFAULT_BRISTLE_SETTINGS },
      naturalPaint: { ...DEFAULT_NATURAL_PAINT_SETTINGS },
      impasto: { ...DEFAULT_IMPASTO_SETTINGS, enabled: true },
      colorMixing: true,
      perceptualMixing: true,
      mixGroundColor: true,
      mixingMode: 'impasto_mix',
      isRibbon: false,
      ribbonRepeatMode: 'reverse',
      useBlur: true,
      blurStrength: 0.4,
    };

    const payload = await buildNativeBrushConfigPayload('brush', bs, '#1d4ed8', '#facc15', false);
    expect(payload.presetKey).toBe('g-pen');
    expect(payload.colorMixing).toBe(true);
    expect(payload.perceptualMixing).toBe(true);
    expect(payload.mixGroundColor).toBe(true);
    expect(payload.mixingMode).toBe('impasto_mix');
    expect(payload.ribbonRepeatMode).toBe('reverse');
    expect(payload.useBlur).toBe(true);
    expect(payload.blurStrength).toBeCloseTo(0.4, 4);
    expect(payload.bristle).toBeTruthy();
    expect(payload.naturalPaint).toBeTruthy();
    expect(payload.impasto).toBeTruthy();
    expect((payload.impasto as Record<string, unknown>).enabled).toBe(true);
  });
});