Skip to content

Add orientation to VMobject, shoelace, ArcPolygon, Tiling, Graph #210

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

Closed
wants to merge 13 commits into from

Conversation

XorUnison
Copy link
Collaborator

@XorUnison XorUnison commented Jul 21, 2020

Added shoelace method to space_ops.py
Added orientation methods to vectorized_mobject.py, uses shoelace
Added ArcPolygon, Tiling and Graph to geometry.py
Added Honeycomb to three_dimensions.py
Added BraceBetweenPoints to brace.py

The code I used for testing the new additions:

class Test1(ZoomedScene):# Orientation
    CONFIG = {
        "zoomed_camera_frame_starting_position": [0,0,0],
        "zoomed_display_corner": [0,0,0],
        "zoomed_display_height": config['frame_height'],
        "zoomed_display_width": config['frame_width'],
        "zoom_factor": 0.5,
    }   
    def construct(self):
        self.activate_zooming(animate=False)
        pol1=RegularPolygon(5)
        pol2=RegularPolygon(5).force_direction("CW")
        pol3=RegularPolygon(5).reverse_direction()
        pol4=RegularPolygon(5).reverse_direction().reverse_direction()
        pol5=RegularPolygon(5).force_direction("CW").reverse_direction()
        self.play(ShowCreation(pol1))
        self.remove(pol1)
        self.play(ShowCreation(pol2))
        self.remove(pol2)
        self.play(ShowCreation(pol3))
        self.remove(pol3)
        self.play(ShowCreation(pol4))
        self.remove(pol4)
        self.play(ShowCreation(pol5))
        self.wait(1)

Test1

class Test2(Scene):# ArcPolygon
    def construct(self):
        r3 = math.sqrt(3)
        arc_config = {"stroke_width":3,"stroke_color":RED,
                      "fill_opacity":0.5,"color": GREEN}
        pol_config = {"stroke_width":10,"stroke_color":BLUE,
                      "fill_opacity":1,"color": PURPLE}
        arc0=ArcBetweenPoints(np.array([-1,0,0]),
                              np.array([1,0,0]),radius=2,**arc_config)
        arc1=ArcBetweenPoints(np.array([1,0,0]),
                              np.array([0,r3,0]),radius=2,**arc_config)
        arc2=ArcBetweenPoints(np.array([0,r3,0]),
                              np.array([-1,0,0]),radius=2,**arc_config)
        reuleaux_triangle=ArcPolygon(arc0,arc1,arc2,**pol_config)
        self.play(Write(reuleaux_triangle))
        self.wait(2)

Test2

class Test3(Scene):# Tiling
    def construct(self):
        test=Tiling(Square(),
                    [[Mobject.shift,[2.1,0,0]]],
                    [[Mobject.shift,[0,2.1,0]]],
                    range(-1,1),
                    range(-1,1))
        self.play(Write(test))
        self.play(FadeOut(test.tile_dictionary[1][-1]))
        self.wait(2)

Test3

class Test4(ZoomedScene):# Graph
    CONFIG = {
        "zoomed_camera_frame_starting_position": [0,0,0],
        "zoomed_display_corner": [0,0,0],
        "zoomed_display_height": config['frame_height'],
        "zoomed_display_width": config['frame_width'],
        "zoom_factor": 0.5,
    }   
    def construct(self):
        self.activate_zooming(animate=False)
        g = {0: [[0,0,0], [1, 2], {"color": BLUE}],
             1: [[1,0,0], [0, 2], {"color": GRAY}],
             2: [[0,1,0], [0, 1], {"color": PINK}]}
        K3 = Graph(g,vertex_config={"radius": 0.2,"fill_opacity": 1},
                   edge_config={"stroke_width": 5,"color": RED})
        K3v = K3.vertices
        K3e = K3.edges
        self.play(ShowCreation(K3e),ShowCreation(K3v))
        self.wait(2)
        self.remove(K3e,K3v)
        
        g = {0: [[0,0,0], [[1,{"angle": 2}], [2,{"color": WHITE}]], {"color": BLUE}],
             1: [[1,0,0], [0, 2], {"color": GRAY}],
             2: [[0,1,0], [0, 1], {"color": PINK}]}
        K3 = Graph(g,vertex_config={"radius": 0.2,"fill_opacity": 1},
                   edge_config={"stroke_width": 5,"color": RED})
        K3v = K3.vertices
        K3e = K3.edges
        self.play(ShowCreation(K3e),ShowCreation(K3v))
        self.wait(2)

