File size: 1,826 Bytes
2680bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import pickle, json
import textwrap

def get_motion_data_boundary(motion:np.ndarray):
    '''
    motion: (T, J, 3)
    '''
    xmin = np.min(motion[:, :, 0])
    xmax = np.max(motion[:, :, 0])
    ymin = np.min(motion[:, :, 1])
    ymax = np.max(motion[:, :, 1])
    zmin = np.min(motion[:, :, 2])
    zmax = np.max(motion[:, :, 2])
    return xmin, xmax, ymin, ymax, zmin, zmax


def load_npy(file_path):
    return np.load(file_path)


def save_npy(data, file_path):
    np.save(file_path, data)

def save_json(data, file_path):
    with open(file_path, 'w') as f:
        json.dump(data, f, indent=4)


def load_pkl(file_path):
    with open(file_path, 'rb') as f:
        return pickle.load(f)


def save_pkl(data, file_path):
    with open(file_path, 'wb') as f:
        pickle.dump(data, f)


def load_txt(file_path):
    with open(file_path, 'r', encoding="utf8") as f:
        return f.read()

def load_json(file_path):
    with open(file_path, 'r') as f:
        return json.load(f)

def start_debug():
    import debugpy
    debugpy.listen(
        ('0.0.0.0', 5678)  # Change the port if needed
    )
    print("--- Debugpy is listening on port 5678. Waiting for client to attach... ---")
    debugpy.wait_for_client()
    print("--- Client attached. Continuing execution... ---")

def debug():
    import code
    code.interact(local=locals())

def smart_wrap(text, width=70):
    """智能换行:保留原有段落结构,对每段分别换行"""
    paragraphs = text.split('\n')
    wrapped_paragraphs = []

    for para in paragraphs:
        if para.strip():  # 非空段落
            wrapped = textwrap.fill(para, width=width)
            wrapped_paragraphs.append(wrapped)
        else:  # 空行保留
            wrapped_paragraphs.append('')

    return '\n'.join(wrapped_paragraphs)