File size: 2,930 Bytes
ad8cacf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Parameter management for SVG vectorization.

"""

# Default parameters for SVG conversion
DEFAULT_PARAMS = {
    # Color mode settings
    'COLORMODE': 'color',  # 'color' or 'binary'

    # Hierarchy mode settings
    'HIERARCHICAL': 'stacked',  # 'stacked' or 'cutout'

    # Trace mode settings
    'MODE': 'spline',  # 'spline', 'polygon', or 'none'

    # Filter settings
    'FILTER_SPECKLE': 10,  # Noise filter (0-128)
    'COLOR_PRECISION': 6,  # Color precision (1-8)
    'LAYER_DIFFERENCE': 16,  # Gradient steps (0-128)

    # Curve fitting settings
    'CORNER_THRESHOLD': 60,  # Angle threshold (0-180)
    'LENGTH_THRESHOLD': 4.0,  # Segment length (3.5-10)
    'MAX_ITERATIONS': 10,  # Maximum iterations (1-20)
    'SPLICE_THRESHOLD': 45,  # Splice threshold (0-180)
    'PATH_PRECISION': 9,  # Path precision (1-10)
}

def update_params(base_params, new_params):
    """

    Update parameters with new values.



    Args:

        base_params (dict): Base parameter dictionary

        new_params (dict): New parameter values to update

        

    Returns:

        dict: Updated parameter dictionary

    """
    updated_params = base_params.copy()
    for key, value in new_params.items():
        if key in updated_params:
            updated_params[key] = value
            print(f"Parameter updated: {key} = {value}")
        else:
            print(f"Warning: Unknown parameter '{key}' was ignored.")
    return updated_params

def print_params(params):
    """

    Display current parameter settings.

    

    Args:

        params (dict): Parameter dictionary to display

    """
    print("Current parameter settings:")
    for key, value in params.items():
        print(f"  {key}: {value}")

def validate_params(params):
    """

    Validate parameter values.

    

    Args:

        params (dict): Parameters to validate

        

    Returns:

        tuple: (bool, str) - (is_valid, error_message)

    """
    validations = {
        'COLORMODE': lambda x: x in ['color', 'binary'],
        'HIERARCHICAL': lambda x: x in ['stacked', 'cutout'],
        'MODE': lambda x: x in ['spline', 'polygon', 'none'],
        'FILTER_SPECKLE': lambda x: 0 <= x <= 128,
        'COLOR_PRECISION': lambda x: 1 <= x <= 8,
        'LAYER_DIFFERENCE': lambda x: 0 <= x <= 128,
        'CORNER_THRESHOLD': lambda x: 0 <= x <= 180,
        'LENGTH_THRESHOLD': lambda x: 3.5 <= x <= 10,
        'MAX_ITERATIONS': lambda x: 1 <= x <= 20,
        'SPLICE_THRESHOLD': lambda x: 0 <= x <= 180,
        'PATH_PRECISION': lambda x: 1 <= x <= 10
    }
    
    for key, validator in validations.items():
        if key not in params:
            return False, f"Missing parameter: {key}"
        if not validator(params[key]):
            return False, f"Invalid value for {key}: {params[key]}"
    
    return True, "Parameters are valid"