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

JImage Implementation for J-Objects #399

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f62037
Exported the JImage function from the JImage shorthand
TheCedarPrince Aug 14, 2021
f1e0822
Possible implementation of adding an image easily to JObjects
TheCedarPrince Aug 14, 2021
e1f5cd8
Made argument names less confusing
TheCedarPrince Aug 14, 2021
de8f54f
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince Sep 28, 2021
7ffc1ba
Added scaling capabilities
TheCedarPrince Sep 28, 2021
e908f6d
Added docstring, changed default for shape
TheCedarPrince Oct 5, 2021
da0184c
In process of adding tests for JImage
TheCedarPrince Oct 5, 2021
1ac4713
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince Dec 29, 2021
c891118
Added type signature from Cairo
TheCedarPrince Dec 30, 2021
27620ba
Reference image for JImage
TheCedarPrince Dec 30, 2021
80957f1
Fixed docstrings
TheCedarPrince Dec 30, 2021
6017adc
Revised using dispatch image
TheCedarPrince Dec 30, 2021
10c9686
Merge branch 'master' into tcp-image-jobjects
TheCedarPrince Jan 5, 2022
68a452a
Added TODO for scaling logic
TheCedarPrince Jan 5, 2022
36bbcbd
Temporary disabling of tests
TheCedarPrince Jan 5, 2022
5811f1a
Added TODO for tests, fixed test cases, and fixed references
TheCedarPrince Jan 5, 2022
2debc17
Added individual tests; working on scaling
TheCedarPrince Jan 10, 2022
545268c
Begin adding autoscaling support for JImage
TheCedarPrince Jan 10, 2022
80ca14e
Added image support dispatch for JBox
TheCedarPrince Jan 16, 2022
92f36ca
Added image support dispatch for JPoly
TheCedarPrince Jan 16, 2022
6e91da7
Added image support dispatch for JStar
TheCedarPrince Jan 16, 2022
2c18b27
Added image support dispatch for JRect
TheCedarPrince Jan 17, 2022
d6331a2
Added image support dispatch for JCircle
TheCedarPrince Jan 17, 2022
51dde2c
Added image support dispatch for JEllipse
TheCedarPrince Jan 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/shorthands/JImage.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
function _JImage(pos, img, centering, shapeargs, shape, scaleargs)
if shape != false
if !isnothing(shape)
shape(shapeargs...)
Copy link
Member

@Sov-trotter Sov-trotter Aug 15, 2021

Choose a reason for hiding this comment

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

One minor thing:
I think we should mention(in the docstring) that shape should be a valid Luxor shape(a luxor function).
eg: rect, box, poly etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

"valid Luxor shape" I'm not aware of this concept. :) Do you mean a built-in Luxor function - eg one that constructs paths, or one that generates points for polygons...? (Not trying to be awkward, just I get worried in case I'm not providing the tools you folks need for your cool constructions!)

Copy link
Member

@Sov-trotter Sov-trotter Aug 15, 2021

Choose a reason for hiding this comment

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

Do you mean a built-in Luxor function - eg one that constructs paths

Yeah! We need shape to be a valid luxor function. Since a user may interpret it as entering a full shape name eg: rectangle instead of rect.

Copy link
Member

Choose a reason for hiding this comment

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

We mean any kind of function either their own or more likely a Luxor drawing function. Mostly those which provide the clipping action (so yeah a drawing function 😂)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, yes. Perhaps any function that has an action parameter/keyword...

Copy link
Member

Choose a reason for hiding this comment

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

Another thing I want to mention is that shape should by typed to Method.
eg: If there's a variable circle = Object(...), and user passes circle as an argument, it will throw the Objects of type Javis.Object are not callable error and maybe use a try catch block to give out a better error message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea - error handling is something we need to reckon with @Sov-trotter . I agree with your thoughts and will see what I can do.

end
scale(scaleargs)
Copy link
Member

Choose a reason for hiding this comment

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

I would really like to have automatic scaling by checking the size of the shape and that of the image.
For the shape it would be awesome to be able to call it with :clip / :path automatically but it seems action isn't always a keyword argument which makes that a bit hard. Any idea on that @cormullion ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, following on from my question (#399 (comment)) not all graphic construction functions are similar in having an action keyword. We'd have to compile a list and see which ones could be updated...

Copy link
Member

Choose a reason for hiding this comment

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

Are you interested in standardizing the functions though such that all have an option which provide using the action as a kwarg?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can make a list of possible functions as an issue at Luxor.jl. It might be easy or not, not too sure how many are affected...

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

since this spawned off another issue, shall we resolve this comment @Wikunia and @cormullion ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to close this conversation as I do not think automatic scaling is feasible as all shapes can define a bounding box differently within Luxor.
To find that bounding box for a shape depends on the arguments provided by such a shape.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can find a BoundingBox for a lot of "shapes" using eg pathtopoly():

@draw begin
    circle(O, 100, :stroke)
    circle(O, 100, :path)
    bbox = BoundingBox(pathtopoly()[1])
    box(bbox, :stroke)
end

If you can convert a shape to a polygon, then you can get a bounding box that way. Are there any other shapes in Luxor that you'd like BoundingBox to work on?

placeimage(img, pos, centered = centering)
TheCedarPrince marked this conversation as resolved.
Show resolved Hide resolved
return pos
end

JImage(pos::Point, img, centering = true; shapeargs = (), shape = false, scaleargs = 1) =
"""
JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1)

Place a given image at a given location as a `Javis` object.
Images can be cropped to different shapes and scaled to different sizes while being placed.
TheCedarPrince marked this conversation as resolved.
Show resolved Hide resolved

Returns the position of the image location.
"""
JImage(pos::Point, img, centering = true; shapeargs = (), shape = nothing, scaleargs = 1) =
(
args...;
pos = pos,
Expand Down