///|
/// Creates a regular polygon path.
pub fn Path::regular(
center : Vec2,
sides : Int,
radius : Double,
phase? : Double = 0.0,
) -> Path {
polyline(regular_polygon(center, sides, radius, phase~), closed=true)
}
///|
/// Creates a rounded rectangle using four cubic corner arcs.
pub fn Path::rounded_rect(
width : Double,
height : Double,
radius : Double,
x? : Double = 0.0,
y? : Double = 0.0,
) -> Path {
let r = radius.min(width / 2.0).min(height / 2.0)
let k = 0.5522847498
Path::new()
.move_to(x + r, y)
.line_to(x + width - r, y)
.cubic_to(
x + width - r + k * r,
y,
x + width,
y + r - k * r,
x + width,
y + r,
)
.line_to(x + width, y + height - r)
.cubic_to(
x + width,
y + height - r + k * r,
x + width - r + k * r,
y + height,
x + width - r,
y + height,
)
.line_to(x + r, y + height)
.cubic_to(
x + r - k * r,
y + height,
x,
y + height - r + k * r,
x,
y + height - r,
)
.line_to(x, y + r)
.cubic_to(x, y + r - k * r, x + r - k * r, y, x + r, y)
.close()
}
///|
/// Creates a capsule aligned with the x axis.
pub fn Path::capsule(
width : Double,
height : Double,
x? : Double = 0.0,
y? : Double = 0.0,
) -> Path {
let r = height / 2.0
let k = 0.5522847498
Path::new()
.move_to(x + r, y)
.line_to(x + width - r, y)
.cubic_to(
x + width - r + k * r,
y,
x + width,
y + r - k * r,
x + width,
y + r,
)
.cubic_to(
x + width,
y + r + k * r,
x + width - r + k * r,
y + height,
x + width - r,
y + height,
)
.line_to(x + r, y + height)
.cubic_to(x + r - k * r, y + height, x, y + r + k * r, x, y + r)
.cubic_to(x, y + r - k * r, x + r - k * r, y, x + r, y)
.close()
}
///|
/// Creates an arrow pointing along the positive x axis.
pub fn Path::arrow(length : Double, width : Double, head : Double) -> Path {
let safe_head = head.min(length)
Path::new()
.move_to(0.0, -width / 2.0)
.line_to(length - safe_head, -width / 2.0)
.line_to(length - safe_head, -width)
.line_to(length, 0.0)
.line_to(length - safe_head, width)
.line_to(length - safe_head, width / 2.0)
.line_to(0.0, width / 2.0)
.close()
}
///|
/// Creates a gear-like polygon with alternating tooth radii.
pub fn Path::gear(
center : Vec2,
teeth : Int,
inner_radius : Double,
outer_radius : Double,
phase? : Double = 0.0,
) -> Path {
let options = GeneratorOptions::new(center, outer_radius, teeth).with_phase(
phase,
)
rosette(options, inner_radius)
}
///|
/// Creates a logarithmic spiral as a sampled polyline.
pub fn Path::spiral(
center : Vec2,
turns : Double,
samples : Int,
start_radius : Double,
growth : Double,
phase? : Double = 0.0,
) -> Path {
let points = []
if samples > 1 {
for i in 0.. Path {
let half = size / 2.0
let arm = thickness / 2.0
polyline(
[
Vec2::new(-arm, -half),
Vec2::new(arm, -half),
Vec2::new(arm, -arm),
Vec2::new(half, -arm),
Vec2::new(half, arm),
Vec2::new(arm, arm),
Vec2::new(arm, half),
Vec2::new(-arm, half),
Vec2::new(-arm, arm),
Vec2::new(-half, arm),
Vec2::new(-half, -arm),
Vec2::new(-arm, -arm),
],
closed=true,
)
}