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

Fill only outside of a circle contour #6

Open
Andrew15-5 opened this issue Oct 23, 2023 · 1 comment
Open

Fill only outside of a circle contour #6

Andrew15-5 opened this issue Oct 23, 2023 · 1 comment

Comments

@Andrew15-5
Copy link

When using x² + y² + op: ">=" + z: 9 + fill: true it fills outside the circle and inside of it (although it works as expected with hyperbola).

cetz-package/cetz#270 (comment):

This is very complicated to solve as of now. Please create a separate ticket for this. Detecting holes is a contour is currently not supported. We could test if a polygon lies insides another polygon. BUT Typst is currently unable to draw paths with holes in them.

code
#import "@local/cetz:0.1.2"

#cetz.canvas({
  import cetz.draw: *
  import cetz.plot
  let get-style(color) = {
    let (r, g, b, ..) = color.to-rgba()
    (line: (stroke: rgb(r, g, b) + 1pt, fill: color.lighten(25%)))
  }
  let x-min = -10
  let x-max = 10
  let y-min = -10
  let y-max = 10
  let width = x-max - x-min
  let height = y-max - y-min
  plot.plot(size: (15, 15), {
    // circle
    plot.add-contour(
      (x, y) => (calc.pow((x - 1), 2) + calc.pow((y - 1), 2)),
      op: ">=",
      z: 9,
      x-domain: (x-min, x-max),
      y-domain: (y-min, y-max),
      x-samples: 50,
      y-samples: 50,
      fill: true,
      style: get-style(rgb("#2D6FB47F")), // blue
    )
  })
})
screenshot

image

This issue was tested against redesign-internals#742d560.

@johannes-wolf
Copy link
Member

Note: This is possible by splitting the fill path in 2 halves, if the inner polygon is completely insides the outer polygon.

@johannes-wolf johannes-wolf transferred this issue from cetz-package/cetz Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants