mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Make remove_list_redundancies keep last-most occurance of an element rather than the first occurance
This commit is contained in:
parent
4f322f3137
commit
3f445cb14e
1 changed files with 8 additions and 6 deletions
14
helpers.py
14
helpers.py
|
@ -199,14 +199,16 @@ def bezier(points):
|
||||||
def remove_list_redundancies(l):
|
def remove_list_redundancies(l):
|
||||||
"""
|
"""
|
||||||
Used instead of list(set(l)) to maintain order
|
Used instead of list(set(l)) to maintain order
|
||||||
|
Keeps the last occurance of each element
|
||||||
"""
|
"""
|
||||||
result = []
|
reversed_result = []
|
||||||
used = set()
|
used = set()
|
||||||
for x in l:
|
for x in reversed(l):
|
||||||
if not x in used:
|
if not x in used:
|
||||||
result.append(x)
|
reversed_result.append(x)
|
||||||
used.add(x)
|
used.add(x)
|
||||||
return result
|
reversed_result.reverse()
|
||||||
|
return reversed_result
|
||||||
|
|
||||||
def list_update(l1, l2):
|
def list_update(l1, l2):
|
||||||
"""
|
"""
|
||||||
|
@ -649,8 +651,8 @@ def angle_between_vectors(v1, v2):
|
||||||
return np.arccos(np.dot(v1,v2)/(l1*l2))
|
return np.arccos(np.dot(v1,v2)/(l1*l2))
|
||||||
|
|
||||||
def project_along_vector(point, vector):
|
def project_along_vector(point, vector):
|
||||||
matrix = np.eye(3) - np.outer(vector,vector)
|
matrix = np.identity(3) - np.outer(vector, vector)
|
||||||
return np.dot(point,matrix.T)
|
return np.dot(point, matrix.T)
|
||||||
|
|
||||||
def concatenate_lists(*list_of_lists):
|
def concatenate_lists(*list_of_lists):
|
||||||
return [item for l in list_of_lists for item in l]
|
return [item for l in list_of_lists for item in l]
|
||||||
|
|
Loading…
Add table
Reference in a new issue