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

Rectangle update #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Mattriks
Copy link
Member

  • I've updated the documentation to reflect these changes
  • I've updated the unit tests
  • I've run the regression tests
  • I've built the docs and confirmed these changes don't cause new errors
  • I've tested Gadfly with this PR (tbd)

This PR:

Rectangles are now PolygonPrimitives, so they will obey Compose transformations:

θ = -π/10
img = compose(context(units=UnitBox(0,0,3,1)), fill(nothing), stroke("blue"),
    (context(), rectangle([0.3,1.3,2.3],[0.4],[0.4],[0.2]), stroke("silver")),
    (context(rotation=Rotation(-π/6,0.5,0.5)), rectangle(0.3,0.4,0.4,0.2)),
    (context(rotation=Rotation(θ,1.5,0.4)), line([(1.0,0.4),(2.0,0.4)]), stroke("black")),
    (context(mirror=Mirror(θ,1.5,0.4)), rectangle(1.3,0.4,0.4,0.2)),
    (context(shear=Shear(1.0,0.0,2.5,0.5)), rectangle(2.3,0.4,0.4,0.2)) 
)

iss133a

@codecov-io
Copy link

codecov-io commented Dec 29, 2018

Codecov Report

Merging #338 into master will increase coverage by 0.34%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #338      +/-   ##
==========================================
+ Coverage   37.13%   37.47%   +0.34%     
==========================================
  Files          18       18              
  Lines        3089     3082       -7     
==========================================
+ Hits         1147     1155       +8     
+ Misses       1942     1927      -15
Impacted Files Coverage Δ
src/cairo_backends.jl 52.81% <ø> (-0.58%) ⬇️
src/pgf_backend.jl 49.78% <ø> (+1.45%) ⬆️
src/svg.jl 67.87% <ø> (-1.18%) ⬇️
src/form.jl 49.76% <83.33%> (+0.46%) ⬆️
src/fontfallback.jl 46.6% <0%> (-0.46%) ⬇️
src/measure.jl 49.16% <0%> (-0.02%) ⬇️
src/Compose.jl 15.11% <0%> (+3.06%) ⬆️
src/misc.jl 61.17% <0%> (+28.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8de6805...8a8a4fa. Read the comment docs.

@bjarthur
Copy link
Member

bjarthur commented Dec 29, 2018

i hesitate to get rid of RectanglePrimitive because both cairo and pgf have rectangle primitives that might be more performant than polygons. is it too hard to support shear transformations for rectangles directly?

also, what about shear transformations for circles, ellipses, lines, curves, etc...

@Mattriks
Copy link
Member Author

There are some potential issues with implementing transformations at backend level:

  • a particular transformation might not exist for some backends
  • a transformation (e.g. rotation) might be context independent at backend level
  • nested transformation may not work (golden_rect.jl is an example of a nested transformation).

Compose avoids all these issues by implementing transformations at Compose level. The following code
shows that this works for most Forms (the exception is ellipse shear, I can do circle shear using ngon).
So rectangle is currently the odd shape out, and transformations of rectangle need to be supported at Compose level.

set_default_graphic_size(6.5inch, 6.5inch)

θ = -π/10
img1 = compose(context(units=UnitBox(0,0,3,1)), fill(nothing), stroke("blue"),
    (context(), circle([0.5,1.5,2.5],[0.5],[0.1]), stroke("silver")),
    (context(rotation=Rotation(-π/6,0.5,0.5)), ngon(0.5,0.5,0.1,30)),
    (context(rotation=Rotation(θ,1.5,0.4)), line([(1.0,0.4),(2.0,0.4)]), stroke("black")),
    (context(mirror=Mirror(θ,1.5,0.4)), circle(1.5,0.5,0.1)),
    (context(shear=Shear(1.0,0.0,2.5,0.5)), ngon(2.5,0.5,0.1,30)) 
)

img2 = compose(context(units=UnitBox(0,0,3,1)), fill(nothing), stroke("blue"),
    (context(), ellipse([0.5,1.5,2.5],[0.5],[0.2],[0.1]), stroke("silver")),
    (context(rotation=Rotation(-π/6,0.5,0.5)), ellipse(0.5,0.5,0.2,0.1)),
    (context(rotation=Rotation(θ,1.5,0.4)), line([(1.0,0.4),(2.0,0.4)]), stroke("black")),
    (context(mirror=Mirror(θ,1.5,0.4)), ellipse(1.5,0.5,0.2,0.1)),
    (context(shear=Shear(1.0,0.0,2.5,0.5)), ellipse(2.5,0.5,0.2,0.1)) 
)

X = [(x,y) for x in (0.5,1.5,2.5), y in (0.5, -0.5, 1.5, 0.5) ]
X[:,1] = [x.+(-0.2, 0.0) for x in X[:,1]]
X[:,4] = [x.+(0.2, 0.0) for x in X[:,4]]

img3 = compose(context(units=UnitBox(0,0,3,1)), fill(nothing), stroke("blue"),
    (context(), curve(X[:,1],X[:,2],X[:,3],X[:,4]), stroke("silver")),
    (context(rotation=Rotation(-π/6,0.5,0.5)), curve(X[1,:]...)),
    (context(rotation=Rotation(θ,1.5,0.4)), line([(1.0,0.4),(2.0,0.4)]), stroke("black")),
    (context(mirror=Mirror(θ,1.5,0.4)), curve(X[2,:]...)),
    (context(shear=Shear(1.0,0.0,2.5,0.5)), curve(X[3,:]...)) 
)
vstack(img1,img2,img3) 

iss133b

@Mattriks
Copy link
Member Author

Ran into errors testing on Gadfly with this PR. Looks like PolygonPrimitives need extra support for DateTime types ...

@bjarthur
Copy link
Member

do PolygonPrimitives work yet with DateTime types?

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.

Rectangles not rotated correctly
3 participants