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

line: Draw line between element borders #378

Merged
merged 3 commits into from
Dec 9, 2023

Conversation

johannes-wolf
Copy link
Member

Fixes #234

If last and or first argument of line is an element name, use that for intersection test.
Saves complete elements in ctx.nodes.

@johannes-wolf johannes-wolf added this to the 0.2 milestone Dec 6, 2023
@johannes-wolf johannes-wolf force-pushed the cetz-234-lines-between-elements branch 5 times, most recently from ce6d19f to fced1b5 Compare December 6, 2023 16:28
@johannes-wolf johannes-wolf linked an issue Dec 6, 2023 that may be closed by this pull request
src/draw/shapes.typ Outdated Show resolved Hide resolved
src/draw/shapes.typ Show resolved Hide resolved
src/draw/shapes.typ Outdated Show resolved Hide resolved
src/draw/shapes.typ Outdated Show resolved Hide resolved
Comment on lines 642 to 634
pts.first() = if first-is-elem {
let elem = ctx.nodes.at(first-elem)

let (a, b) = pts.slice(0, 2)
element-line-intersection(ctx, elem, a, b)
} else {
pts.first()
}

// If the last coordinate is an element, test for intersection
// of that element and a line from the two last coordinates of this
// line strip.
pts.last() = if last-is-elem {
let elem = ctx.nodes.at(last-elem)

let (a, b) = pts.slice(-2)
element-line-intersection(ctx, elem, a, b)
} else {
pts.last()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in a for loop which would be easier to read

(pts.first(), pts.last()) = for (name, a, b) in ((first-elem, ..pts.slice(0,2)), (last-elem, pts.slice(-2)) {
...
}

tests/intersection/test.typ Show resolved Hide resolved
src/anchor.typ Outdated Show resolved Hide resolved
src/draw/shapes.typ Outdated Show resolved Hide resolved
@johannes-wolf johannes-wolf force-pushed the cetz-234-lines-between-elements branch 2 times, most recently from ac4ac20 to 13ec259 Compare December 6, 2023 19:58
Copy link
Member

@fenjalien fenjalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having double thoughts about not using border anchors for this. If we do custom elements can define their own border instead relying on something you can't easily configure...

Comment on lines 561 to 563
/// If the first or last coordinate given is the name of an element,
/// the intersection of that element and a line from the first or last
/// two coordinates given is used as coordinate. This is useful to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "If the first or last points are given as the name of an element, that has a "default" anchor, the intersection of that element's border and the line."

@johannes-wolf
Copy link
Member Author

johannes-wolf commented Dec 7, 2023

I'm having double thoughts about not using border anchors for this. If we do custom elements can define their own border instead relying on something you can't easily configure...

I do not get what you mean. Custom elements should be able to override the behavior of how the intersection is determined? Ok, let's do that: the function calls the border anchor function with an angle calculated between the two points. With this PR the border-anchor got changed to the furthest one by default, which is correct for this case, too.

@johannes-wolf johannes-wolf force-pushed the cetz-234-lines-between-elements branch 2 times, most recently from 5aec01b to c3c1acf Compare December 8, 2023 02:39
@johannes-wolf
Copy link
Member Author

johannes-wolf commented Dec 8, 2023

@fenjalien I suggest removing the WIP commit and pushing this as a shortcut for intersections(..)
anchors should be refined at a later stage (not necessarily for 0.2.0).

@johannes-wolf johannes-wolf force-pushed the cetz-234-lines-between-elements branch 3 times, most recently from 38f76f7 to bb97d94 Compare December 9, 2023 21:08
@johannes-wolf johannes-wolf merged commit 9b20adc into 0.2.0 Dec 9, 2023
2 checks passed
@johannes-wolf johannes-wolf deleted the cetz-234-lines-between-elements branch December 9, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drawing well-centered lines between elements
2 participants