UNPKG

@bitbybit-dev/base

Version:

Bit By Bit Developers Base CAD Library to Program Geometry

111 lines (110 loc) 4.59 kB
import * as Inputs from "../inputs"; /** * Contains various logic methods. */ export declare class Logic { /** * Creates and returns a boolean value (pass-through for boolean input). * Example: true → true, false → false * @param inputs a true or false boolean * @returns boolean * @group create * @shortname boolean * @drawable false */ boolean(inputs: Inputs.Logic.BooleanDto): boolean; /** * Generates a random boolean list where each value has a threshold chance of being true. * Example: length=5, threshold=0.7 → might produce [true, true, false, true, true] * @param inputs a length and a threshold for randomization of true values * @returns booleans * @group create * @shortname random booleans * @drawable false */ randomBooleans(inputs: Inputs.Logic.RandomBooleansDto): boolean[]; /** * Converts numbers to booleans using two thresholds with gradient randomization between them. * Values below trueThreshold → always true, above falseThreshold → always false. * Between thresholds → probability gradient (closer to false threshold = higher chance of false). * Example: [0.1, 0.4, 0.6, 0.9] with thresholds [0.3, 0.7] → [true, gradient, gradient, false] * @param inputs a length and a threshold for randomization of true values * @returns booleans * @group create * @shortname 2 threshold random gradient * @drawable false */ twoThresholdRandomGradient(inputs: Inputs.Logic.TwoThresholdRandomGradientDto): boolean[]; /** * Converts numbers to booleans based on a threshold (below threshold → true, above → false). * Can be inverted to flip the logic. * Example: [0.3, 0.7, 0.5] with threshold=0.6 → [true, false, true] * @param inputs a length and a threshold for randomization of true values * @returns booleans * @group create * @shortname threshold boolean list * @drawable false */ thresholdBooleanList(inputs: Inputs.Logic.ThresholdBooleanListDto): boolean[]; /** * Converts numbers to booleans using multiple range thresholds (gaps define true ranges). * Values within any gap range → true, outside all gaps → false. Can be inverted. * Example: [0.2, 0.5, 0.8] with gaps [[0.3, 0.6], [0.7, 0.9]] → [false, true, true] * @param inputs a length and a threshold for randomization of true values * @returns booleans * @group create * @shortname threshold gaps boolean list * @drawable false */ thresholdGapsBooleanList(inputs: Inputs.Logic.ThresholdGapsBooleanListDto): boolean[]; /** * Applies NOT operator to flip a boolean value. * Example: true → false, false → true * @param inputs a true or false boolean * @returns boolean * @group edit * @shortname not * @drawable false */ not(inputs: Inputs.Logic.BooleanDto): boolean; /** * Applies NOT operator to flip all boolean values in a list. * Example: [true, false, true] → [false, true, false] * @param inputs a list of true or false booleans * @returns booleans * @group edit * @shortname not list * @drawable false */ notList(inputs: Inputs.Logic.BooleanListDto): boolean[]; /** * Compares two values using various operators (==, !=, ===, !==, <, <=, >, >=). * Example: 5 > 3 → true, 'hello' === 'world' → false * @param inputs two values to be compared * @returns Result of the comparison * @group operations * @shortname compare * @drawable false */ compare<T>(inputs: Inputs.Logic.ComparisonDto<T>): boolean; /** * Conditionally passes a value through if boolean is true, otherwise returns undefined. * Example: value=42, boolean=true → 42, value=42, boolean=false → undefined * @param inputs a value and a boolean value * @returns value or undefined * @group operations * @shortname value gate * @drawable false */ valueGate<T>(inputs: Inputs.Logic.ValueGateDto<T>): T | undefined; /** * Returns the first defined (non-undefined) value from two options (fallback pattern). * Example: value1=42, value2=10 → 42, value1=undefined, value2=10 → 10 * @param inputs two values * @returns value or undefined * @group operations * @shortname first defined value gate * @drawable false */ firstDefinedValueGate<T, U>(inputs: Inputs.Logic.TwoValueGateDto<T, U>): T | U | undefined; }