wyrd-for-games 0.4.0

Engine-neutral signal-graph game logic for Wyrd
Documentation
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
//! Closed [`KnotKind`] catalog and related op enums (D-dispatch).
//!
//! Author and asset form: host path and emit names stay open strings until
//! bind interns them. Runtime dispatch uses bind-time tags derived from these
//! variants rather than matching `KnotKind` every settle.

use crate::foundation::signal::Signal;

#[cfg(feature = "schema")]
use schemars::JsonSchema;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "schema")]
use std::{borrow::ToOwned, boxed::Box, vec};

/// Which numeric wire path this weave was authored for.
///
/// Must match the crate feature selected at compile time (`signal-f32` or
/// `signal-i32`); validate rejects a mismatch.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum NumericPath {
    /// `f32` wire representation (`signal-f32` builds).
    #[cfg_attr(feature = "serde", serde(rename = "f32"))]
    F32,
    /// Fixed-point i32 Q16 wire representation (`signal-i32` builds).
    #[cfg_attr(feature = "serde", serde(rename = "i32q16"))]
    I32Q16,
}

/// Semantic domain carried by a monomorphic [`Signal`] wire.
///
/// Domains are graph-time contracts. They do not change the runtime wire
/// representation selected by `signal-f32` or `signal-i32`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum SignalDomain {
    /// Exact false/true values (`ZERO`/`ONE`).
    Bool,
    /// Continuous numeric values.
    Level,
    /// Whole-number values.
    Count,
}

impl SignalDomain {
    /// Whether [`KnotKind`] numeric ops (Calc, Map, Threshold, …) may use this domain.
    pub const fn is_numeric(self) -> bool {
        matches!(self, SignalDomain::Level | SignalDomain::Count)
    }
}

impl NumericPath {
    /// Path encoded by the active cargo feature for this build.
    pub fn compiled() -> Self {
        #[cfg(feature = "signal-f32")]
        {
            NumericPath::F32
        }
        #[cfg(feature = "signal-i32")]
        {
            NumericPath::I32Q16
        }
    }
}

/// Comparison operator for [`KnotKind::Compare`].
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum CompareOp {
    /// `lhs` equals `rhs`.
    Eq,
    /// `lhs` does not equal `rhs`.
    Ne,
    /// `lhs` is strictly less than `rhs` (numeric domains only).
    Lt,
    /// `lhs` is less than or equal to `rhs` (numeric domains only).
    Lte,
    /// `lhs` is strictly greater than `rhs` (numeric domains only).
    Gt,
    /// `lhs` is greater than or equal to `rhs` (numeric domains only).
    Gte,
}

impl CompareOp {
    /// Whether this comparison is defined for `domain`.
    ///
    /// Boolean signals support equality only; numeric domains also support
    /// ordering comparisons.
    pub const fn supports_domain(self, domain: SignalDomain) -> bool {
        !matches!(domain, SignalDomain::Bool) || matches!(self, CompareOp::Eq | CompareOp::Ne)
    }
}

/// Timer behavior for [`KnotKind::Timer`].
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum TimerMode {
    /// Countdown reloaded while the `feed` port stays truthy.
    FedCountdown,
    /// Hold `active` for `ticks` after a rising edge on `start`.
    PulseHold,
}

/// Binary arithmetic for [`KnotKind::Calc`] (prefer over path-local `signal_ops`).
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum CalcOp {
    /// Saturating add of `a` and `b`.
    Add,
    /// Saturating subtract `b` from `a`.
    Sub,
    /// Multiply `a` and `b` (Level saturates; Count truncates toward zero).
    Mul,
    /// Divide `a` by `b` (Level float div; Count truncates toward zero).
    Div,
}

/// Simultaneous set/reset priority for [`KnotKind::Flag`].
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum FlagPriority {
    /// Simultaneous set and reset clears the latch.
    ResetWins,
    /// Simultaneous set and reset holds the latch set.
    SetWins,
}

