Skip to content

Commit 59fe413

Browse files
n-star: Take inner-radius as a sep. argument (#957)
1 parent d888ab3 commit 59fe413

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- Added a new `(project: <coordinate>, onto: (<coordinate>, <coordinate>))`
2121
coordinate for projecting a point onto a line (short form: `(pt, "_|_", a, b)`)
2222
- Debug shapes (bounding boxes) are ignored by `merge-path` (#575)
23+
- **BREAKING** The `n-star` element now takes the inner radius as a separate style key `inner-radius` (ratio or number) (#920)
24+
- Fixed an issue with multiline text and baseline anchors in `content` (#956)
2325

2426
# 0.4.1
2527
- Added a `n-star` shape for drawing n-pointed stars

src/draw/shapes.typ

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@
708708
///
709709
/// ## Styling
710710
/// Root: nstar
711-
/// - radius (inner, outer) = : The radius of the star's inner and outer points.
711+
/// - radius (number): The radius of the star's outer points.
712+
/// - inner-radius (number,ratio): The radius (relative to the outer radius) of the star's inner points(relative to the outer radius) of the star's inner points.
712713
/// - show-inner (bool) = false: If true, also draws the inner polygon connecting the star's inner points.
713714
/// - fill (color, gradient): The fill color for the star.
714715
/// - stroke (color, thickness, ...): The stroke for the star and the inner polygon.
@@ -723,10 +724,11 @@
723724
let style = styles.resolve(ctx.style, merge: style, root: "n-star")
724725

725726
let (ctx, origin) = coordinate.resolve(ctx, origin)
726-
let (inner-radius, outer-radius) = if type(style.radius) == array {
727-
style.radius.map(util.resolve-number.with(ctx))
727+
let outer-radius = util.resolve-number(ctx, style.radius)
728+
let inner-radius = if type(style.inner-radius) == ratio {
729+
outer-radius * style.inner-radius / 100%
728730
} else {
729-
(style.radius, style.radius).map(util.resolve-number.with(ctx))
731+
util.resolve-number(ctx, style.inner-radius)
730732
}
731733

732734
let angle-step = 360deg / sides

src/styles.typ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
),
130130
n-star: (
131131
radius: auto,
132+
inner-radius: 50%,
132133
stroke: auto,
133134
fill: auto,
134135
// Connect inner points of the star

tests/shapes/n-star/ref/1.png

-29 KB
Loading

tests/shapes/n-star/test.typ

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
#import "/src/lib.typ": *
33
#import "/tests/helper.typ": *
44

5-
#test-case(
6-
sides => {
5+
#test-case(sides => {
76
import cetz.draw: *
7+
n-star((0, 0), sides, angle: 9deg)
8+
}, args: (3, 4, 5, 6, 7))
89

9-
n-star((0, 0), sides, angle: 9deg, stroke: luma(200) + 1pt)
10-
set-origin((3, 0))
11-
n-star((0, 0), sides, radius: (1, 1.5), angle: 30deg)
12-
set-origin((4, 0))
13-
n-star((0, 0), sides, radius: (1, 2), angle: 60deg, fill: red)
14-
set-origin((4.5, 0))
15-
n-star((0, 0), sides, radius: (1, 2.5), angle: 90deg, fill: blue, show-inner: true)
16-
},
17-
args: (3, 4, 5, 6, 7),
18-
)
10+
#test-case(sides => {
11+
import cetz.draw: *
12+
n-star((0, 0), inner-radius: 0.8, sides, fill: blue)
13+
}, args: (3, 4, 5, 6, 7))

0 commit comments

Comments
 (0)