"""Region class definition (base class - generic region placeholder)"""
from typing import Any
import os
if os.environ.get('__USE_CUDA', '0') == '1':
import cupy as np
from cupy import ndarray
else:
import numpy as np
from numpy import ndarray
from g3d.defs import G3DEntity
from g3d.defs import FunctionByPass
from g3d.mesh.geo import Coord
[docs]
class Region(G3DEntity):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
def _set_default(self):
super()._set_default()
self._tag = 'g3d_region'
self._center = Coord()
def _set_from_args(self, *args: Any, **kwargs: Any) -> ndarray:
bps = self._get_function_evaluate_status(**kwargs)
if bps is FunctionByPass.SELF:
args_stat = np.ones(len(args))
else:
args_stat = super()._set_from_args(*args)
if bps in [FunctionByPass.EVALUATE, FunctionByPass.SELF]:
if np.sum(args_stat) > 0:
for i in range(len(args)):
if args_stat[i] == 1:
arg = args[i]
if type(arg) is Region:
args_stat[i] = 0
self.copy(arg)
elif type(arg) is Coord:
args_stat[i] = 0
self._center.copy(arg)
return args_stat
[docs]
def set_from_key_value(self, key: str, value: Any) -> bool:
if super().set_from_key_value(key, value):
return True
elif key == 'center':
self._center.copy(value)
return True
elif key == 'xc':
self._center.x = value
return True
elif key == 'yc':
self._center.y = value
return True
elif key == 'zc':
self._center.z = value
return True
return False
[docs]
def copy(self, r: 'Region') -> None:
super().copy(r)
[docs]
def coord_is_in_region(self, c: Coord) -> bool:
"""
:param c:
:return:
"""
return False