|
34 | 34 | return calc.sin(angle/2) * (style.stroke.thickness / 2)
|
35 | 35 | }
|
36 | 36 |
|
37 |
| -#let create-tip-and-base-anchor(style, tip, base, center: none, respect-stroke-thickness: true) = { |
38 |
| - if base == tip { base = vector.add(tip, (1e-8, 0, 0)) } |
| 37 | +#let create-tip-and-base-anchor(style, tip, base, center: none, respect-stroke-thickness: false) = { |
| 38 | + if base == auto or base == tip { |
| 39 | + base = vector.add(tip, (1e-6, 0, 0)) |
| 40 | + } |
39 | 41 | let dir = vector.norm(vector.sub(tip, base))
|
40 | 42 |
|
41 | 43 | let thickness = if respect-stroke-thickness {
|
|
52 | 54 | }
|
53 | 55 |
|
54 | 56 | #let create-triangle-tip-and-base-anchor(style, tip, base, center: none) = {
|
55 |
| - if base == tip { base = vector.add(tip, (1e-8, 0, 0)) } |
| 57 | + if base == auto or base == tip { |
| 58 | + base = vector.add(tip, (1e-6, 0, 0)) |
| 59 | + } |
56 | 60 | let dir = vector.norm(vector.sub(tip, base))
|
| 61 | + let dist = vector.dist(tip, base) |
| 62 | + let thickness = calc.min(style.stroke.at("thickness", default: 0), dist) / 2 |
57 | 63 |
|
58 | 64 | import "/src/draw.typ": anchor
|
59 | 65 | if style.reverse {
|
60 | 66 | // Since tip and base are now "swapped", we add the stroke thickness to the triangle
|
61 | 67 | // base. To get smooth looking connections between the triangle tip and a connecting line,
|
62 | 68 | // we do not add the tip-offset.
|
63 |
| - anchor("tip", vector.add(tip, vector.scale(dir, style.stroke.thickness / 2))) |
64 |
| - anchor("base", base) |
| 69 | + anchor("tip", tip) |
| 70 | + anchor("base", vector.sub(base, vector.scale(dir, thickness))) |
65 | 71 | } else {
|
66 | 72 | anchor("tip", vector.add(tip, vector.scale(dir, _calculate-tip-offset(style))))
|
67 |
| - anchor("base", vector.sub(base, vector.scale(dir, style.stroke.thickness / 2))) |
| 73 | + anchor("base", base) |
68 | 74 | }
|
69 | 75 | }
|
70 | 76 |
|
|
96 | 102 | import "/src/draw.typ": *
|
97 | 103 |
|
98 | 104 | if style.harpoon {
|
99 |
| - line((0,0), (style.length, 0), (style.length, +style.width / 2), close: true) |
| 105 | + line((0,0), (style.length, 0), (style.length, style.width / 2), close: true) |
100 | 106 | } else {
|
101 |
| - line((0,0), (style.length, -style.width / 2), (style.length, +style.width / 2), close: true) |
| 107 | + line((0,0), (style.length, -style.width / 2), (style.length, style.width / 2), close: true) |
102 | 108 | }
|
103 | 109 |
|
104 | 110 | create-triangle-tip-and-base-anchor(style, (0, 0), (style.length, 0))
|
|
129 | 135 | }
|
130 | 136 |
|
131 | 137 | let offset = style.stroke.thickness / 2
|
132 |
| - create-tip-and-base-anchor(style, (offset, 0), (offset, 0), respect-stroke-thickness: false) |
| 138 | + create-tip-and-base-anchor(style, (-offset, 0), (offset, 0)) |
133 | 139 | anchor("center", (0, 0))
|
134 | 140 | },
|
135 | 141 | ellipse: (style) => {
|
|
143 | 149 | circle((0, 0), radius: r)
|
144 | 150 | }
|
145 | 151 |
|
146 |
| - create-tip-and-base-anchor(style, (r.at(0), 0), (-r.at(0), 0)) |
| 152 | + create-tip-and-base-anchor(style, (r.at(0), 0), (-r.at(0), 0), respect-stroke-thickness: true) |
147 | 153 | },
|
148 | 154 | circle: (style) => {
|
149 | 155 | import "/src/draw.typ": arc, circle
|
|
156 | 162 | circle((0, 0), radius: r)
|
157 | 163 | }
|
158 | 164 |
|
159 |
| - create-tip-and-base-anchor(style, (r, 0), (-r, 0)) |
| 165 | + create-tip-and-base-anchor(style, (r, 0), (-r, 0), respect-stroke-thickness: true) |
160 | 166 | },
|
161 | 167 | bracket: (style) => {
|
162 | 168 | import "/src/draw.typ": *
|
163 | 169 |
|
164 | 170 | let (l, w, i) = (style.length, style.width, style.inset)
|
165 | 171 |
|
166 | 172 | if style.harpoon {
|
167 |
| - line((-l - i, w / 2), (0, w / 2), (0, 0), fill: none) |
| 173 | + line((l + i, w / 2), (0, w / 2), (0, 0), fill: none) |
168 | 174 | } else {
|
169 |
| - line((-l - i, w / 2), (0, w / 2), (0, -w / 2), (-l - i, -w / 2), fill: none) |
| 175 | + line((l + i, w / 2), (0, w / 2), (0, -w / 2), (l + i, -w / 2), fill: none) |
170 | 176 | }
|
171 | 177 |
|
172 |
| - let offset = style.stroke.thickness / 2 |
173 |
| - create-tip-and-base-anchor(style, (offset, 0), (offset + 1e-8, 0)) |
| 178 | + create-tip-and-base-anchor(style, (0, 0), (0, 0), respect-stroke-thickness: true) |
174 | 179 | },
|
175 | 180 | diamond: (style) => {
|
176 | 181 | import "/src/draw.typ": *
|
|
196 | 201 | rect((0, -w / 2), (-l, +w / 2))
|
197 | 202 | }
|
198 | 203 |
|
199 |
| - create-tip-and-base-anchor(style, (0, 0), (-l, 0)) |
| 204 | + create-tip-and-base-anchor(style, (0, 0), (-l, 0), respect-stroke-thickness: true) |
200 | 205 | },
|
201 | 206 | hook: (style) => {
|
202 | 207 | import "/src/draw.typ": *
|
|
213 | 218 | }
|
214 | 219 | }, fill: none)
|
215 | 220 |
|
216 |
| - line((0, 0), (l - r, 0)) |
217 |
| - |
218 |
| - create-tip-and-base-anchor(style, (-r, 0), (l - r, 0), center: ((-r + i) / 2, 0), respect-stroke-thickness: false) |
| 221 | + create-tip-and-base-anchor(style, (-r, 0), (0, 0), center: ((-r + i) / 2, 0)) |
219 | 222 | },
|
220 | 223 | // An unfilled mark in the shape of an angle bracket (>).
|
221 | 224 | straight: (style) => {
|
|
230 | 233 | }
|
231 | 234 |
|
232 | 235 | if style.harpoon {
|
233 |
| - create-tip-and-base-anchor(style, (0, 0), (-1e-6, 0), respect-stroke-thickness: false) |
| 236 | + create-tip-and-base-anchor(style, (0, 0), (0, 0)) |
234 | 237 | } else {
|
235 | 238 | create-triangle-tip-and-base-anchor(style, (0, 0), (0, 0))
|
236 | 239 | }
|
|
254 | 257 | }, ..style)
|
255 | 258 |
|
256 | 259 | let offset = style.stroke.thickness / 2
|
257 |
| - create-tip-and-base-anchor(style, (-offset, 0), (-offset - 1e-6, 0), respect-stroke-thickness: false) |
| 260 | + create-tip-and-base-anchor(style, (-offset, 0), (2 * offset, 0)) |
258 | 261 | },
|
259 | 262 | plus: (style) => {
|
260 | 263 | import "/src/draw.typ": *
|
261 | 264 |
|
262 |
| - let style = style |
263 |
| - style.stroke.join = "round" |
264 |
| - |
265 | 265 | let (l, w) = (style.length, style.width)
|
266 | 266 |
|
267 | 267 | line((-l / 2, 0), (+l / 2, 0))
|
268 | 268 | line((0, -w / 2), (0, +w / 2))
|
269 | 269 |
|
270 |
| - create-tip-and-base-anchor(style, (0, 0), (l / 2, 0), respect-stroke-thickness: false) |
| 270 | + create-tip-and-base-anchor(style, (0, 0), (0, 0)) |
271 | 271 | },
|
272 | 272 | x: (style) => {
|
273 | 273 | import "/src/draw.typ": *
|
274 | 274 |
|
275 |
| - let style = style |
276 |
| - style.stroke.join = "round" |
277 |
| - |
278 | 275 | let (l, w) = (style.length, style.width)
|
279 | 276 |
|
280 | 277 | line((-l / 2, w / 2), (+l / 2, -w / 2))
|
281 | 278 | line((-l / 2, -w / 2), (+l / 2, +w / 2))
|
282 | 279 |
|
283 |
| - create-tip-and-base-anchor(style, (0, 0), (0, 0), respect-stroke-thickness: false) |
| 280 | + create-tip-and-base-anchor(style, (0, 0), (0, 0)) |
284 | 281 | },
|
285 | 282 | star: (style) => {
|
286 | 283 | import "/src/draw.typ": *
|
|
293 | 290 | line((0, 0), (calc.cos(a) * l / 2, calc.sin(a) * w / 2))
|
294 | 291 | }
|
295 | 292 |
|
296 |
| - create-tip-and-base-anchor(style, (0, 0), (l / 2, 0), respect-stroke-thickness: false) |
| 293 | + create-tip-and-base-anchor(style, (0, 0), (0, 0)) |
297 | 294 | },
|
298 | 295 | )
|
299 | 296 | #let names = marks.keys()
|
|
0 commit comments