Skip to content

Utilities

Snowpulse includes small helpers for randomized values, geometric overlap queries, and dictionary/trie searches.

Randomizer

Randomizer offers:

  • randomSeed(seed) for repeatable output; a negative seed restores a nondeterministic seed.
  • randomFloat(min, max) for a floating-point value in [min, max).
  • randomInt(min, max) with an exclusive upper bound.
  • randomBool() and randomSign() (-1.0f or 1.0f).

If max <= min, the range methods return min.

auto* random = context()->randomizer();
random->randomSeed(2026);

const float opacity = random->randomFloat(0.25f, 1.0f);
const int index = random->randomInt(0, 4);  // 0, 1, 2, or 3
const bool enabled = random->randomBool();
const float direction = random->randomSign();

OverlapChecker

OverlapChecker accepts centers and half-extents for boxes. Oriented-box rotations are in radians. Contact at an edge counts as overlap or containment. The available queries are:

  • aabbVsAabb, aabbVsCircle, and circleVsCircle
  • obbVsObb and obbVsCircle
  • aabbContainsPoint, obbContainsPoint, and circleContainsPoint
auto* overlap = context()->overlapChecker();

const bool boxesTouch = overlap->aabbVsAabb(
    { 0.0f, 0.0f }, { 10.0f, 6.0f },
    { 14.0f, 0.0f }, { 5.0f, 5.0f });

const bool circlesTouch = overlap->circleVsCircle(
    { 0.0f, 0.0f }, 8.0f,
    { 12.0f, 0.0f }, 5.0f);

const bool rotatedBoxTouchesCircle = overlap->obbVsCircle(
    { 0.0f, 0.0f }, { 12.0f, 4.0f }, 0.5f,
    { 8.0f, 3.0f }, 3.0f);

const bool containsPointer = overlap->obbContainsPoint(
    { 20.0f, 20.0f }, { 8.0f, 4.0f }, 0.25f,
    { 22.0f, 21.0f });

Word Utilities

snowpulse::WordDictionary loads newline-separated entries, owns a snowpulse::WordTrie, and builds indexes used by snowpulse::WordFinder. Entries are normalized to lowercase ASCII. Empty lines are ignored, duplicates are counted, and entries containing characters outside a-z are skipped. Calling loadFromText() replaces the previous contents.

WordFinder keeps a reference to its dictionary, so the dictionary must outlive the finder. isPrefix() means PrefixOnly; use isWordOrPrefix() when an exact word should also pass a prefix query.

const std::string wordsText =
    context()->assetManager()->loadText("data/dictionary.txt");

snowpulse::WordDictionary dictionary(wordsText);
const std::size_t accepted = dictionary.wordCount();
const std::size_t skipped = dictionary.skippedWordCount();
const std::size_t duplicates = dictionary.duplicateWordCount();
const std::string summary = dictionary.info();

snowpulse::WordFinder finder(dictionary);
const bool exact = finder.isWord("sample");
const bool validStart = finder.isWordOrPrefix("sam");
const auto prefixed = finder.findWordsWithPrefix("sam", 3, 8);
const auto constructible = finder.findWordsWithinString("examples", 3, 8);

Use snowpulse::WordTrie directly when entries are assembled in memory:

snowpulse::WordTrie trie;
trie.insert("alpha");
trie.insert("alpine");

const snowpulse::WordTrieQueryResult query = trie.validate("alp");
const auto matches = trie.findWords("alp", 4, 8);
const std::size_t rootBranches = trie.childrenCount();
trie.clear();