/// Author / asset knot kind. Host path and emit names stay open strings until bind.
///
/// Closed enum: port tables, validate, and loom dispatch all key off these
/// variants. Adding a kind requires catalog ports plus runtime eval.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum KnotKind {
    /// Fixed authored value seeded on `out` before topo eval.
    Constant {
        /// Domain contract for `out`.
        domain: SignalDomain,
        /// Literal emitted each settle.
        value: Signal,
    },
    /// Host sense source: loom copies the bound value onto `out` each settle.
    SignalIn {
        /// Expected domain of the host-bound signal.
        domain: SignalDomain,
    },
    /// One-shot truthy pulse on the first settle after bind.
    OnStart,
    /// Boolean invert: truthy `in` → falsey `out`, and vice versa.
    Not,
    /// Conjunction: `out` truthy only when every `in_*` port is truthy.
    And {
        /// Number of boolean inputs (`in_0` … `in_{arity-1}`).
        arity: u8,
    },
    /// Disjunction: `out` truthy when any `in_*` port is truthy.
    Or {
        /// Number of boolean inputs (`in_0` … `in_{arity-1}`).
        arity: u8,
    },
    /// Relational compare of `lhs` against `rhs` (or `rhs_const`) into boolean `out`.
    Compare {
        /// Domain shared by `lhs` and `rhs`.
        domain: SignalDomain,
        /// Comparison applied each settle.
        op: CompareOp,
        /// Domain-encoded fallback when the `rhs` port is unconnected.
        rhs_const: Option<Signal>,
    },
    /// One-tick pulse when `in` rises from falsey to truthy.
    RisingFromZero,
    /// Set/reset/toggle latch with configurable simultaneous priority.
    Flag {
        /// Tie-break when `set` and `reset` are both truthy in one settle.
        priority: FlagPriority,
        /// Rising edge on `toggle` flips the latch when true.
        enable_toggle: bool,
    },
    /// Saturating counter: rising `inc`/`dec`, level `reset` clears to zero.
    Counter,
    /// Boolean `active` from countdown or pulse-hold rune state.
    Timer {
        /// Countdown reload vs pulse-hold behavior.
        mode: TimerMode,
        /// Duration in loom settle ticks.
        ticks: u16,
    },
    /// Ring-buffer delay: `out` lags `in` by `ticks` settle passes.
    Delay {
        /// Delay depth in loom settle ticks.
        ticks: u16,
    },
    /// Binary arithmetic on `a` and `b` into `out`.
    Calc {
        /// Numeric domain for operands and result.
        domain: SignalDomain,
        /// Operation applied each settle.
        op: CalcOp,
    },
    /// Linear rescale of `in` across authored input and output ranges.
    Map {
        /// Numeric domain for `in` and `out`.
        domain: SignalDomain,
        /// Input range low endpoint (bind-time constant).
        in_min: Signal,
        /// Input range high endpoint (bind-time constant).
        in_max: Signal,
        /// Output range low endpoint (bind-time constant).
        out_min: Signal,
        /// Output range high endpoint (bind-time constant).
        out_max: Signal,
    },
    /// Absolute value of `in` in the declared domain.
    Abs {
        /// Numeric domain for `in` and `out`.
        domain: SignalDomain,
    },
    /// Negation of `in` in the declared domain.
    Neg {
        /// Numeric domain for `in` and `out`.
        domain: SignalDomain,
    },
    /// Multiplex: falsey `sel` → `a`, truthy `sel` → `b`.
    Select,
    /// Quantize `in` into `steps` bins over the in range, map to the out range.
    Digitize {
        /// Numeric domain for `in` and `out`.
        domain: SignalDomain,
        /// Bin count across the input span.
        steps: u16,
        /// Input range low endpoint (bind-time constant).
        in_min: Signal,
        /// Input range high endpoint (bind-time constant).
        in_max: Signal,
        /// Output range low endpoint (bind-time constant).
        out_min: Signal,
        /// Output range high endpoint (bind-time constant).
        out_max: Signal,
    },
    /// Gate a continuous signal with optional hysteresis; edge pulse outs.
    Threshold {
        /// Numeric domain for `in` and threshold constants.
        domain: SignalDomain,
        /// Upper crossing level (or sole threshold when hysteresis is off).
        high: Signal,
        /// Lower release level when hysteresis is on.
        low: Signal,
        /// Latch `out` between `low` and `high` instead of a single cutoff.
        use_hysteresis: bool,
    },
    /// Seeded PRNG sample into `[min, max]` ports; optional rising `gate`.
    Random {
        /// Numeric domain for sample and range ports.
        domain: SignalDomain,
        /// Resample only on a rising edge of `gate` when true.
        require_gate: bool,
    },
    /// Square root of `in` using the declared numeric domain's representation.
    Sqrt {
        /// Numeric domain for `in` and `out`.
        domain: SignalDomain,
    },
    /// Exclusive-or of two boolean inputs into `out`.
    Xor,
    /// One-tick pulse when `in` falls from truthy to falsey.
    FallingToZero,
    /// One-tick pulse when `in` truthiness changes in either direction.
    Change,
    /// Saturate `in` between authored `min` and `max`.
    Clamp {
        /// Numeric domain for `in`, bounds, and `out`.
        domain: SignalDomain,
        /// Lower clamp bound (bind-time constant).
        min: Signal,
        /// Upper clamp bound (bind-time constant).
        max: Signal,
    },
    /// Explicit conversion between two distinct signal domains.
    Convert {
        /// Source domain on `in`.
        from: SignalDomain,
        /// Target domain on `out`.
        to: SignalDomain,
    },
    /// Write `in` to a host-bound signal path each settle.
    SignalOut {
        /// Open host path string until bind interns it.
        path: std::string::String,
        /// Expected domain of the host-bound signal.
        domain: SignalDomain,
    },
    /// Queue a named host command when `trigger` is truthy.
    EmitCommand {
        /// Open command name string until bind interns it.
        name: std::string::String,
    },
}

