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

Size units (sx, sy) #409

Merged
merged 2 commits into from
Jan 4, 2021
Merged

Conversation

Mattriks
Copy link
Member

@Mattriks Mattriks commented Jan 3, 2021

  • I've built the docs and confirmed these changes don't cause new errors
  • I've added and/or updated the unit tests
  • I've run the regression tests

This PR:

  • Introduces sx, sy units which are essentially "relative context units" e.g. 20cy + 1sx makes sense
    even when the context origin point is not (0cx, 0cy)
  • sx, sy units are user friendly (users don't need to know Compose's resolve functions)
  • Fixes ngon, star and xgon (fixes ngon and xgon are transformed incorrectly in UnitBox? #406)
  • In the future, other forms in Compose may be simplified by using sx, sy units

Example

In this example, the polygon is sized in both sx and sy units

polyf(x, y, s::Compose.Length) = [(x*cx, y*cy-s), (x*cx+s, y*cy), (x*cx, y*cy+s), (x*cx-s, y*cy), (x*cx, y*cy-s)]

gridf(xs, ys, args...) = (context(),
     line([[(x, 0h), (x, 1h)] for x in xs]), line([[(0w, y), (1w, y)] for y in ys]), args..., linewidth(0.1mm))

using Random
 x, y = [-8; -4:2:4; 8], [-2.5, -2.5, 2.5, -1, 1,-2.5,2]
gx, gy = -10:10, -5:5
rainbow = ["darkviolet","indigo","blue","green","yellow","orange","red"]

img = compose(context(units = UnitBox(-10., -3, 20, 6)), 
    gridf(gx, gy, stroke("gray")),  fill("transparent"),
    (context(), polygon(polyf.(x, y, 0.5sx)), stroke(shuffle(rainbow))),
    (context(), polygon(polyf.(x, y, 0.5sy)), stroke(shuffle(rainbow)))    
)

size_xy_units

@Mattriks
Copy link
Member Author

Mattriks commented Jan 4, 2021

I'll merge this if there are no comments.

docs/src/tutorial.md Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

ngon and xgon are transformed incorrectly in UnitBox?
2 participants