Test4

class Test5(Scene):# BraceBetweeenPoints
    def construct(self):
        bbp=BraceBetweeenPoints([-1,0,0],[1,0,0])
        self.play(Write(bbp))
        self.wait(2)

Pretty self-explanatory.

class Test6(ThreeDScene):# Honeycomb
    def construct(self):
        self.set_camera_orientation(0.6, -0.7853981, 86.6)
        self.begin_ambient_camera_rotation()
        
        test=Honeycomb(Cube(stroke_width=5,stroke_color=BLUE,
                            fill_opacity=0.3,fill_color=PURPLE),
                    [[Mobject.shift,[2.1,0,0]]],
                    [[Mobject.shift,[0,2.1,0]]],
                    [[Mobject.shift,[0,0,2.1]]],
                    range(-1,1),
                    range(-1,1),
                    range(-1,1))
        self.play(Write(test))
        self.wait(2)
        self.play(FadeOut(test.cell_dictionary[1][-1][1]))
        self.wait(2)
        self.move_camera(0.8*np.pi/2, -0.45*np.pi)
        self.wait(2)

Test6

Added shoelace method to space_ops.py
Added orientation methods to vectorized_mobject.py, uses shoelace
Added ArcPolygon, Tiling and Graph to geometry.py
@XorUnison XorUnison linked an issue Jul 21, 2020 that may be closed by this pull request
@Aathish04 Aathish04 changed the title Initial Commit Add orientation to Mobject Jul 21, 2020
@XorUnison XorUnison changed the title Add orientation to Mobject Add orientation to VMobject, shoelace, ArcPolygon, Tiling, Graph Jul 22, 2020
@huguesdevimeux
Copy link
Member

huguesdevimeux commented Jul 24, 2020

Could you write a test of this PR ? Refer to the wiki to see the instructions.

And just a request, could you add a visual of your changes ? like an image, or a gif. It would be easier for all of us to see and understand what you did. Thank you in advance !

@XorUnison
Copy link
Collaborator Author

Could you write a test of this PR ? Refer to the wiki to see the instructions.

And just a request, could you add a visual of your changes ? like an image, or a gif. It would be easier for all of us to see and understand what you did. Thank you in advance !

Sure I guess, but I'll have to work myself into the testing architecture. From the looks of it... I have to mostly add scenes to test_geometry.py. Also I just realized I wanted to add another obvious feature, BraceBetweenPoints, so there's that too.

@huguesdevimeux
Copy link
Member

Sure I guess, but I'll have to work myself into the testing architecture. From the looks of it... I have to mostly add scenes to test_geometry.py. Also I just realized I wanted to add another obvious feature, BraceBetweenPoints, so there's that too.

Yes, in theory you only have to touch test_geometry.py.

@XorUnison
Copy link
Collaborator Author

Yes, in theory you only have to touch test_geometry.py.

But I'd wager tests should also test some consistency on applying colors etc... but I see nothing like this in the tests, nor in the wiki. Do we have any policy on that?

@XorUnison
Copy link
Collaborator Author

Alright. BraceBetweenPoints has been added, tests for the 3 new geometry classes have been added, and the OP now contains gifs of the orientation methods and the 3 new geometry classes.

@XorUnison XorUnison added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Jul 26, 2020
Copy link
Member