impl KnotKind {
    /// Two-input And knot (`arity` 2).
    pub fn and2() -> Self {
        KnotKind::And { arity: 2 }
    }

    /// Two-input Or knot (`arity` 2).
    pub fn or2() -> Self {
        KnotKind::Or { arity: 2 }
    }

    /// Boolean Not knot.
    pub fn not() -> Self {
        KnotKind::Not
    }

    /// SignalIn sense source in `domain`.
    pub fn signal_in(domain: SignalDomain) -> Self {
        KnotKind::SignalIn { domain }
    }

    /// Constant source with explicit `value` and `domain`.
    pub fn constant(value: Signal, domain: SignalDomain) -> Self {
        KnotKind::Constant { domain, value }
    }

    /// Count-domain constant from whole number `n`.
    pub fn constant_count(n: i32) -> Self {
        KnotKind::Constant {
            domain: SignalDomain::Count,
            value: crate::foundation::signal::from_count(n),
        }
    }

    /// Bool-domain constant (`ONE` when true, `ZERO` when false).
    pub fn constant_bool(value: bool) -> Self {
        KnotKind::Constant {
            domain: SignalDomain::Bool,
            value: if value {
                crate::foundation::signal::ONE
            } else {
                crate::foundation::signal::ZERO
            },
        }
    }

    /// Level-domain constant from an author float (~0..=1).
    pub fn constant_level(value: f32) -> Self {
        KnotKind::Constant {
            domain: SignalDomain::Level,
            value: crate::foundation::signal::from_level(value),
        }
    }

    /// SignalOut sink bound to host `path` in `domain`.
    pub fn signal_out(path: impl Into<std::string::String>, domain: SignalDomain) -> Self {
        KnotKind::SignalOut {
            path: path.into(),
            domain,
        }
    }

    /// EmitCommand knot for host command `name`.
    pub fn emit_command(name: impl Into<std::string::String>) -> Self {
        KnotKind::EmitCommand { name: name.into() }
    }

    /// Rising-edge detector: pulse when `in` crosses from falsey to truthy.
    pub fn rising_from_zero() -> Self {
        KnotKind::RisingFromZero
    }

    /// Compare knot with `op`, optional baked-in `rhs_const`, in `domain`.
    pub fn compare(op: CompareOp, rhs_const: Option<Signal>, domain: SignalDomain) -> Self {
        KnotKind::Compare {
            domain,
            op,
            rhs_const,
        }
    }

    /// Saturating counter rune with default `inc`/`dec`/`reset` ports.
    pub fn counter() -> Self {
        KnotKind::Counter
    }

    /// Timer rune with `mode` behavior lasting `ticks` settle passes.
    pub fn timer(mode: TimerMode, ticks: u16) -> Self {
        KnotKind::Timer { mode, ticks }
    }

    /// Flag latch with simultaneous `priority` and optional `toggle` edge.
    pub fn flag(priority: FlagPriority, enable_toggle: bool) -> Self {
        KnotKind::Flag {
            priority,
            enable_toggle,
        }
    }

