Skip to content

Commit

Permalink
shapes: Make shapes CCW by default
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Jul 19, 2024
1 parent 6b9fa2b commit e931c83
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
24 changes: 12 additions & 12 deletions src/draw/shapes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,10 @@
let (rx, ry) = radius
if rx > 0 or ry > 0 {
let m = 0.551784
let p0 = (p0.at(0) * m * radius.at(0),
p0.at(1) * m * radius.at(1))
let p1 = (p1.at(0) * m * radius.at(0),
p1.at(1) * m * radius.at(1))
let p0 = (p0.at(0) * m * rx,
p0.at(1) * m * ry)
let p1 = (p1.at(0) * m * rx,
p1.at(1) * m * ry)
(path-util.cubic-segment(s, e,
vector.add(s, p0),
vector.add(e, p1)),)
Expand All @@ -1098,14 +1098,14 @@
let (p6, p7) = get-corner-pts(sw, (x1, y1, z), ( 1, 0), ( 0, 1))

let segments = ()
segments += corner-arc(nw, p0, p1, (0, 1), (-1, 0))
if p1 != p2 { segments += (path-util.line-segment((p1, p2)),) }
segments += corner-arc(ne, p2, p3, (1, 0), (0, 1))
if p3 != p4 { segments += (path-util.line-segment((p3, p4)),) }
segments += corner-arc(se, p4, p5, (0, -1), (1, 0))
if p5 != p6 { segments += (path-util.line-segment((p5, p6)),) }
segments += corner-arc(sw, p6, p7, (-1, 0), (0,-1))
if p7 != p0 { segments += (path-util.line-segment((p7, p0)),) }
segments += corner-arc(nw, p1, p0, (-1,0), (0, 1))
if p0 != p7 { segments += (path-util.line-segment((p0, p7)),) }
segments += corner-arc(sw, p7, p6, (0,-1), (-1,0))
if p6 != p5 { segments += (path-util.line-segment((p6, p5)),) }
segments += corner-arc(se, p5, p4, (1, 0), (0,-1))
if p4 != p3 { segments += (path-util.line-segment((p4, p3)),) }
segments += corner-arc(ne, p3, p2, (0, 1), (1, 0))
if p2 != p1 { segments += (path-util.line-segment((p2, p1)),) }

drawable.path(segments, fill: style.fill, stroke: style.stroke, close: true)
}
Expand Down
25 changes: 15 additions & 10 deletions src/drawable.typ
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,28 @@
(
path-util.cubic-segment(
(x, top, z),
(right, y, z),
(x + m * rx, top, z),
(right, y + m * ry, z),
(left, y, z),
(x - m * rx, top, z),
(left, y + m * ry, z),
),
path-util.cubic-segment(
(right, y, z),
(left, y, z),
(x, bottom, z),
(right, y - m * ry, z),
(x + m * rx, bottom, z),
(left, y - m * ry, z),
(x - m * rx, bottom, z),
),
path-util.cubic-segment(
(x, bottom, z),
(left, y, z),
(x - m * rx, bottom, z),
(left, y - m * ry, z),
(right, y, z),
(x + m * rx, bottom, z),
(right, y - m * ry, z),
),
path-util.cubic-segment(
(right, y, z),
(x, top, z),
(right, y + m * ry, z),
(x + m * rx, top, z)
),
path-util.cubic-segment((left, y, z), (x, top, z), (left, y + m * ry, z), (x - m * rx, top, z)),
),
stroke: stroke,
fill: fill,
Expand Down
Binary file modified tests/projection/ortho/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions tests/projection/ortho/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,32 @@
line((-1,-1), (1,-1), (0,1), close: true)
})
})

// Face order of library shapes
#test-case({
import draw: *
ortho(cull-face: "cw", {
rect((-1, -1), (1, 1), radius: .5)
})
})

#test-case({
import draw: *
ortho(cull-face: "cw", {
circle((0,0))
})
})

#test-case({
import draw: *
ortho(cull-face: "cw", {
arc((0,0), start: 0deg, stop: 270deg, mode: "PIE")
})
})

#test-case({
import draw: *
ortho(cull-face: "cw", {
content((0,0), [Text])
})
})

0 comments on commit e931c83

Please sign in to comment.