manim icon indicating copy to clipboard operation
manim copied to clipboard

Added rotate-label/mob feature to Brace

Open LedMeExplain opened this issue 4 years ago • 2 comments
trafficstars

Changelog / Overview

Added a parameter rotate: bool to Brace.put_at_tip() which allows Mobjects to be rotated in the same direction of the brace. Now you can create a BraceLabel or BraceText and set the parameter label_rotate: bool to automatically rotate or not your label.

Explanation for Changes

Here's a test code I used to create the following images.

IMPORTANT: The new parameter is optional and False by default.

from manim import *

class braceTest(Scene):
    def construct(self):
        poly_1 = RegularPolygon(n = 4, radius = 2)
        poly_2 = RegularPolygon(n = 5, radius = 2)

        group = VGroup(poly_1,poly_2).arrange(buff=2.5)

        self.add(group)

        dir = [RIGHT,UR,UP,UL,LEFT,DL,DOWN,DR]
        rot = True

        for d in dir:
            ## put_at_tip TEST ##
            brace = Brace(poly_1,d)
            square = Square().scale(0.3)
            square.add(Dot(square.get_top(),color = RED))
            brace.put_at_tip(square, rotate = rot)
            self.add(brace,square)

            ## get_tex TEST ##
            # brace = Brace(poly_1,d)
            # lbl = brace.get_tex(r'e^{i\pi}+1', rotate = rot)
            # self.add(brace,lbl)

            ## get_text TEST ##
            # brace = Brace(poly_1,d)
            # lbl = brace.get_text(r'abc', rotate = rot)
            # self.add(brace,lbl)

            ## BraceLabel TEST ##
            # brace = BraceLabel(poly_1,r'\pi\theta', d, label_rotate = rot)
            # self.add(brace)

            ## BraceText TEST ##
            # brace = BraceText(poly_1,r'text', d, label_rotate = rot)
            # self.add(brace)

        p_0 = poly_2.get_points_defining_boundary()[0]
        for p in poly_2.get_points_defining_boundary()[1:]:
            if p_0[0] == p[0] and p_0[1] == p[1]:
                p_0 = p
                continue
            brace = BraceBetweenPoints(p_0,p)
            lbl = brace.get_tex(r'\gamma', rotate = rot)
            self.add(brace,lbl)
            p_0 = p

"Rotated" results

test5 test3 test1 test2 test4

"Not rotated" results

test6 test7

Documentation Reference

Checklist

  • [ ] I have read the Contributing Guidelines
  • [ ] I have written a descriptive PR title (see top of PR template for examples)
  • [ ] I have written a changelog entry for the PR or deem it unnecessary
  • [ ] My new functions/classes either have a docstring or are private
  • [ ] My new functions/classes have tests added and (optional) examples in the docs
  • [ ] My new documentation builds, looks correctly formatted, and adds no additional build warnings

Reviewer Checklist

  • [ ] The PR title is descriptive enough
  • [ ] The PR is labeled correctly
  • [ ] The changelog entry is completed if necessary
  • [ ] Newly added functions/classes either have a docstring or are private
  • [ ] Newly added functions/classes have tests added and (optional) examples in the docs
  • [ ] Newly added documentation builds, looks correctly formatted, and adds no additional build warnings

LedMeExplain avatar Aug 03 '21 22:08 LedMeExplain

If everything goes well with this PR I'll do the docs and examples for all Brace classes

LedMeExplain avatar Aug 04 '21 03:08 LedMeExplain

This is a nice feature, thanks for your contribution! I have tried to resolve the existing merge conflicts, but before we can merge this, tests should be added to check that the functionality of this PR does not break with future updates.

Could you please have a look at our documentation for adding graphical unit tests and add one of your examples (without text, that's important due to default font issues) as a test for this?

behackl avatar Jan 30 '22 16:01 behackl