idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
36,300 | def process_template ( file_src ) : def tmpl_sqrt ( x ) : return math . sqrt ( x ) def tmpl_cubert ( x ) : return x ** ( 1.0 / 3.0 ) if x >= 0 else - ( - x ) ** ( 1.0 / 3.0 ) def tmpl_pow ( x , y ) : return math . pow ( x , y ) try : import jinja2 except ImportError : raise GeomdlException ( "Please install 'jinja2' pa... | Process Jinja2 template input |
36,301 | def import_surf_mesh ( file_name ) : raw_content = read_file ( file_name ) raw_content = raw_content . split ( "\n" ) content = [ ] for rc in raw_content : temp = rc . strip ( ) . split ( ) content . append ( temp ) if int ( content [ 0 ] [ 0 ] ) != 3 : raise TypeError ( "Input mesh '" + str ( file_name ) + "' must be ... | Generates a NURBS surface object from a mesh file . |
36,302 | def import_vol_mesh ( file_name ) : raw_content = read_file ( file_name ) raw_content = raw_content . split ( "\n" ) content = [ ] for rc in raw_content : temp = rc . strip ( ) . split ( ) content . append ( temp ) if int ( content [ 0 ] [ 0 ] ) != 3 : raise TypeError ( "Input mesh '" + str ( file_name ) + "' must be 3... | Generates a NURBS volume object from a mesh file . |
36,303 | def import_txt ( file_name , two_dimensional = False , ** kwargs ) : content = exch . read_file ( file_name ) j2tmpl = kwargs . get ( 'jinja2' , False ) if j2tmpl : content = exch . process_template ( content ) col_sep = kwargs . get ( 'col_separator' , ";" ) sep = kwargs . get ( 'separator' , "," ) return exch . impor... | Reads control points from a text file and generates a 1 - dimensional list of control points . |
36,304 | def export_txt ( obj , file_name , two_dimensional = False , ** kwargs ) : if obj . ctrlpts is None or len ( obj . ctrlpts ) == 0 : raise exch . GeomdlException ( "There are no control points to save!" ) if obj . pdimension == 1 and two_dimensional : two_dimensional = False col_sep = kwargs . get ( 'col_separator' , ";... | Exports control points as a text file . |
36,305 | def import_csv ( file_name , ** kwargs ) : sep = kwargs . get ( 'separator' , "," ) content = exch . read_file ( file_name , skip_lines = 1 ) return exch . import_text_data ( content , sep ) | Reads control points from a CSV file and generates a 1 - dimensional list of control points . |
36,306 | def export_csv ( obj , file_name , point_type = 'evalpts' , ** kwargs ) : if not 0 < obj . pdimension < 3 : raise exch . GeomdlException ( "Input object should be a curve or a surface" ) if point_type == 'ctrlpts' : points = obj . ctrlptsw if obj . rational else obj . ctrlpts elif point_type == 'evalpts' : points = obj... | Exports control points or evaluated points as a CSV file . |
36,307 | def import_cfg ( file_name , ** kwargs ) : def callback ( data ) : return libconf . loads ( data ) try : import libconf except ImportError : raise exch . GeomdlException ( "Please install 'libconf' package to use libconfig format: pip install libconf" ) delta = kwargs . get ( 'delta' , - 1.0 ) use_template = kwargs . g... | Imports curves and surfaces from files in libconfig format . |
36,308 | def export_cfg ( obj , file_name ) : def callback ( data ) : return libconf . dumps ( data ) try : import libconf except ImportError : raise exch . GeomdlException ( "Please install 'libconf' package to use libconfig format: pip install libconf" ) exported_data = exch . export_dict_str ( obj = obj , callback = callback... | Exports curves and surfaces in libconfig format . |
36,309 | def import_yaml ( file_name , ** kwargs ) : def callback ( data ) : yaml = YAML ( ) return yaml . load ( data ) try : from ruamel . yaml import YAML except ImportError : raise exch . GeomdlException ( "Please install 'ruamel.yaml' package to use YAML format: pip install ruamel.yaml" ) delta = kwargs . get ( 'delta' , -... | Imports curves and surfaces from files in YAML format . |
36,310 | def export_yaml ( obj , file_name ) : def callback ( data ) : stream = StringIO ( ) yaml = YAML ( ) yaml . dump ( data , stream ) return stream . getvalue ( ) try : from ruamel . yaml import YAML except ImportError : raise exch . GeomdlException ( "Please install 'ruamel.yaml' package to use YAML format: pip install ru... | Exports curves and surfaces in YAML format . |
36,311 | def import_json ( file_name , ** kwargs ) : def callback ( data ) : return json . loads ( data ) delta = kwargs . get ( 'delta' , - 1.0 ) use_template = kwargs . get ( 'jinja2' , False ) file_src = exch . read_file ( file_name ) return exch . import_dict_str ( file_src = file_src , delta = delta , callback = callback ,... | Imports curves and surfaces from files in JSON format . |
36,312 | def export_json ( obj , file_name ) : def callback ( data ) : return json . dumps ( data , indent = 4 ) exported_data = exch . export_dict_str ( obj = obj , callback = callback ) return exch . write_file ( file_name , exported_data ) | Exports curves and surfaces in JSON format . |
36,313 | def import_obj ( file_name , ** kwargs ) : def default_callback ( face_list ) : return face_list callback_func = kwargs . get ( 'callback' , default_callback ) content = exch . read_file ( file_name ) content_arr = content . split ( "\n" ) on_face = False vertices = [ ] triangles = [ ] faces = [ ] vert_idx = 1 tri_idx ... | Reads . obj files and generates faces . |
36,314 | def select_color ( cpcolor , evalcolor , idx = 0 ) : color = utilities . color_generator ( ) if isinstance ( cpcolor , str ) : color [ 0 ] = cpcolor if isinstance ( cpcolor , ( list , tuple ) ) : color [ 0 ] = cpcolor [ idx ] if isinstance ( evalcolor , str ) : color [ 1 ] = evalcolor if isinstance ( evalcolor , ( list... | Selects item color for plotting . |
36,315 | def process_tessellate ( elem , update_delta , delta , ** kwargs ) : if update_delta : elem . delta = delta elem . evaluate ( ) elem . tessellate ( ** kwargs ) return elem | Tessellates surfaces . |
36,316 | def process_elements_surface ( elem , mconf , colorval , idx , force_tsl , update_delta , delta , reset_names ) : if idx < 0 : lock . acquire ( ) idx = counter . value counter . value += 1 lock . release ( ) if update_delta : elem . delta = delta elem . evaluate ( ) if reset_names : elem . name = "surface" if elem . na... | Processes visualization elements for surfaces . |
36,317 | def find_span_binsearch ( degree , knot_vector , num_ctrlpts , knot , ** kwargs ) : tol = kwargs . get ( 'tol' , 10e-6 ) n = num_ctrlpts - 1 if abs ( knot_vector [ n + 1 ] - knot ) <= tol : return n low = degree high = num_ctrlpts mid = ( low + high ) / 2 mid = int ( round ( mid + tol ) ) while ( knot < knot_vector [ m... | Finds the span of the knot over the input knot vector using binary search . |
36,318 | def find_span_linear ( degree , knot_vector , num_ctrlpts , knot , ** kwargs ) : span = 0 while span < num_ctrlpts and knot_vector [ span ] <= knot : span += 1 return span - 1 | Finds the span of a single knot over the knot vector using linear search . |
36,319 | def find_spans ( degree , knot_vector , num_ctrlpts , knots , func = find_span_linear ) : spans = [ ] for knot in knots : spans . append ( func ( degree , knot_vector , num_ctrlpts , knot ) ) return spans | Finds spans of a list of knots over the knot vector . |
36,320 | def find_multiplicity ( knot , knot_vector , ** kwargs ) : tol = kwargs . get ( 'tol' , 10e-8 ) mult = 0 for kv in knot_vector : if abs ( knot - kv ) <= tol : mult += 1 return mult | Finds knot multiplicity over the knot vector . |
36,321 | def basis_function ( degree , knot_vector , span , knot ) : left = [ 0.0 for _ in range ( degree + 1 ) ] right = [ 0.0 for _ in range ( degree + 1 ) ] N = [ 1.0 for _ in range ( degree + 1 ) ] for j in range ( 1 , degree + 1 ) : left [ j ] = knot - knot_vector [ span + 1 - j ] right [ j ] = knot_vector [ span + j ] - k... | Computes the non - vanishing basis functions for a single parameter . |
36,322 | def basis_functions ( degree , knot_vector , spans , knots ) : basis = [ ] for span , knot in zip ( spans , knots ) : basis . append ( basis_function ( degree , knot_vector , span , knot ) ) return basis | Computes the non - vanishing basis functions for a list of parameters . |
36,323 | def basis_function_all ( degree , knot_vector , span , knot ) : N = [ [ None for _ in range ( degree + 1 ) ] for _ in range ( degree + 1 ) ] for i in range ( 0 , degree + 1 ) : bfuns = basis_function ( i , knot_vector , span , knot ) for j in range ( 0 , i + 1 ) : N [ j ] [ i ] = bfuns [ j ] return N | Computes all non - zero basis functions of all degrees from 0 up to the input degree for a single parameter . |
36,324 | def basis_functions_ders ( degree , knot_vector , spans , knots , order ) : basis_ders = [ ] for span , knot in zip ( spans , knots ) : basis_ders . append ( basis_function_ders ( degree , knot_vector , span , knot , order ) ) return basis_ders | Computes derivatives of the basis functions for a list of parameters . |
36,325 | def basis_function_one ( degree , knot_vector , span , knot ) : if ( span == 0 and knot == knot_vector [ 0 ] ) or ( span == len ( knot_vector ) - degree - 2 ) and knot == knot_vector [ len ( knot_vector ) - 1 ] : return 1.0 if knot < knot_vector [ span ] or knot >= knot_vector [ span + degree + 1 ] : return 0.0 N = [ 0... | Computes the value of a basis function for a single parameter . |
36,326 | def set_axes_equal ( ax ) : bounds = [ ax . get_xlim3d ( ) , ax . get_ylim3d ( ) , ax . get_zlim3d ( ) ] ranges = [ abs ( bound [ 1 ] - bound [ 0 ] ) for bound in bounds ] centers = [ np . mean ( bound ) for bound in bounds ] radius = 0.5 * max ( ranges ) lower_limits = centers - radius upper_limits = centers + radius ... | Sets equal aspect ratio across the three axes of a 3D plot . |
36,327 | def animate ( self , ** kwargs ) : super ( VisSurface , self ) . render ( ** kwargs ) surf_cmaps = kwargs . get ( 'colormap' , None ) tri_idxs = [ ] vert_coords = [ ] trisurf_params = [ ] frames = [ ] frames_tris = [ ] num_vertices = 0 fig = plt . figure ( figsize = self . vconf . figure_size , dpi = self . vconf . fig... | Animates the surface . |
36,328 | def tangent_curve_single_list ( obj , param_list , normalize ) : ret_vector = [ ] for param in param_list : temp = tangent_curve_single ( obj , param , normalize ) ret_vector . append ( temp ) return tuple ( ret_vector ) | Evaluates the curve tangent vectors at the given list of parameter values . |
36,329 | def normal_curve_single ( obj , u , normalize ) : ders = obj . derivatives ( u , 2 ) point = ders [ 0 ] vector = linalg . vector_normalize ( ders [ 2 ] ) if normalize else ders [ 2 ] return tuple ( point ) , tuple ( vector ) | Evaluates the curve normal vector at the input parameter u . |
36,330 | def normal_curve_single_list ( obj , param_list , normalize ) : ret_vector = [ ] for param in param_list : temp = normal_curve_single ( obj , param , normalize ) ret_vector . append ( temp ) return tuple ( ret_vector ) | Evaluates the curve normal vectors at the given list of parameter values . |
36,331 | def binormal_curve_single ( obj , u , normalize ) : tan_vector = tangent_curve_single ( obj , u , normalize ) norm_vector = normal_curve_single ( obj , u , normalize ) point = tan_vector [ 0 ] vector = linalg . vector_cross ( tan_vector [ 1 ] , norm_vector [ 1 ] ) vector = linalg . vector_normalize ( vector ) if normal... | Evaluates the curve binormal vector at the given u parameter . |
36,332 | def binormal_curve_single_list ( obj , param_list , normalize ) : ret_vector = [ ] for param in param_list : temp = binormal_curve_single ( obj , param , normalize ) ret_vector . append ( temp ) return tuple ( ret_vector ) | Evaluates the curve binormal vectors at the given list of parameter values . |
36,333 | def tangent_surface_single_list ( obj , param_list , normalize ) : ret_vector = [ ] for param in param_list : temp = tangent_surface_single ( obj , param , normalize ) ret_vector . append ( temp ) return tuple ( ret_vector ) | Evaluates the surface tangent vectors at the given list of parameter values . |
36,334 | def normal_surface_single_list ( obj , param_list , normalize ) : ret_vector = [ ] for param in param_list : temp = normal_surface_single ( obj , param , normalize ) ret_vector . append ( temp ) return tuple ( ret_vector ) | Evaluates the surface normal vectors at the given list of parameter values . |
36,335 | def find_ctrlpts_curve ( t , curve , ** kwargs ) : span_func = kwargs . get ( 'find_span_func' , helpers . find_span_linear ) span = span_func ( curve . degree , curve . knotvector , len ( curve . ctrlpts ) , t ) idx = span - curve . degree curve_ctrlpts = [ ( ) for _ in range ( curve . degree + 1 ) ] for i in range ( ... | Finds the control points involved in the evaluation of the curve point defined by the input parameter . |
36,336 | def find_ctrlpts_surface ( t_u , t_v , surf , ** kwargs ) : span_func = kwargs . get ( 'find_span_func' , helpers . find_span_linear ) span_u = span_func ( surf . degree_u , surf . knotvector_u , surf . ctrlpts_size_u , t_u ) span_v = span_func ( surf . degree_v , surf . knotvector_v , surf . ctrlpts_size_v , t_v ) idx... | Finds the control points involved in the evaluation of the surface point defined by the input parameter pair . |
36,337 | def link_curves ( * args , ** kwargs ) : tol = kwargs . get ( 'tol' , 10e-8 ) validate = kwargs . get ( 'validate' , False ) if validate : for idx in range ( len ( args ) - 1 ) : if linalg . point_distance ( args [ idx ] . ctrlpts [ - 1 ] , args [ idx + 1 ] . ctrlpts [ 0 ] ) > tol : raise GeomdlException ( "Curve #" + ... | Links the input curves together . |
36,338 | def add_dimension ( obj , ** kwargs ) : if not isinstance ( obj , abstract . SplineGeometry ) : raise GeomdlException ( "Can only operate on spline geometry objects" ) inplace = kwargs . get ( 'inplace' , False ) array_init = kwargs . get ( 'array_init' , [ [ ] for _ in range ( len ( obj . ctrlpts ) ) ] ) offset_value ... | Elevates the spatial dimension of the spline geometry . |
36,339 | def split_curve ( obj , param , ** kwargs ) : if not isinstance ( obj , abstract . Curve ) : raise GeomdlException ( "Input shape must be an instance of abstract.Curve class" ) if param == obj . knotvector [ 0 ] or param == obj . knotvector [ - 1 ] : raise GeomdlException ( "Cannot split on the corner points" ) span_fu... | Splits the curve at the input parametric coordinate . |
36,340 | def decompose_curve ( obj , ** kwargs ) : if not isinstance ( obj , abstract . Curve ) : raise GeomdlException ( "Input shape must be an instance of abstract.Curve class" ) multi_curve = [ ] curve = copy . deepcopy ( obj ) knots = curve . knotvector [ curve . degree + 1 : - ( curve . degree + 1 ) ] while knots : knot =... | Decomposes the curve into Bezier curve segments of the same degree . |
36,341 | def length_curve ( obj ) : if not isinstance ( obj , abstract . Curve ) : raise GeomdlException ( "Input shape must be an instance of abstract.Curve class" ) length = 0.0 evalpts = obj . evalpts num_evalpts = len ( obj . evalpts ) for idx in range ( num_evalpts - 1 ) : length += linalg . point_distance ( evalpts [ idx ... | Computes the approximate length of the parametric curve . |
36,342 | def split_surface_u ( obj , param , ** kwargs ) : if not isinstance ( obj , abstract . Surface ) : raise GeomdlException ( "Input shape must be an instance of abstract.Surface class" ) if param == obj . knotvector_u [ 0 ] or param == obj . knotvector_u [ - 1 ] : raise GeomdlException ( "Cannot split on the edge" ) span... | Splits the surface at the input parametric coordinate on the u - direction . |
36,343 | def decompose_surface ( obj , ** kwargs ) : def decompose ( srf , idx , split_func_list , ** kws ) : srf_list = [ ] knots = srf . knotvector [ idx ] [ srf . degree [ idx ] + 1 : - ( srf . degree [ idx ] + 1 ) ] while knots : knot = knots [ 0 ] srfs = split_func_list [ idx ] ( srf , param = knot , ** kws ) srf_list . ap... | Decomposes the surface into Bezier surface patches of the same degree . |
36,344 | def tangent ( obj , params , ** kwargs ) : normalize = kwargs . get ( 'normalize' , True ) if isinstance ( obj , abstract . Curve ) : if isinstance ( params , ( list , tuple ) ) : return ops . tangent_curve_single_list ( obj , params , normalize ) else : return ops . tangent_curve_single ( obj , params , normalize ) if... | Evaluates the tangent vector of the curves or surfaces at the input parameter values . |
36,345 | def normal ( obj , params , ** kwargs ) : normalize = kwargs . get ( 'normalize' , True ) if isinstance ( obj , abstract . Curve ) : if isinstance ( params , ( list , tuple ) ) : return ops . normal_curve_single_list ( obj , params , normalize ) else : return ops . normal_curve_single ( obj , params , normalize ) if is... | Evaluates the normal vector of the curves or surfaces at the input parameter values . |
36,346 | def binormal ( obj , params , ** kwargs ) : normalize = kwargs . get ( 'normalize' , True ) if isinstance ( obj , abstract . Curve ) : if isinstance ( params , ( list , tuple ) ) : return ops . binormal_curve_single_list ( obj , params , normalize ) else : return ops . binormal_curve_single ( obj , params , normalize )... | Evaluates the binormal vector of the curves or surfaces at the input parameter values . |
36,347 | def translate ( obj , vec , ** kwargs ) : if not vec or not isinstance ( vec , ( tuple , list ) ) : raise GeomdlException ( "The input must be a list or a tuple" ) if len ( vec ) != obj . dimension : raise GeomdlException ( "The input vector must have " + str ( obj . dimension ) + " components" ) inplace = kwargs . get... | Translates curves surface or volumes by the input vector . |
36,348 | def scale ( obj , multiplier , ** kwargs ) : if not isinstance ( multiplier , ( int , float ) ) : raise GeomdlException ( "The multiplier must be a float or an integer" ) inplace = kwargs . get ( 'inplace' , False ) if not inplace : geom = copy . deepcopy ( obj ) else : geom = obj for g in geom : new_ctrlpts = [ [ ] fo... | Scales curves surfaces or volumes by the input multiplier . |
36,349 | def voxelize ( obj , ** kwargs ) : grid_size = kwargs . pop ( 'grid_size' , ( 8 , 8 , 8 ) ) use_cubes = kwargs . pop ( 'use_cubes' , False ) num_procs = kwargs . get ( 'num_procs' , 1 ) if not isinstance ( grid_size , ( list , tuple ) ) : raise TypeError ( "Grid size must be a list or a tuple of integers" ) grid = [ ] ... | Generates binary voxel representation of the surfaces and volumes . |
36,350 | def convert_bb_to_faces ( voxel_grid ) : new_vg = [ ] for v in voxel_grid : p1 = v [ 0 ] p2 = [ v [ 1 ] [ 0 ] , v [ 0 ] [ 1 ] , v [ 0 ] [ 2 ] ] p3 = [ v [ 1 ] [ 0 ] , v [ 1 ] [ 1 ] , v [ 0 ] [ 2 ] ] p4 = [ v [ 0 ] [ 0 ] , v [ 1 ] [ 1 ] , v [ 0 ] [ 2 ] ] p5 = [ v [ 0 ] [ 0 ] , v [ 0 ] [ 1 ] , v [ 1 ] [ 2 ] ] p6 = [ v [ ... | Converts a voxel grid defined by min and max coordinates to a voxel grid defined by faces . |
36,351 | def save_voxel_grid ( voxel_grid , file_name ) : try : with open ( file_name , 'wb' ) as fp : for voxel in voxel_grid : fp . write ( struct . pack ( "<I" , voxel ) ) except IOError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise e except Exception : raise | Saves binary voxel grid as a binary file . |
36,352 | def vector_cross ( vector1 , vector2 ) : try : if vector1 is None or len ( vector1 ) == 0 or vector2 is None or len ( vector2 ) == 0 : raise ValueError ( "Input vectors cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Input must be a list or t... | Computes the cross - product of the input vectors . |
36,353 | def vector_dot ( vector1 , vector2 ) : try : if vector1 is None or len ( vector1 ) == 0 or vector2 is None or len ( vector2 ) == 0 : raise ValueError ( "Input vectors cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Input must be a list or tup... | Computes the dot - product of the input vectors . |
36,354 | def vector_sum ( vector1 , vector2 , coeff = 1.0 ) : summed_vector = [ v1 + ( coeff * v2 ) for v1 , v2 in zip ( vector1 , vector2 ) ] return summed_vector | Sums the vectors . |
36,355 | def vector_normalize ( vector_in , decimals = 18 ) : try : if vector_in is None or len ( vector_in ) == 0 : raise ValueError ( "Input vector cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Input must be a list or tuple" ) except Exception : r... | Generates a unit vector from the input . |
36,356 | def vector_generate ( start_pt , end_pt , normalize = False ) : try : if start_pt is None or len ( start_pt ) == 0 or end_pt is None or len ( end_pt ) == 0 : raise ValueError ( "Input points cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Inp... | Generates a vector from 2 input points . |
36,357 | def vector_magnitude ( vector_in ) : sq_sum = 0.0 for vin in vector_in : sq_sum += vin ** 2 return math . sqrt ( sq_sum ) | Computes the magnitude of the input vector . |
36,358 | def vector_angle_between ( vector1 , vector2 , ** kwargs ) : degrees = kwargs . get ( 'degrees' , True ) magn1 = vector_magnitude ( vector1 ) magn2 = vector_magnitude ( vector2 ) acos_val = vector_dot ( vector1 , vector2 ) / ( magn1 * magn2 ) angle_radians = math . acos ( acos_val ) if degrees : return math . degrees (... | Computes the angle between the two input vectors . |
36,359 | def vector_is_zero ( vector_in , tol = 10e-8 ) : if not isinstance ( vector_in , ( list , tuple ) ) : raise TypeError ( "Input vector must be a list or a tuple" ) res = [ False for _ in range ( len ( vector_in ) ) ] for idx in range ( len ( vector_in ) ) : if abs ( vector_in [ idx ] ) < tol : res [ idx ] = True return ... | Checks if the input vector is a zero vector . |
36,360 | def point_translate ( point_in , vector_in ) : try : if point_in is None or len ( point_in ) == 0 or vector_in is None or len ( vector_in ) == 0 : raise ValueError ( "Input arguments cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Input must ... | Translates the input points using the input vector . |
36,361 | def point_distance ( pt1 , pt2 ) : if len ( pt1 ) != len ( pt2 ) : raise ValueError ( "The input points should have the same dimension" ) dist_vector = vector_generate ( pt1 , pt2 , normalize = False ) distance = vector_magnitude ( dist_vector ) return distance | Computes distance between two points . |
36,362 | def point_mid ( pt1 , pt2 ) : if len ( pt1 ) != len ( pt2 ) : raise ValueError ( "The input points should have the same dimension" ) dist_vector = vector_generate ( pt1 , pt2 , normalize = False ) half_dist_vector = vector_multiply ( dist_vector , 0.5 ) return point_translate ( pt1 , half_dist_vector ) | Computes the midpoint of the input points . |
36,363 | def matrix_transpose ( m ) : num_cols = len ( m ) num_rows = len ( m [ 0 ] ) m_t = [ ] for i in range ( num_rows ) : temp = [ ] for j in range ( num_cols ) : temp . append ( m [ j ] [ i ] ) m_t . append ( temp ) return m_t | Transposes the input matrix . |
36,364 | def triangle_center ( tri , uv = False ) : if uv : data = [ t . uv for t in tri ] mid = [ 0.0 , 0.0 ] else : data = tri . vertices mid = [ 0.0 , 0.0 , 0.0 ] for vert in data : mid = [ m + v for m , v in zip ( mid , vert ) ] mid = [ float ( m ) / 3.0 for m in mid ] return tuple ( mid ) | Computes the center of mass of the input triangle . |
36,365 | def lu_decomposition ( matrix_a ) : q = len ( matrix_a ) for idx , m_a in enumerate ( matrix_a ) : if len ( m_a ) != q : raise ValueError ( "The input must be a square matrix. " + "Row " + str ( idx + 1 ) + " has a size of " + str ( len ( m_a ) ) + "." ) return _linalg . doolittle ( matrix_a ) | LU - Factorization method using Doolittle s Method for solution of linear systems . |
36,366 | def forward_substitution ( matrix_l , matrix_b ) : q = len ( matrix_b ) matrix_y = [ 0.0 for _ in range ( q ) ] matrix_y [ 0 ] = float ( matrix_b [ 0 ] ) / float ( matrix_l [ 0 ] [ 0 ] ) for i in range ( 1 , q ) : matrix_y [ i ] = float ( matrix_b [ i ] ) - sum ( [ matrix_l [ i ] [ j ] * matrix_y [ j ] for j in range (... | Forward substitution method for the solution of linear systems . |
36,367 | def backward_substitution ( matrix_u , matrix_y ) : q = len ( matrix_y ) matrix_x = [ 0.0 for _ in range ( q ) ] matrix_x [ q - 1 ] = float ( matrix_y [ q - 1 ] ) / float ( matrix_u [ q - 1 ] [ q - 1 ] ) for i in range ( q - 2 , - 1 , - 1 ) : matrix_x [ i ] = float ( matrix_y [ i ] ) - sum ( [ matrix_u [ i ] [ j ] * ma... | Backward substitution method for the solution of linear systems . |
36,368 | def linspace ( start , stop , num , decimals = 18 ) : start = float ( start ) stop = float ( stop ) if abs ( start - stop ) <= 10e-8 : return [ start ] num = int ( num ) if num > 1 : div = num - 1 delta = stop - start return [ float ( ( "{:." + str ( decimals ) + "f}" ) . format ( ( start + ( float ( x ) * float ( delt... | Returns a list of evenly spaced numbers over a specified interval . |
36,369 | def convex_hull ( points ) : turn_left , turn_right , turn_none = ( 1 , - 1 , 0 ) def cmp ( a , b ) : return ( a > b ) - ( a < b ) def turn ( p , q , r ) : return cmp ( ( q [ 0 ] - p [ 0 ] ) * ( r [ 1 ] - p [ 1 ] ) - ( r [ 0 ] - p [ 0 ] ) * ( q [ 1 ] - p [ 1 ] ) , 0 ) def keep_left ( hull , r ) : while len ( hull ) > 1... | Returns points on convex hull in counterclockwise order according to Graham s scan algorithm . |
36,370 | def is_left ( point0 , point1 , point2 ) : return ( ( point1 [ 0 ] - point0 [ 0 ] ) * ( point2 [ 1 ] - point0 [ 1 ] ) ) - ( ( point2 [ 0 ] - point0 [ 0 ] ) * ( point1 [ 1 ] - point0 [ 1 ] ) ) | Tests if a point is Left|On|Right of an infinite line . |
36,371 | def wn_poly ( point , vertices ) : wn = 0 v_size = len ( vertices ) - 1 for i in range ( v_size ) : if vertices [ i ] [ 1 ] <= point [ 1 ] : if vertices [ i + 1 ] [ 1 ] > point [ 1 ] : if is_left ( vertices [ i ] , vertices [ i + 1 ] , point ) > 0 : wn += 1 else : if vertices [ i + 1 ] [ 1 ] <= point [ 1 ] : if is_left... | Winding number test for a point in a polygon . |
36,372 | def construct_surface ( direction , * args , ** kwargs ) : possible_dirs = [ 'u' , 'v' ] if direction not in possible_dirs : raise GeomdlException ( "Possible direction values: " + ", " . join ( [ val for val in possible_dirs ] ) , data = dict ( input_dir = direction ) ) size_other = len ( args ) if size_other < 2 : ra... | Generates surfaces from curves . |
36,373 | def extract_curves ( psurf , ** kwargs ) : if psurf . pdimension != 2 : raise GeomdlException ( "The input should be a spline surface" ) if len ( psurf ) != 1 : raise GeomdlException ( "Can only operate on single spline surfaces" ) extract_u = kwargs . get ( 'extract_u' , True ) extract_v = kwargs . get ( 'extract_v' ,... | Extracts curves from a surface . |
36,374 | def extract_surfaces ( pvol ) : if pvol . pdimension != 3 : raise GeomdlException ( "The input should be a spline volume" ) if len ( pvol ) != 1 : raise GeomdlException ( "Can only operate on single spline volumes" ) vol_data = pvol . data rational = vol_data [ 'rational' ] degree_u = vol_data [ 'degree' ] [ 0 ] degree... | Extracts surfaces from a volume . |
36,375 | def extract_isosurface ( pvol ) : if pvol . pdimension != 3 : raise GeomdlException ( "The input should be a spline volume" ) if len ( pvol ) != 1 : raise GeomdlException ( "Can only operate on single spline volumes" ) isosrf = extract_surfaces ( pvol ) return isosrf [ 'uv' ] [ 0 ] , isosrf [ 'uv' ] [ - 1 ] , isosrf [ ... | Extracts the largest isosurface from a volume . |
36,376 | def check_trim_curve ( curve , parbox , ** kwargs ) : def next_idx ( edge_idx , direction ) : tmp = edge_idx + direction if tmp < 0 : return 3 if tmp > 3 : return 0 return tmp tol = kwargs . get ( 'tol' , 10e-8 ) dist = linalg . point_distance ( curve . evalpts [ 0 ] , curve . evalpts [ - 1 ] ) if dist <= tol : return ... | Checks if the trim curve was closed and sense was set . |
36,377 | def get_par_box ( domain , last = False ) : u_range = domain [ 0 ] v_range = domain [ 1 ] verts = [ ( u_range [ 0 ] , v_range [ 0 ] ) , ( u_range [ 1 ] , v_range [ 0 ] ) , ( u_range [ 1 ] , v_range [ 1 ] ) , ( u_range [ 0 ] , v_range [ 1 ] ) ] if last : verts . append ( verts [ 0 ] ) return tuple ( verts ) | Returns the bounding box of the surface parametric domain in ccw direction . |
36,378 | def detect_sense ( curve , tol ) : if curve . opt_get ( 'reversed' ) is None : pts = curve . evalpts num_pts = len ( pts ) for idx in range ( 1 , num_pts - 1 ) : sense = detect_ccw ( pts [ idx - 1 ] , pts [ idx ] , pts [ idx + 1 ] , tol ) if sense < 0 : curve . opt = [ 'reversed' , 0 ] return True elif sense > 0 : curv... | Detects the sense i . e . clockwise or counter - clockwise of the curve . |
36,379 | def intersect ( ray1 , ray2 , ** kwargs ) : if not isinstance ( ray1 , Ray ) or not isinstance ( ray2 , Ray ) : raise TypeError ( "The input arguments must be instances of the Ray object" ) if ray1 . dimension != ray2 . dimension : raise ValueError ( "Dimensions of the input rays must be the same" ) tol = kwargs . get ... | Finds intersection of 2 rays . |
36,380 | def evaluate ( self , ** kwargs ) : self . _eval_points = kwargs . get ( 'points' , self . _init_array ( ) ) self . _dimension = len ( self . _eval_points [ 0 ] ) | Sets points that form the geometry . |
36,381 | def export_polydata ( obj , file_name , ** kwargs ) : content = export_polydata_str ( obj , ** kwargs ) return exch . write_file ( file_name , content ) | Exports control points or evaluated points in VTK Polydata format . |
36,382 | def make_zigzag ( points , num_cols ) : new_points = [ ] points_size = len ( points ) forward = True idx = 0 rev_idx = - 1 while idx < points_size : if forward : new_points . append ( points [ idx ] ) else : new_points . append ( points [ rev_idx ] ) rev_idx -= 1 idx += 1 if idx % num_cols == 0 : forward = False if for... | Converts linear sequence of points into a zig - zag shape . |
36,383 | def make_quad ( points , size_u , size_v ) : new_points = make_zigzag ( points , size_v ) new_points . reverse ( ) forward = True for row in range ( 0 , size_v ) : temp = [ ] for col in range ( 0 , size_u ) : temp . append ( points [ row + ( col * size_v ) ] ) if forward : forward = False else : forward = True temp . r... | Converts linear sequence of input points into a quad structure . |
36,384 | def make_quadtree ( points , size_u , size_v , ** kwargs ) : extrapolate = kwargs . get ( 'extrapolate' , True ) points2d = [ ] for i in range ( 0 , size_u ) : row_list = [ ] for j in range ( 0 , size_v ) : row_list . append ( points [ j + ( i * size_v ) ] ) points2d . append ( row_list ) qtree = [ ] for u in range ( s... | Generates a quadtree - like structure from surface control points . |
36,385 | def evaluate_bounding_box ( ctrlpts ) : dimension = len ( ctrlpts [ 0 ] ) bbmin = [ float ( 'inf' ) for _ in range ( 0 , dimension ) ] bbmax = [ float ( '-inf' ) for _ in range ( 0 , dimension ) ] for cpt in ctrlpts : for i , arr in enumerate ( zip ( cpt , bbmin ) ) : if arr [ 0 ] < arr [ 1 ] : bbmin [ i ] = arr [ 0 ] ... | Computes the minimum bounding box of the point set . |
36,386 | def make_triangle_mesh ( points , size_u , size_v , ** kwargs ) : def fix_numbering ( vertex_list , triangle_list ) : final_vertices = [ ] tri_vertex_ids = [ ] for tri in triangle_list : for td in tri . data : if td not in tri_vertex_ids : tri_vertex_ids . append ( td ) seen_vertices = [ ] for vertex in vertex_list : i... | Generates a triangular mesh from an array of points . |
36,387 | def polygon_triangulate ( tri_idx , * args ) : tidx = 0 triangles = [ ] for idx in range ( 1 , len ( args ) - 1 ) : tri = Triangle ( ) tri . id = tri_idx + tidx tri . add_vertex ( args [ 0 ] , args [ idx ] , args [ idx + 1 ] ) triangles . append ( tri ) tidx += 1 return triangles | Triangulates a monotone polygon defined by a list of vertices . |
36,388 | def make_quad_mesh ( points , size_u , size_v ) : vertex_idx = 0 quad_idx = 0 vertices = [ ] for pt in points : vrt = Vertex ( * pt , id = vertex_idx ) vertices . append ( vrt ) vertex_idx += 1 quads = [ ] for i in range ( 0 , size_u - 1 ) : for j in range ( 0 , size_v - 1 ) : v1 = vertices [ j + ( size_v * i ) ] v2 = ... | Generates a mesh of quadrilateral elements . |
36,389 | def surface_tessellate ( v1 , v2 , v3 , v4 , vidx , tidx , trim_curves , tessellate_args ) : tris = polygon_triangulate ( tidx , v1 , v2 , v3 , v4 ) return [ ] , tris | Triangular tessellation algorithm for surfaces with no trims . |
36,390 | def gone_online ( stream ) : while True : packet = yield from stream . get ( ) session_id = packet . get ( 'session_key' ) if session_id : user_owner = get_user_from_session ( session_id ) if user_owner : logger . debug ( 'User ' + user_owner . username + ' gone online' ) online_opponents = list ( filter ( lambda x : x... | Distributes the users online status to everyone he has dialog with |
36,391 | def new_messages_handler ( stream ) : while True : packet = yield from stream . get ( ) session_id = packet . get ( 'session_key' ) msg = packet . get ( 'message' ) username_opponent = packet . get ( 'username' ) if session_id and msg and username_opponent : user_owner = get_user_from_session ( session_id ) if user_own... | Saves a new chat message to db and distributes msg to connected users |
36,392 | def users_changed_handler ( stream ) : while True : yield from stream . get ( ) users = [ { 'username' : username , 'uuid' : uuid_str } for username , uuid_str in ws_connections . values ( ) ] packet = { 'type' : 'users-changed' , 'value' : sorted ( users , key = lambda i : i [ 'username' ] ) } logger . debug ( packet ... | Sends connected client list of currently active users in the chatroom |
36,393 | def is_typing_handler ( stream ) : while True : packet = yield from stream . get ( ) session_id = packet . get ( 'session_key' ) user_opponent = packet . get ( 'username' ) typing = packet . get ( 'typing' ) if session_id and user_opponent and typing is not None : user_owner = get_user_from_session ( session_id ) if us... | Show message to opponent if user is typing message |
36,394 | def read_message_handler ( stream ) : while True : packet = yield from stream . get ( ) session_id = packet . get ( 'session_key' ) user_opponent = packet . get ( 'username' ) message_id = packet . get ( 'message_id' ) if session_id and user_opponent and message_id is not None : user_owner = get_user_from_session ( ses... | Send message to user if the opponent has read the message |
36,395 | def main_handler ( websocket , path ) : path = path . split ( '/' ) username = path [ 2 ] session_id = path [ 1 ] user_owner = get_user_from_session ( session_id ) if user_owner : user_owner = user_owner . username ws_connections [ ( user_owner , username ) ] = websocket try : while websocket . open : data = yield from... | An Asyncio Task is created for every new websocket client connection that is established . This coroutine listens to messages from the connected client and routes the message to the proper queue . This coroutine can be thought of as a producer . |
36,396 | def anyword_substring_search_inner ( query_word , target_words ) : for target_word in target_words : if ( target_word . startswith ( query_word ) ) : return query_word return False | return True if ANY target_word matches a query_word |
36,397 | def anyword_substring_search ( target_words , query_words ) : matches_required = len ( query_words ) matches_found = 0 for query_word in query_words : reply = anyword_substring_search_inner ( query_word , target_words ) if reply is not False : matches_found += 1 else : return False if ( matches_found == matches_require... | return True if all query_words match |
36,398 | def substring_search ( query , list_of_strings , limit_results = DEFAULT_LIMIT ) : matching = [ ] query_words = query . split ( ' ' ) query_words . sort ( key = len , reverse = True ) counter = 0 for s in list_of_strings : target_words = s . split ( ' ' ) if ( anyword_substring_search ( target_words , query_words ) ) :... | main function to call for searching |
36,399 | def search_people_by_bio ( query , limit_results = DEFAULT_LIMIT , index = [ 'onename_people_index' ] ) : from pyes import QueryStringQuery , ES conn = ES ( ) q = QueryStringQuery ( query , search_fields = [ 'username' , 'profile_bio' ] , default_operator = 'and' ) results = conn . search ( query = q , size = 20 , indi... | queries lucene index to find a nearest match output is profile username |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.