All files / src/draw/glyph index.ts

100% Statements 34/34
100% Branches 9/9
100% Functions 5/5
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 731x 1x 1x 1x 1x                                     1x 4x 4x 4x 4x 4x 4x 4x           1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x           1x 1x 1x  
import {cross, type CrossName} from './crosses.js'
import {Function} from '#util'
import {elbowSet, type ElbowSetName} from './elbows.js'
import {lineSet, type LineSetName} from './lines.js'
import {teeSet, type TeeSetName} from './tees.js'
import type {ElbowSet, LineSet, TeeSet} from './types.js'
 
/**
 * A glyph group has a {@link TeeSet}, a {@link LineSet}, an {@link ElbowSet},
 * and a cross in some specific style.
 * @category drawing
 */
export interface GlyphGroup {
  tees: TeeSet
  lines: LineSet
  elbows: ElbowSet
  cross: string
}
 
/**
 * Build a glyph group by common style name.
 * @category drawing
 */
export const GlyphGroup = (
  name: TeeSetName & LineSetName & ElbowSetName & CrossName,
): GlyphGroup => ({
  tees: teeSet(name),
  lines: lineSet(name),
  elbows: elbowSet(name),
  cross: cross(name),
})
 
/**
 * Set the glyph group `tees` to the given {@link TeeSet}.
 * @category drawing
 */
export const setGroupTees =
  (tees: TeeSetName): Function.EndoOf<GlyphGroup> =>
  ({tees: _, ...group}) => ({
    ...group,
    tees: teeSet(tees),
  })
 
/**
 * Set the glyph group `lines` to the given {@link LineSet}.
 * @category drawing
 */
export const setGroupLines =
  (lines: LineSetName): Function.EndoOf<GlyphGroup> =>
  ({lines: _, ...group}) => ({
    ...group,
    lines: lineSet(lines),
  })
 
/**
 * Set the glyph group `elbows` to the given {@link ElbowSet}.
 * @category drawing
 */
export const setGroupElbows =
  (elbows: ElbowSetName): Function.EndoOf<GlyphGroup> =>
  ({elbows: _, ...group}) => ({
    ...group,
    elbows: elbowSet(elbows),
  })
 
/**
 * Set the `cross` glyph to the given string.
 * @category drawing
 */
export const setGroupCross =
  (cross: string): Function.EndoOf<GlyphGroup> =>
  ({cross: _, ...group}) => ({...group, cross})