Add "Spiral" to the Shape tool and as a new node (#2803)

* made spiral node

* number of turns in decimal and arc-angle implementation

* logarithmic spiral

* unified log and arc spiral into spiral node

* add spiral shape in shape tool

* fix min value and degree unit

* make it compile

* updated the api

* changed the function_name

* [/] to update the turns widget in shape tool

* Code review

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0SlowPoke0
2025-09-09 03:07:43 +05:30
committed by GitHub
parent ee586be381
commit 485152bf8d
15 changed files with 483 additions and 44 deletions

View File

@@ -5,7 +5,7 @@ use crate::registry::types::{Angle, PixelSize};
use crate::subpath;
use crate::table::Table;
use crate::vector::Vector;
use crate::vector::misc::HandleId;
use crate::vector::misc::{HandleId, SpiralType};
use glam::DVec2;
trait CornerRadius {
@@ -75,6 +75,27 @@ fn arc(
)))
}
#[node_macro::node(category("Vector: Shape"), properties("spiral_properties"))]
fn spiral(
_: impl Ctx,
_primary: (),
spiral_type: SpiralType,
#[default(5.)] turns: f64,
#[default(0.)] start_angle: f64,
#[default(0.)] inner_radius: f64,
#[default(25)] outer_radius: f64,
#[default(90.)] angular_resolution: f64,
) -> Table<Vector> {
Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_spiral(
inner_radius,
outer_radius,
turns,
start_angle.to_radians(),
angular_resolution.to_radians(),
spiral_type,
)))
}
#[node_macro::node(category("Vector: Shape"))]
fn ellipse(
_: impl Ctx,

View File

@@ -415,3 +415,11 @@ impl HandleId {
}
}
}
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, Hash, DynAny, specta::Type, node_macro::ChoiceType)]
#[widget(Dropdown)]
pub enum SpiralType {
#[default]
Archimedean,
Logarithmic,
}

View File

@@ -241,9 +241,8 @@ async fn repeat<I: 'n + Send + Clone>(
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn circular_repeat<I: 'n + Send + Clone>(
_: impl Ctx,
// TODO: Implement other graphical types.
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>)] instance: Table<I>,
angle_offset: Angle,
start_angle: Angle,
#[unit(" px")]
#[default(5)]
radius: f64,
@@ -254,7 +253,7 @@ async fn circular_repeat<I: 'n + Send + Clone>(
let mut result_table = Table::new();
for index in 0..count {
let angle = DAffine2::from_angle((TAU / count as f64) * index as f64 + angle_offset.to_radians());
let angle = DAffine2::from_angle((TAU / count as f64) * index as f64 + start_angle.to_radians());
let translation = DAffine2::from_translation(radius * DVec2::Y);
let transform = angle * translation;