diff --git a/GEMstack/mathutils/transforms.py b/GEMstack/mathutils/transforms.py index a29ec48e2..7a5a7a8dd 100644 --- a/GEMstack/mathutils/transforms.py +++ b/GEMstack/mathutils/transforms.py @@ -72,11 +72,11 @@ def point_segment_distance(x,a,b) -> Tuple[float,float]: udotv = np.dot(u,v) if udotv < 0: return vector_norm(u),0 - elif udotv > vnorm: + elif udotv > vnorm**2: return vector_norm(vector_sub(x,b)),1 else: - param = udotv/vnorm - return vector_norm(vector_sub(u,vector_mul(v,param/vnorm))),param + param = udotv/vnorm**2 + return vector_norm(vector_sub(u,vector_mul(v,param))),param def rotate2d(point, angle : float, origin=None): """Rotates a point about the origin by an angle""" diff --git a/GEMstack/utils/settings.py b/GEMstack/utils/settings.py index b2470ce25..65d1ef467 100644 --- a/GEMstack/utils/settings.py +++ b/GEMstack/utils/settings.py @@ -1,23 +1,33 @@ import json -from ..knowledge import defaults import copy from typing import List,Union,Any SETTINGS = None -def load_settings(): +def load_settings(settings_file : str = None): """Loads the settings object for the first time. - Order of operations is to look into defaults.SETTINGS, and then - look through the command line arguments to determine whether the user has - overridden any settings using --KEY=VALUE. + Order of operations is: + - If settings_file is given, load it. + - Otherwise, get the settings from defaults.SETTINGS + - Look through the command line arguments to determine whether the user has + overridden any settings using --KEY=VALUE. """ global SETTINGS if SETTINGS is not None: return import os import sys - SETTINGS = copy.deepcopy(defaults.SETTINGS) + if settings_file is not None: + from .config import load_config_recursive + import os + print("**************************************************************") + print("Loading global settings from",settings_file) + print("**************************************************************") + SETTINGS = load_config_recursive(os.path.abspath(settings_file)) + else: + from ..knowledge import defaults + SETTINGS = copy.deepcopy(defaults.SETTINGS) for arg in sys.argv: if arg.startswith('--'): k,v = arg.split('=',1) diff --git a/main.py b/main.py index 64d6afadc..a30a833be 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,16 @@ import sys if __name__=='__main__': + #check for settings override + for arg in sys.argv[1:]: + if arg.startswith('--settings='): + settings.load_settings(arg[11:]) + break + #get launch file launch_file = None for arg in sys.argv[1:]: if arg.startswith('--run='): - launch_file = arg[9:] + launch_file = arg[6:] break elif not arg.startswith('--'): launch_file = arg @@ -13,8 +19,8 @@ if launch_file is None: runconfig = settings.get('run',None) if runconfig is None: - print("Usage: python3 [--key1=value1 --key2=value2] LAUNCH_FILE.yaml") - print(" Current settings are found in knowledge/defaults/current.yaml") + print("Usage: python3 [--key1=value1 --key2=value2] [--settings=SETTINGS_OVERRIDE.yaml] LAUNCH_FILE.yaml") + print(" Default settings are found in knowledge/defaults/current.yaml") exit(1) else: print("Using default run configuration in knowledge/defaults/current.yaml")