def from_config(cls, config, scene=None, tag=None): """Alternate constructor. Args: config (dict): Configuration dictionary Returns: :class:`.Polycurve`: new Polycurve instance """ if tag is None: tag = config.get('tag') region = cls(scene=scene, tag=tag) curves_config = config['curves'] M_start = Point.from_config(curves_config[0]['M1']) region.start(M_start) region.tag = config.get('tag') region.n = config['n'] for curve_config in curves_config: cls = curve_config['Class'] if cls == 'Segment': M_next = Point.from_config(curve_config['M2']) region.add_line(M_next) elif cls == 'Arc': M_next = Point.from_config(curve_config['M2']) tangent = Vector.from_config(curve_config['tangent']) region.add_arc(M_next, tangent) else: raise (NotImplementedError) # normally, the stored polycurves are already closed # (the last point is equal to the first one) # no need for a final close() return region
def from_config(cls, config): """Alternate constructor. Args: config (dict): Configuration dictionary Returns: Line: new Line instance Examples: >>> from geoptics.elements.vector import Point, Vector >>> p = Point(10, 20) >>> u = Vector(30, 60) >>> line1 = Line(p, u) >>> config = line1.config >>> line2 = Line.from_config(config) >>> line2.config == config True """ p = Point.from_config(config['p']) u = Vector.from_config(config['u']) return cls(p, u)