@Aathish04 Aathish04 left a comment

Choose a reason for hiding this comment

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

I think I'm speaking for @PgBiel here, but I think that it would be extremely useful if you could add numpy style docstrings to the objects and methods that you have added.

Having the detailed breakdown of instantiating each object (like you've done now) is really well done and detailed, but having docstrings for each and every method would be extremely useful when using an IDE.

@XorUnison
Copy link
Collaborator Author

I think I'm speaking for @PgBiel here, but I think that it would be extremely useful if you could add numpy style docstrings to the objects and methods that you have added.

Having the detailed breakdown of instantiating each object (like you've done now) is really well done and detailed, but having docstrings for each and every method would be extremely useful when using an IDE.

Noted. I'll have a look at that. Shouldn't be too hard to add considering it's not that many new objects/methods. And there's not really such a thing as too verbose comments.

@XorUnison
Copy link
Collaborator Author

Alright I've added yet more verbose docstrings, fixed a few formatting issues I made myself and also added Honeycomb, which basically just Tiling in 3D.

There's some beef with the new formatting though, it's not giving me logs, and the local black installation was unwilling to check the files I tried to use it on, instead opting to complain about being unable to import stuff, so if there's something specific you need on the formatting someone else is gonna have to tell me what and how.

@XorUnison
Copy link
Collaborator Author

XorUnison commented Jul 31, 2020

Suggestion: Maybe rename this to GraphTheoryGraph or GraphGT or something like that, because this is most certainly going to be confusing to newcomers.

I've been thinking about this but neither of these seem like great ideas either. I'll probably think about this some more since this isn't gonna get merged today anyway.

Edit: Maybe something like:
EdgeVertexGraph?
VertexGraph?

@huguesdevimeux
Copy link
Member

Suggestion: Maybe rename this to GraphTheoryGraph or GraphGT or something like that, because this is most certainly going to be confusing to newcomers.

I've been thinking about this but neither of these seem like great ideas either. I'll probably think about this some more since this isn't gonna get merged today anyway.

Edit: Maybe something like:
EdgeVertexGraph?
VertexGraph?

EdgeVertex Graph looks good to me.

Pinging Captain Docs @PgBiel to check the docstrings (if he has time, of course)

@Aathish04
Copy link
Member

Aathish04 commented Jul 31, 2020

@XorUnison I ran your branch through black and there were about 10 files that needed reformatting, these were reformatted and that's what my commit is.

There's some beef with the new formatting though, it's not giving me logs, and the local black installation was unwilling to check the files I tried to use it on, instead opting to complain about being unable to import stuff, so if there's something specific you need on the formatting someone else is gonna have to tell me what and how.

@XorUnison
Copy link
Collaborator Author

EdgeVertex Graph looks good to me.

EdgeVertexGraph seems a bit clunky, but it's definitely much clearer than Graph while being less clunky than GraphTheoryGraph. I adjusted it.

@XorUnison I ran your branch through black and there were about 10 files that needed reformatting, these were reformatted and that's what my commit is.

Noted and appreciated, but a bunch of those files weren't even touched by me. Probably jankyness from the switch.

Although I also figured out along with this commit that Black ignores the very first standard outlined in PEP8 and pretends it doesn't exist, opening delimiter alignment, which also made Black instantly die as a serious PEP8 autoformatter in my eyes. Thanks to that it made some changes that are technically still okay within PEP8, but positively hideous ones that aren't really in alignment with the underlying intent of PEP8 either. I mean ignoring the very first standard of PEP8...?
I'm not saying we should dig it up again and look for a better autoformatter but Black? Yeah... wasn't a good choice at all. We dun goofed on that one.

@leotrs
Copy link
Contributor

leotrs commented Aug 15, 2020

What's the status of this PR? Can we get an update please? :) I believe I saw some discussion about this on Discord.

@XorUnison
Copy link
Collaborator Author

XorUnison commented Aug 15, 2020

What's the status of this PR? Can we get an update please? :) I believe I saw some discussion about this on Discord.

Still working through all the requested changes. The only one that's currently left is a suggestion by EulerTour on how to handle the functions applied to the tiles. His suggestion is a bit more complicated for the simplest scenarios, but it is more flexible and pythonic in total, and also deals better with more complicated scenarios. So I aim to digest it and switch up the way Tiling works again, since it's supposed to be as good as possible upon merging after all. Once that's done I have to fix all the conflicts piling up and then it'll be ready for review again.

Copy link
Member

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

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

see the docs guidelines in the wiki for more info


Parameters
----------
*arcs : Arc or ArcBetweenPoints
Copy link
Member

Choose a reason for hiding this comment

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

doc fixes

Suggested change
*arcs : Arc or ArcBetweenPoints
arcs : Union[:class:`Arc`, :class:`ArcBetweenPoints`]


Example
-------
ArcPolygon(arc0,arc1,arc2,arcN,**kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

so that sphinx displays it properly

Suggested change
ArcPolygon(arc0,arc1,arc2,arcN,**kwargs)
::
ArcPolygon(arc0,arc1,arc2,arcN,**kwargs)

Comment on lines 763 to 767
ArcPolygon also doubles as a group for the input arcs.
That means these arcs can be drawn and seen separately.
If only the ArcPolygon itself is supposed to be visible,
make the arcs invisible (for example with "stroke_width": 0).
ArcPolygon.arcs can be used get values from these subarcs.
Copy link
Member

Choose a reason for hiding this comment

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

this shouldn't be under Examples but in description itself

class ArcPolygon(VMobject):
"""
The ArcPolygon is what it says, a polygon, but made from arcs.
More versatile than the standard Polygon.
Copy link
Member

Choose a reason for hiding this comment

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

just so it links to the class for quick access

Suggested change
More versatile than the standard Polygon.
More versatile than the standard :class:`Polygon`.

"""
This method computes and applies the offsets for the tiles,
in the given dimension.
multiplies inputs, which requires arrays to be numpy arrays.
Copy link
Member

Choose a reason for hiding this comment

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

docs of parameters

Comment on lines 881 to 884
The tile prototype can be any Mobject (also groups) or a function.
The function format is function(x,y), returning a Mobject.
Using groups or functions allows the tiling to contain multiple
different tiles or to simplify the following offset functions.
Copy link
Member

Choose a reason for hiding this comment

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

should be moved to tile_prototype short desc

Comment on lines 886 to 889
Next are two nested lists that determine how the tiles are arranged.
The functions are typically Mobject.shift and Mobject.rotate.
Each list has to contain sublists with Function/Value pairs.
More on this in the Examples section.
Copy link
Member

Choose a reason for hiding this comment

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

should be moved to the offset short descs

Comment on lines 891 to 892
Last are two ranges: If both ranges are range(-1,1,1),
that would result in a square grid of 9 tiles.
Copy link
Member

Choose a reason for hiding this comment

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

should be moved to range short descs

@huguesdevimeux huguesdevimeux marked this pull request as draft August 27, 2020 21:37
Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com>
XorUnison and others added 3 commits September 4, 2020 12:51
Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com>
The final edits before the changes in here are spread into multiple new and fresh PRs
@leotrs
Copy link
Contributor

leotrs commented Oct 8, 2020

Hi @XorUnison do you have any updates on this branch? :)

@leotrs
Copy link
Contributor

leotrs commented Oct 25, 2020

There hasn't been any movement here for over two months, and by now it will be highly non-trivial to deal with the merge conflicts here. I vote we close this :(

XorUnison and others added 3 commits October 30, 2020 00:47
Committing suggestions to use in new branch

Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com>
Committing suggestions to use in new branch

Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com>
Committing suggestions to use in new branch

Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding orientation to Mobject
7 participants