    /// Multiplex knot: falsey `sel` passes `a`, truthy `sel` passes `b`.
    pub fn select() -> Self {
        KnotKind::Select
    }

    /// Calc knot applying `op` in `domain`.
    pub fn calc(op: CalcOp, domain: SignalDomain) -> Self {
        KnotKind::Calc { domain, op }
    }

    /// Map knot with explicit input and output range endpoints.
    pub fn map(
        in_min: Signal,
        in_max: Signal,
        out_min: Signal,
        out_max: Signal,
        domain: SignalDomain,
    ) -> Self {
        KnotKind::Map {
            domain,
            in_min,
            in_max,
            out_min,
            out_max,
        }
    }

    /// Abs knot in `domain`.
    pub fn abs(domain: SignalDomain) -> Self {
        KnotKind::Abs { domain }
    }

    /// Neg knot in `domain`.
    pub fn neg(domain: SignalDomain) -> Self {
        KnotKind::Neg { domain }
    }

    /// Digitize with `steps` bins over 0..ONE → 0..ONE. Steps of 0 become 1.
    pub fn digitize(steps: u16, domain: SignalDomain) -> Self {
        KnotKind::Digitize {
            domain,
            steps: steps.max(1),
            in_min: crate::foundation::signal::ZERO,
            in_max: crate::foundation::signal::ONE,
            out_min: crate::foundation::signal::ZERO,
            out_max: crate::foundation::signal::ONE,
        }
    }

    /// Level thresholds use half-scale hysteresis; Count thresholds use 0/1.
    pub fn threshold_default(domain: SignalDomain) -> Self {
        if domain == SignalDomain::Count {
            return KnotKind::Threshold {
                domain,
                high: crate::foundation::signal::from_count(1),
                low: crate::foundation::signal::from_count(0),
                use_hysteresis: true,
            };
        }
        #[cfg(feature = "signal-f32")]
        {
            KnotKind::Threshold {
                domain,
                high: 0.5,
                low: 0.4,
                use_hysteresis: true,
            }
        }
        #[cfg(feature = "signal-i32")]
        {
            let one = crate::foundation::signal::ONE;
            KnotKind::Threshold {
                domain,
                high: one / 2,
                low: one * 2 / 5, // 0.4
                use_hysteresis: true,
            }
        }
    }

    /// Random sampler; resamples on rising `gate` when `require_gate` is true.
    pub fn random(require_gate: bool, domain: SignalDomain) -> Self {
        KnotKind::Random {
            domain,
            require_gate,
        }
    }

    /// Sqrt knot in `domain`.
    pub fn sqrt(domain: SignalDomain) -> Self {
        KnotKind::Sqrt { domain }
    }

    /// Boolean xor of `a` and `b`.
    pub fn xor() -> Self {
        KnotKind::Xor
    }

    /// Falling-edge detector: pulse when `in` crosses from truthy to falsey.
    pub fn falling_to_zero() -> Self {
        KnotKind::FallingToZero
    }

    /// Any-truthiness-change edge pulse on `in`.
    pub fn change() -> Self {
        KnotKind::Change
    }

    /// Clamp knot saturating `in` between `min` and `max` in `domain`.
    pub fn clamp(min: Signal, max: Signal, domain: SignalDomain) -> Self {
        KnotKind::Clamp { domain, min, max }
    }

    /// Cross-domain converter from `from` to `to` (must differ).
    pub fn convert(from: SignalDomain, to: SignalDomain) -> Self {
        KnotKind::Convert { from, to }
    }

    /// Whether all authored domain choices are legal for this knot kind.
    pub fn has_valid_domains(&self) -> bool {
        match self {
            KnotKind::Compare { domain, op, .. } => op.supports_domain(*domain),
            KnotKind::Calc { domain, .. }
            | KnotKind::Map { domain, .. }
            | KnotKind::Abs { domain }
            | KnotKind::Neg { domain }
            | KnotKind::Digitize { domain, .. }
            | KnotKind::Threshold { domain, .. }
            | KnotKind::Random { domain, .. }
            | KnotKind::Sqrt { domain }
            | KnotKind::Clamp { domain, .. } => domain.is_numeric(),
            KnotKind::Convert { from, to } => from != to,
            _ => true,
        }
    }

