Skip to content

Commit

Permalink
fixed the stroke width issue with single color in streamlines (ManimC…
Browse files Browse the repository at this point in the history
…ommunity#3436)

* fixed the stroke width issue with single color in streamlines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added test for streamlines

* Added test for streamlines

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: MrDiver <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 1704374 commit 98a7f42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion manim/mobject/vector_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ def outside_box(p):
step = max(1, int(len(points) / self.max_anchors_per_line))
line.set_points_smoothly(points[::step])
if self.single_color:
line.set_stroke(self.color)
line.set_stroke(
color=self.color, width=self.stroke_width, opacity=opacity
)
else:
if config.renderer == RendererType.OPENGL:
# scaled for compatibility with cairo
Expand Down
15 changes: 15 additions & 0 deletions tests/module/mobject/types/vectorized_mobject/test_stroke.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import manim.utils.color as C
from manim import VMobject
from manim.mobject.vector_field import StreamLines


def test_stroke_props_in_ctor():
Expand All @@ -24,3 +25,17 @@ def test_set_background_stroke():
assert m.background_stroke_width == 2
assert m.background_stroke_opacity == 0.8
assert m.background_stroke_color.to_hex() == C.ORANGE.to_hex()


def test_streamline_attributes_for_single_color():
vector_field = StreamLines(
lambda x: x, # It is not important what this function is.
x_range=[-1, 1, 0.1],
y_range=[-1, 1, 0.1],
padding=0.1,
stroke_width=1.0,
opacity=0.2,
color=C.BLUE_D,
)
assert vector_field[0].stroke_width == 1.0
assert vector_field[0].stroke_opacity == 0.2

0 comments on commit 98a7f42

Please sign in to comment.