Vector Types & Algorithms
Relevant source files
The following files were used as context for generating this wiki page:
- node-graph/libraries/vector-types/src/lib.rs
- node-graph/libraries/vector-types/src/vector/algorithms/mod.rs
- node-graph/libraries/vector-types/src/subpath/core.rs
- website/content/features.md
- website/content/learn/introduction/features-and-limitations.md
- website/content/volunteer/guide/student-projects/completed-projects.md
- website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md
- website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Vector types and algorithms form the foundation of Graphite's procedural graphics engine, Graphene. These components allow the editor to represent, manipulate, and render mathematical curves and shapes that remain sharp at any scale. Unlike raster data which relies on pixel grids, vector data in Graphite is treated as a collection of geometric instructions—such as paths, fills, and strokes—that are redrawn dynamically based on the user's viewport resolution.
The core of this system is powered by the Bezier-rs library, a standalone Rust crate designed to handle computational geometry for Bézier curves and paths. This architecture enables nondestructive editing workflows, where complex shapes are generated through a sequence of nodes (e.g., Path, Fill, and Boolean Operation) rather than destructive pixel alterations.
Sources: website/content/features.md:38-48, website/content/learn/introduction/features-and-limitations.md:4-15, website/content/volunteer/guide/student-projects/completed-projects.md:120-130
Core Data Structures
Graphite represents vector artwork using a hierarchy of geometric primitives. Primitive geometry like rectangles and ellipses serve as the base, which can be further modified into complex organic shapes using the Pen and Path tools.
Bezier-rs Integration
The Bezier-rs library provides the API for representing Bézier curves and paths. It serves as the underlying vector data format, supporting advanced computational geometry algorithms required for professional illustration.
| Component | Description |
|---|---|
| Bezier Curve | The fundamental building block representing a single curved segment. |
| Path | A sequence of Bezier segments that form a shape. |
| Subpath | A distinct component of a larger path, which may be open or closed. |
Sources: website/content/learn/introduction/features-and-limitations.md:10-15, website/content/volunteer/guide/student-projects/completed-projects.md:120-135
Geometric Primitives
Users can generate primitive shapes through specific nodes. For example, the Rectangle node supports corner rounding, and the Poisson-Disk Points node allows for sampling randomly distributed points within a shape.
Sources: website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:53-58, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:118-125
Vector Algorithms
Graphite utilizes a variety of algorithms to perform procedural modifications on vector data. These algorithms are typically exposed as nodes within the Graphene engine.
Path Manipulation
Path manipulation algorithms allow for the transformation of raw geometry into complex designs:
- Solidify Stroke: Converts a vector stroke into a filled shape.
- Morph: Performs tweening between two different vector shapes.
- Copy to Points: Scatters instances of a shape across points sampled from another path, with support for randomizing scale and rotation.
Sources: website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:73-81, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:101-106, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:185-187
Boolean Operations
Boolean operations allow for constructive solid geometry (CSG) on 2D paths. These operations are nondestructive and can be updated by changing node parameters.
The Boolean Operation node combines two shape paths based on the selected mode to produce a new resultant path.
Sources: website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:85-101
Computational Geometry Analysis
Graphite includes nodes that analyze existing geometry to provide data for subsequent procedural steps:
- Area: Calculates the interior size of a shape.
- Centroid: Determines the center of mass of a shape.
- Sample Points: Samples points along a path, utilized by scattering and repeating nodes.
Sources: website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:74-83, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:215-217
Data Flow in Procedural Design
The following diagram illustrates how vector types flow through nodes to generate visual output.
Graphical data starts as raw geometry (Path) and is transformed by styling nodes (Fill) and generator nodes (Circular Repeat) before reaching the final output.
Sources: website/content/learn/introduction/features-and-limitations.md:25-50
Procedural Scattering & Repetition
One of the key strengths of the vector system is the ability to build "procedures" for repeating geometry.
| Node | Key Parameters | Outcome |
|---|---|---|
| Circular Repeat | Angle Offset, Radius, Instances | Distributes copies of a shape in a radial pattern. |
| Repeat | Rotation, Offset, Count | Creates linear or grid-based repetitions. |
| Poisson-Disk | Density, Seed | Samples points with a minimum distance constraint. |
Sources: website/content/learn/introduction/features-and-limitations.md:50-60, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:60-65, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md:118-125
Conclusion
The Vector Types & Algorithms system provides the mathematical and architectural framework for Graphite's "Hybrid Editing" experience. By treating artwork as data and utilizing specialized algorithms like Bézier manipulation and boolean operations, Graphite enables a powerful, nondestructive workflow that bridges the gap between traditional illustration and procedural design.
Sources: website/content/features.md:27-36, website/content/volunteer/guide/student-projects/completed-projects.md:120-135