-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
93 lines (70 loc) · 2.42 KB
/
utils.py
File metadata and controls
93 lines (70 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import unicodedata
import string
import dash_html_components as html
from hotwing_core.utils import isect_line_plane_v3
from operator import itemgetter
import math
import numpy as np
import os
validFilenameChars = "-_.()%s%s" % (string.ascii_letters, string.digits)
def removeDisallowedFilenameChars(filename):
cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').decode()
clist = []
for c in cleanedFilename:
if not c in validFilenameChars:
c = "_"
clist.append(c)
return ''.join(clist)
def list_to_html(input_list):
result = html.Ul(
[html.Li(s) for s in input_list]
)
return result
def argmin(a):
return min(enumerate(a), key=itemgetter(1))[0]
def argmax(a):
return max(enumerate(a), key=itemgetter(1))[0]
def project_line(x,y,u,v, width, offset):
''' Projects a line between two 3d coordinates onto a surface at "offset" and returns the 3d coordinates of the point where it intersects'''
c1_3d = (0, x, y)
c2_3d = (width, u, v)
p_no = (1, 0, 0)
position = [offset,0,0]
a = isect_line_plane_v3(c1_3d, c2_3d, position, p_no)
return a
def rotate(p, origin=(0, 0), degrees=0):
angle = np.deg2rad(degrees)
R = np.array([[np.cos(angle), -np.sin(angle)],
[np.sin(angle), np.cos(angle)]])
o = np.atleast_2d(origin)
p = np.atleast_2d(p)
return np.squeeze((R @ (p.T-o.T) + o.T).T)
def prep_file_for_saving(input_str):
lines = input_str.split("\n")
result = "\n;".join(lines)
return ";" + result
def parse_uploaded(input_str):
lines = input_str.split("\n")
return "\n".join([l[1:] for l in lines if l.startswith(";") and not l.startswith(";Generated")])
def get_temp_filename(folder):
import tempfile
with tempfile.NamedTemporaryFile(dir=folder, delete=False) as tmpfile:
temp_file_name = tmpfile.name
return temp_file_name
def load_gallery_file():
if not os.path.exists('contrib/gallery.md'):
gallery_file = "gallery_default.md"
else:
gallery_file = "contrib/gallery.md"
with open(gallery_file) as f:
gallery_md = f.read()
return gallery_md
def runs(x_series):
result = [0]
for i,x in enumerate(x_series):
if i > 0:
if abs(x_series[i-1] - x_series[i])< 1e-8:
result.append(result[-1]+1)
else:
result.append(0)
return result