- Core library with SVG and PNG generation - CLI tool with generate and batch commands - Cross-platform path handling for Windows compatibility - Comprehensive test suite with integration tests
52 lines
2.2 KiB
Go
52 lines
2.2 KiB
Go
/*
|
|
Package engine contains the core, format-agnostic logic for generating Jdenticon
|
|
identicons. It is responsible for translating an input hash into a structured,
|
|
intermediate representation of the final image.
|
|
|
|
This package is internal to the jdenticon library and its API is not guaranteed
|
|
to be stable. Do not use it directly.
|
|
|
|
# Architectural Overview
|
|
|
|
The generation process follows a clear pipeline:
|
|
|
|
1. Hashing: An input value (e.g., a username) is hashed into a byte slice. This
|
|
is handled by the public `jdenticon` package.
|
|
|
|
2. Generator: The `Generator` struct is the heart of the engine. It consumes the
|
|
hash to deterministically select shapes, colors, and their transformations
|
|
(rotation, position).
|
|
|
|
3. Shape Selection: Based on bytes from the hash, specific shapes are chosen from
|
|
the predefined shape catalog in `shapes.go`.
|
|
|
|
4. Transform & Positioning: The `transform.go` file defines how shapes are
|
|
positioned and rotated within the icon's grid. The center shape is
|
|
handled separately from the outer shapes.
|
|
|
|
5. Colorization: `color.go` uses the hash and the `Config` to determine the
|
|
final hue, saturation, and lightness of the icon's foreground color.
|
|
|
|
The output of this engine is a `[]RenderedElement`, which is a list of
|
|
geometries and their associated colors. This intermediate representation is then
|
|
passed to a renderer (see the `internal/renderer` package) to produce the final
|
|
output (e.g., SVG or PNG). This separation of concerns allows the core generation
|
|
logic to remain independent of the output format.
|
|
|
|
# Key Components
|
|
|
|
- generator.go: Main generation algorithm and core deterministic logic
|
|
- shapes.go: Shape definitions and rendering with coordinate transformations
|
|
- color.go: Color theme generation using HSL color space
|
|
- config.go: Internal configuration structures and validation
|
|
- transform.go: Coordinate transformation utilities
|
|
|
|
# Hash-Based Determinism
|
|
|
|
The engine ensures deterministic output by using specific positions within the
|
|
input hash to drive shape selection, color generation, and transformations.
|
|
This guarantees that identical inputs always produce identical identicons while
|
|
maintaining visual variety across different inputs.
|
|
*/
|
|
package engine
|