    /// And/Or input arity when applicable.
    pub fn arity(&self) -> Option<u8> {
        match self {
            KnotKind::And { arity } => Some(*arity),
            KnotKind::Or { arity } => Some(*arity),
            _ => None,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::foundation::signal::{from_count, from_level, ONE, ZERO};

    #[test]
    fn helpers_and_arity() {
        assert!(matches!(KnotKind::or2(), KnotKind::Or { arity: 2 }));
        assert!(matches!(KnotKind::not(), KnotKind::Not));
        assert!(matches!(
            KnotKind::constant_count(7),
            KnotKind::Constant { value, .. } if value == from_count(7)
        ));
        assert!(matches!(
            KnotKind::constant_bool(false),
            KnotKind::Constant {
                domain: SignalDomain::Bool,
                value: ZERO,
            }
        ));
        assert!(matches!(
            KnotKind::constant_level(0.25),
            KnotKind::Constant {
                domain: SignalDomain::Level,
                value,
            } if value == from_level(0.25)
        ));
        assert!(matches!(
            KnotKind::emit_command("go"),
            KnotKind::EmitCommand { name } if name == "go"
        ));
        assert_eq!(KnotKind::and2().arity(), Some(2));
        assert_eq!(KnotKind::or2().arity(), Some(2));
        assert_eq!(KnotKind::not().arity(), None);
        assert_eq!(NumericPath::compiled(), NumericPath::compiled());
        let _ = ONE;
        let _ = KnotKind::signal_in(SignalDomain::Bool);
        let _ = KnotKind::signal_out("p", SignalDomain::Bool);
        let _ = KnotKind::rising_from_zero();
        let _ = KnotKind::compare(CompareOp::Eq, None, SignalDomain::Bool);
        let _ = KnotKind::counter();
        let _ = KnotKind::timer(TimerMode::PulseHold, 1);
        let _ = KnotKind::flag(FlagPriority::SetWins, false);
        let _ = KnotKind::constant(ONE, SignalDomain::Bool);
        let _ = KnotKind::select();
        let _ = KnotKind::calc(CalcOp::Add, SignalDomain::Count);
        let _ = KnotKind::map(crate::ZERO, ONE, crate::ZERO, ONE, SignalDomain::Level);
        let _ = KnotKind::abs(SignalDomain::Level);
        let _ = KnotKind::neg(SignalDomain::Count);
        let _ = KnotKind::digitize(4, SignalDomain::Level);
        let _ = KnotKind::threshold_default(SignalDomain::Level);
        let _ = KnotKind::random(false, SignalDomain::Count);
        let _ = KnotKind::sqrt(SignalDomain::Count);
        let _ = KnotKind::xor();
        let _ = KnotKind::falling_to_zero();
        let _ = KnotKind::change();
        let _ = KnotKind::clamp(crate::ZERO, ONE, SignalDomain::Level);
        let _ = KnotKind::convert(SignalDomain::Count, SignalDomain::Level);
    }

    #[test]
    fn domain_legality_is_catalog_owned() {
        assert!(KnotKind::compare(CompareOp::Eq, None, SignalDomain::Bool).has_valid_domains());
        assert!(!KnotKind::compare(CompareOp::Lt, None, SignalDomain::Bool).has_valid_domains());
        assert!(KnotKind::calc(CalcOp::Mul, SignalDomain::Count).has_valid_domains());
        assert!(!KnotKind::calc(CalcOp::Mul, SignalDomain::Bool).has_valid_domains());
        assert!(KnotKind::convert(SignalDomain::Bool, SignalDomain::Level).has_valid_domains());
        assert!(!KnotKind::convert(SignalDomain::Bool, SignalDomain::Bool).has_valid_domains());
        assert!(KnotKind::signal_in(SignalDomain::Bool).has_valid_domains());

        let numeric_kinds = [
            KnotKind::map(ZERO, ONE, ZERO, ONE, SignalDomain::Level),
            KnotKind::abs(SignalDomain::Level),
            KnotKind::neg(SignalDomain::Count),
            KnotKind::digitize(2, SignalDomain::Level),
            KnotKind::threshold_default(SignalDomain::Level),
            KnotKind::random(false, SignalDomain::Count),
            KnotKind::sqrt(SignalDomain::Level),
            KnotKind::clamp(ZERO, ONE, SignalDomain::Count),
        ];
        assert!(numeric_kinds.iter().all(KnotKind::has_valid_domains));
    }
}