diff --git a/gallery/example1.pdf b/gallery/example1.pdf index 750205d..53f7f9e 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example1.typ b/gallery/example1.typ index 3af0b84..f9d2cc2 100644 --- a/gallery/example1.typ +++ b/gallery/example1.typ @@ -26,7 +26,7 @@ disc(center: ($0$, "bottom"), eod: true), disc(center: ($0$, "bottom")), val(asymp($y=1$), "top"), - inter($y_0$, 2, 4, i: 2) + inter($y_0$, 2, 3) ) ) convex-line( @@ -68,7 +68,7 @@ val($2$, "bottom"), none, val(asymp($2sqrt(2)$), "top"), - inter($(2sqrt(1 + sqrt(5))) / sqrt(3)$, 3, 4, i: 5) + inter($(2sqrt(1 + sqrt(5))) / sqrt(3)$, 3, 4) )) convex-line("concavité", ( @@ -118,7 +118,7 @@ val([min], "bottom"), none, val(asymp($x = 0$), "top"), - inter($0$, 0, 1, i: 1), + inter($0$, 0, 1), inter($0$, 1, 2, i: 4) ) ) diff --git a/src/func.typ b/src/func.typ index aa210aa..212fa48 100644 --- a/src/func.typ +++ b/src/func.typ @@ -41,10 +41,6 @@ } #let inter(value, start, end, i: auto) = { - let i = i - if i == auto { - i = calc.floor( (start + end) / 2 ) - } return ( type: "intermediate", value: value, diff --git a/src/renderer.typ b/src/renderer.typ index 9990dc4..ff240d2 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -154,6 +154,7 @@ let header = "header-" + str(line-i) let ood = line.start-ood let value-i = -1 + let values-anchors = (:) if line.start-ood and line.values.len() != 0 { let first = line.values.first() @@ -178,6 +179,7 @@ if value.type == "value" { let pos = func.get-anchor(ctx, line-i, i, value.alignment, "center") value-i += 1 + values-anchors.insert(str(value-i), i) draw.content( name: "value-" + str(value-i), pos, @@ -193,8 +195,14 @@ } else if value.type == "intermediate" { let start = "value-" + str(value.start) let end = "value-" + str(value.end) - let top = func.get-anchor(ctx, line-i, value.i, "top", "center", dy: 0) - let bottom = func.get-anchor(ctx, line-i, value.i, "bottom", "center", dy: 0) + let i = value.i + if i == auto { + let start-anchor = values-anchors.at(str(value.start)) + let end-anchor = values-anchors.at(str(value.end)) + i = calc.floor((start-anchor + end-anchor) / 2) + } + let top = func.get-anchor(ctx, line-i, i, "top", "center", dy: 0) + let bottom = func.get-anchor(ctx, line-i, i, "bottom", "center", dy: 0) let inter-name = "inter-" + str(i) draw.intersections(inter-name, { draw.hide(draw.line(start, end)) @@ -257,6 +265,7 @@ if value.left.value != none { let p = func.get-anchor(ctx, line-i, i, value.left.alignment, "left") value-i += 1 + values-anchors.insert(str(value-i), i) draw.content( name: "value-" + str(value-i), p, @@ -274,6 +283,7 @@ if value.center.value != none { let p = func.get-anchor(ctx, line-i, i, value.center.alignment, "center") value-i += 1 + values-anchors.insert(str(value-i), i) draw.content( name: "value-" + str(value-i), p, @@ -291,6 +301,7 @@ if value.right.value != none { let p = func.get-anchor(ctx, line-i, i, value.right.alignment, "right") value-i += 1 + values-anchors.insert(str(value-i), i) draw.content( name: "value-" + str(value-i), p,