Skip to content

Commit

Permalink
arc: Set previous point to arc end (#360)
Browse files Browse the repository at this point in the history
The `arc` command should update the previous point to its end-point.
This might be inconsistent, though, as there are no other commands
setting the previous point to a non user-provided one. Should we add an
option to enable/disable this @fenjalien?
  • Loading branch information
johannes-wolf authored Dec 4, 2023
1 parent 9303e08 commit c3ab713
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
Binary file modified manual.pdf
Binary file not shown.
9 changes: 8 additions & 1 deletion src/draw/shapes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
/// == Keys
/// #show-parameter-block("radius", ("number", "array"), [The radius of the arc. An elliptical arc can be created by passing a tuple of numbers where the first element is the x radius and the second element is the y radius.], default: 1)
/// #show-parameter-block("mode", ("string",), [The options are: "OPEN" no additional lines are drawn so just the arc is shown; "CLOSE" a line is drawn from the start to the end of the arc creating a circular segment; "PIE" lines are drawn from the start and end of the arc to the origin creating a circular sector.], default: "OPEN")
/// #show-parameter-block("update-position", ("bool",), [Update the current canvas position to the arc's end point (anchor `"arc-end"`).
/// This overrides the default of `true`, that allows chaining of (arc) elements.], default: true)
///
/// = Anchors
/// Supports compass anchors when `mode` is "PIE"
Expand Down Expand Up @@ -311,7 +313,12 @@
z
)

// center is calculated based on observations of tikz's circular sector and semi circle shapes.
// Set the last position to arc-end
if style.update-position {
ctx.prev.pt = arc-end
}

// Center is calculated based on observations of tikz's circular sector and semi circle shapes.
let center = if style.mode != "CLOSE" {
// A circular sector's center anchor is placed half way between the sector-center and arc-center when the angle is 180deg. At 60deg it is placed 1/3 of the way between, this is mirrored at 300deg.
vector.lerp(
Expand Down
1 change: 1 addition & 0 deletions src/styles.typ
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
// - "PIE"
mode: "OPEN",
mark: _default-mark,
update-position: true,
),
content: (
// Allowed values:
Expand Down
Binary file added tests/arc/last-pos/ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tests/arc/last-pos/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#set page(width: auto, height: auto)
#import "/src/lib.typ": *

#box(stroke: 2pt + red, canvas({
import draw: *

arc((0,0), start: 0deg, stop: 180deg)
circle((), radius: .1, fill: blue)
}))

#box(stroke: 2pt + red, canvas({
import draw: *

arc((0,0), start: 180deg, stop: 0deg)
circle((), radius: .1, fill: blue)
}))

#box(stroke: 2pt + red, canvas({
import draw: *

arc((0,0), start: 180deg, stop: 0deg, update-position: false)
circle((), radius: .1, fill: blue)
}))

0 comments on commit c3ab713

Please sign in to comment.