Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arc: Set previous point to arc end #360

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}))