Paste Code
Paste Blends
Paste Images
#!/usr/bin/env python

import os
import re

items = [
["FloatLerpf", "interpf", []],
["Sqrt3d", "sqrt3d", []],
["AngleToLength", "shell_angle_to_dist", []],

["Vec2Copyf", "copy_v2_v2", []],
["Vec2Addf", "add_v2_v2v2", []],
["Vec2Subf", "sub_v2_v2v2", []],
["Vec2Mulf", "mul_v2_fl", []],
["Vec2Lenf", "len_v2v2", []],
["Vec2Length", "len_v2", []],
["Vec2Length", "len_v2", []],
["Inp2f", "dot_v2v2", []],
["Normalize2", "normalize_v2", []],
["Vec2Lerpf", "interp_v2_v2v2", []],
["Vec2Lerp3f", "interp_v2_v2v2v2", []],

["VecCopyf", "copy_v3_v3", []],
["VecAddf", "add_v3_v3v3", []],
["VecSubf", "sub_v3_v3v3", []],
["VecMulf", "mul_v3_fl", []],
["VecMulVecf", "mul_v3_v3v3", []],
["VecNegf", "negate_v3", []],
["Inpf", "dot_v3v3", []],
["Crossf", "cross_v3_v3v3", []],
["Normalize", "normalize_v3", []],
["VecLength", "len_v3", []],
["VecLenf", "len_v3v3", []],
["VecMidf", "mid_v3_v3v3", []],
["VecLerpf", "interp_v3_v3v3", []],
["VecLerp3f", "interp_v3_v3v3v3", []],
["MinMax3", "minmax_v3_v3v3", []],
["VecOrthoBasisf", "ortho_basis_v3v3_v3", [1, 2, 0]],
["printvecf", "print_v3", []],
["VecIsNull", "is_zero_v3", []],
["VecEqual", "equals_v3v3", []],
["VecCompare", "compare_v3v3", []],
["VecLenCompare", "compare_len_v3v3", []],
["FloatCompare", "compare_v3v3", []],
["Projf", "project_v3_v3v3", []],
["VecBisect3", "bisect_v3_v3v3v3", []],
["VecReflect", "reflect_v3_v3v3", []],
["VecStar", "star_m3_v3", []],

["NormalShortToFloat", "normal_short_to_float_v3", []],
["NormalFloatToShort", "normal_float_to_short_v3", []],

["FloatCompare4", "compare_v4v4", []],
["printvec4f", "print_v4", []],

["VecAngle2", "angle_v2v2", []],
["VecAngle3", "angle_v3v3v3", []],
["Vec2Angle3", "angle_v2v2v2", []],
["NormalizedVecAngle2", "angle_normalized_v3v3", []],
["NormalizedVecAngle2_2D", "angle_normalized_v2v2", []],

["Mat3Clr", "zero_m3", []],
["Mat4Clr", "zero_m4", []],
["Mat3One", "unit_m3", []],
["Mat4One", "unit_m4", []],
["Mat3CpyMat3", "copy_m3_m3", []],
["Mat4CpyMat4", "copy_m4_m4", []],
["Mat4CpyMat3", "copy_m4_m3", []],
["Mat3CpyMat4", "copy_m3_m4", []],

["Mat3AddMat3", "add_m3_m3m3", []],
["Mat4AddMat4", "add_m4_m4m4", []],
["Mat3MulMat3", "mul_m3_m3m3", []],
["Mat4MulMat4", "mul_m4_m4m4", []],
["Mat4MulMat34", "mul_m4_m3m4", []],
["Mat4MulMat43", "mul_m4_m4m3", []],
["Mat3IsMat3MulMat4", "mul_m3_m3m4", []],
["Mat3MulSerie", "mul_serie_m3", []],
["Mat4MulSerie", "mul_serie_m4", []],
["Mat4MulVecfl", "mul_m4_v3", []],
["VecMat4MulVecfl", "mul_v3_m4v3", []],
["Mat4Mul3Vecfl", "mul_mat3_m4_v3", []],
["Mat4MulVec4fl", "mul_m4_v4", []],
["Mat4MulVec3Project", "mul_project_m4_v4", []],
["Mat3MulVecfl", "mul_m3_v3", []],
["Mat3MulVecd", "mul_m3_v3_double", []],
["Mat3TransMulVecfl", "mul_transposed_m3_v3", []],
["Mat3MulFloat", "mul_m3_fl", []],
["Mat4MulFloat", "mul_m4_fl", []],
["Mat4MulFloat3", "mul_mat3_m4_fl", []],
["Mat3SwapMat3", "swap_m3m3", []],
["Mat4SwapMat4", "swap_m4m4", []],

["Mat3Transp", "transpose_m3", []],
["Mat4Transp", "transpose_m4", []],
["Mat3Ortho", "normalize_m3", []],
["Mat4Ortho", "normalize_m4", []],
["Mat3Orthogonal", "orthogonalize_m3", []],
["Mat4Orthogonal", "orthogonalize_m4", []],
["IsMat3Orthogonal", "is_orthogonal_m3", []],
["IsMat4Orthogonal", "is_orthogonal_m4", []],
["Mat3Adj", "adjoint_m3_m3", []],
["Mat4Adj", "adjoint_m4_m4", []],
["Det2x2", "determinant_m2", []],
["Det3x3", "determinant_m3", []],
["Det4x4", "determinant_m4", []],

["Mat3Inv", "invert_m3_m3", []],
["Mat4Invert", "invert_m4_m4", []],
["Mat4InvertSimp", "invert_m4_m4", []],
["Mat4Inv", "invert_m4_m4", []],
["Mat4InvGG", "invert_m4_m4", []],

["Mat3Scale", "scale_m3_fl", []],
["Mat4Scale", "scale_m4_fl", []],
["Mat3ToScalef", "mat3_to_scale", []],
["Mat4ToScalef", "mat4_to_scale", []],
["SizeToMat3", "size_to_mat3", [1, 0]],
["SizeToMat4", "size_to_mat4", [1, 0]],
["Mat3ToSize", "mat3_to_size", [1, 0]],
["Mat4ToSize", "mat4_to_size", [1, 0]],
["LocEulSizeToMat4", "loc_eul_size_to_mat4", []],
["LocEulOSizeToMat4", "loc_eulO_size_to_mat4", []],
["LocQuatSizeToMat4", "loc_quat_size_to_mat4", []],
["Mat3BlendMat3", "blend_m3_m3m3", []],
["Mat4BlendMat4", "blend_m4_m4m4", []],

["printmatrix3", "print_m3", []],
["printmatrix4", "print_m4", []],

["MinMaxRGB", "minmax_rgb", []],

["CalcCent3f", "cent_tri_v3", []],
["CalcCent4f", "cent_quad_v3", []],
["CalcNormFloat", "normal_tri_v3", [3, 0, 1, 2]],
["CalcNormFloat4", "normal_quad_v3", [4, 0, 1, 2, 3]],
["AreaT3Dfl", "area_tri_v3", []],
["AreaQ3Dfl", "area_quad_v3", []],
["AreaPoly3Dfl", "area_poly_v3", []],
["AreaF2Dfl", "area_tri_v2", []],

["DistVL2Dfl", "dist_to_line_v2", []],
["PdistVL2Dfl", "dist_to_line_segment_v2", []],
["PdistVL3Dfl", "dist_to_line_segment_v3", []],
["PclosestVL3Dfl", "closest_to_line_segment_v3", []],
["lambda_cp_line_ex", "closest_to_line_v3", [3, 0, 1, 2]],

["IsectLL2Df", "isect_line_line_v2", []],
["IsectLL2Ds", "isect_line_line_v2_short", []],

["QuatIsNul", "is_zero_qt", []],
["QuatToEul", "quat_to_eul", [1, 0]],
["QuatOne", "unit_qt", []],
["QuatOne", "unit_qt", []],
["NormalQuat", "normalize_qt", []],
["QuatCopy", "copy_qt_qt", []],
["QuatMul", "mul_qt_qtqt", []],
["QuatMulVecf", "mul_qt_v3", []],
["QuatMulf", "mul_qt_fl", []],
["QuatMulFac", "mul_fac_qt_fl", []],
["QuatSub", "sub_qt_qtqt", []],
["QuatConj", "conjugate_qt", []],
["QuatInv", "invert_qt", []],
["QuatDot", "dot_qtqt", []],
["QuatInterpol", "interp_qt_qtqt", []],
["QuatAdd", "add_qt_qtqt", []],
["printquat", "print_qt", []],
["QuatToMat3", "quat_to_mat3", [1, 0]],
["QuatToMat4", "quat_to_mat4", [1, 0]],
["Mat3ToQuat", "mat3_to_quat", [1, 0]],
["Mat3ToQuat_is_ok", "mat3_to_quat_is_ok", [1, 0]],
["Mat4ToQuat", "mat4_to_quat", [1, 0]],
["triatoquat", "tri_to_quat", [3, 0, 1, 2]],
["vectoquat", "vec_to_quat", [3, 0, 1, 2]],
["RotationBetweenVectorsToQuat", "rotation_between_vecs_to_quat", []],

["EulToQuat", "eul_to_quat", [1, 0]],
["EulToMat3", "eul_to_mat3", [1, 0]],
["EulToMat4", "eul_to_mat4", [1, 0]],
["QuatToEul", "quat_to_eul", [1, 0]],
["Mat3ToEul", "mat3_to_eul", [1, 0]],
["Mat4ToEul", "mat4_to_eul", [1, 0]],
["Mat3ToCompatibleEulO", "mat3_to_compatible_eulO", [1, 2, 3, 0]],

["EulOToQuat", "eulO_to_quat", [2, 0, 1]],
["EulOToMat3", "eulO_to_mat3", [2, 0, 1]],
["EulOToMat4", "eulO_to_mat4", [2, 0, 1]],
["QuatToEulO", "quat_to_eulO", [1, 2, 0]],
["Mat3ToEulO", "mat3_to_eulO", [1, 2, 0]],
["Mat4ToEulO", "mat4_to_eulO", [1, 2, 0]],
["Mat3ToCompatibleEul", "mat3_to_compatible_eul", [1, 2, 0]],
["EulToGimbalAxis", "eulO_to_gimbal_axis", []],

["DQuatCpyDQuat", "copy_dq_dq", []],
["DQuatNormalize", "normalize_dq", []],
["DQuatAddWeighted", "add_weighted_dq_dq", []],
["DQuatMulVecfl", "mul_v3m3_dq", [1, 2, 0]],
["Mat4ToDQuat", "mat4_to_dquat", [2, 0, 1]],
["DQuatToMat4", "dquat_to_mat4", [1, 0]],

["AxisAngleToQuat", "axis_angle_to_quat", []],
["AxisAngleToMat3", "axis_angle_to_mat3", [2, 0, 1]],
["AxisAngleToMat4", "axis_angle_to_mat4", [2, 0, 1]],
["QuatToAxisAngle", "quat_to_axis_angle", [1, 2, 0]],
["Mat3ToAxisAngle", "mat3_to_axis_angle", [1, 2, 0]],
["Mat4ToAxisAngle", "mat4_to_axis_angle", [1, 2, 0]],

["AxisAngleToEulO", "axis_angle_to_eulO", [2, 3, 0, 1]],
["EulOToAxisAngle", "eulO_to_axis_angle", [2, 3, 0, 1]],

["euler_rot", "rotate_eul", [0, 2, 1]],
["eulerO_rot", "rotate_eulO", [0, 3, 2, 1]],

["VecRotToQuat", "axis_angle_to_quat", [2, 0, 1]],
["VecRotToMat3", "vec_rot_to_mat3", [2, 0, 1]],
["VecRotToMat4", "vec_rot_to_mat4", [2, 0, 1]],
["Mat3ToVecRot", "mat3_to_vec_rot", [1, 2, 0]],
["Mat4ToVecRot", "mat4_to_vec_rot", [1, 2, 0]],


["tubemap", "map_to_tube", [3, 4, 0, 1, 2]],
["spheremap", "map_to_sphere", [3, 4, 0, 1, 2]],

["IsectPT2Df", "isect_point_tri_v2", []],
["IsectPQ2Df", "isect_point_quad_v2", []],
["LineIntersectLine", "isect_line_line_v3", []],
["LineIntersectLineStrict", "isect_line_line_strict_v3", []],
["LineIntersectsTriangle", "isect_line_tri_v3", []],
["RayIntersectsTriangle", "isect_ray_tri_v3", []],
["RayIntersectsTriangleThreshold", "isect_ray_tri_threshold_v3", []],
["AabbIntersectAabb", "isect_aabb_aabb_v3", []],
["AabbIntersectAabb", "isect_aabb_aabb_v3", []],
["PointInQuad2DUV", "isect_point_quad_uv_v2", []],
["PointInFace2DUV", "isect_point_face_uv_v2", []],
["IsPointInTri2D", "isect_point_tri_v2", []],
["IsPointInTri2DInts", "isect_point_tri_v2_int", []],
["point_in_tri_prism", "isect_point_tri_prism_v3", []],
["SweepingSphereIntersectsTriangleUV", "isect_sweeping_sphere_tri_v3", []],
["AxialLineIntersectsTriangle", "isect_axial_line_tri_v3", []],

["InterpWeightsQ3Dfl", "interp_weights_face_v3", [5, 0, 1, 2, 3, 4]],
["MeanValueWeights", "interp_weights_poly_v3", [3, 0, 1, 2]],
["VecfCubicInterpol", "interp_cubic_v3", [5, 6, 0, 1, 2, 3, 4]],

["i_window", "perspective_m4", [6, 0, 1, 2, 3, 4, 5]],
["i_ortho", "orthographic_m4", [6, 0, 1, 2, 3, 4, 5]],
["i_polarview", "polarview_m4", [4, 0, 1, 2, 3]],
["i_lookat", "lookat_m4", [7, 0, 1, 2, 3, 4, 5, 6]],
["i_rotate", "rotate_m4", [2, 1, 0]],
["i_translate", "translate_m4", [3, 0, 1, 2]],
]

# create regular expressions
subs = []
subs += [["BLI_arithb.h", "BLI_math.h"]]

sdetect = "(BLI_arithb.h"

for item in items:
old, new, shuffle = item

sfrom = r'([^A-Za-z_:])%s\s*\(' % old

if len(shuffle):
for s in shuffle:
sfrom += r'(.*)'

if s != shuffle[-1]:
sfrom += r','

sfrom += r'\)'

sto = r'\1%s(' % new

if len(shuffle):
for s in shuffle:
sto += r'\%d' % (s+2)

if s != shuffle[-1]:
sto += r','

sto += r')'

subs += [[sfrom, sto]]

sdetect += "|" + old

sdetect += ")"
rdetect = re.compile(sdetect)

for i in range(0, len(subs)):
print subs[i]
subs[i][0] = re.compile(subs[i][0])
#subs[i][1] = re.compile(subs[i][1])

# apply to files
files = []

for dirpath, dirnames, filenames in os.walk("source"):
for filename in filenames:
if filename.startswith("math_"):
pass
elif filename.startswith("BLI_math"):
pass
elif filename.endswith(".c") or filename.endswith(".cpp") or filename.endswith(".h"):
files += [dirpath + os.sep + filename]

# default cache is too small, and there doesn't seem
# to be a way to compile patterns for sub()
re._MAXCACHE = len(items)*2 + 50

for file in files:
print file
f = open(file, "r")

lines = f.readlines()
newlines = []
for line in lines:
if rdetect.search(line):
for sub in subs:
line = sub[0].sub(sub[1], line)
newlines += [line]

f.close()

f = open(file, "w")
f.writelines(newlines)
f.close()
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import re
  5.  
  6. items = [
  7. ["FloatLerpf", "interpf", []],
  8. ["Sqrt3d", "sqrt3d", []],
  9. ["AngleToLength", "shell_angle_to_dist", []],
  10.  
  11. ["Vec2Copyf", "copy_v2_v2", []],
  12. ["Vec2Addf", "add_v2_v2v2", []],
  13. ["Vec2Subf", "sub_v2_v2v2", []],
  14. ["Vec2Mulf", "mul_v2_fl", []],
  15. ["Vec2Lenf", "len_v2v2", []],
  16. ["Vec2Length", "len_v2", []],
  17. ["Vec2Length", "len_v2", []],
  18. ["Inp2f", "dot_v2v2", []],
  19. ["Normalize2", "normalize_v2", []],
  20. ["Vec2Lerpf", "interp_v2_v2v2", []],
  21. ["Vec2Lerp3f", "interp_v2_v2v2v2", []],
  22.  
  23. ["VecCopyf", "copy_v3_v3", []],
  24. ["VecAddf", "add_v3_v3v3", []],
  25. ["VecSubf", "sub_v3_v3v3", []],
  26. ["VecMulf", "mul_v3_fl", []],
  27. ["VecMulVecf", "mul_v3_v3v3", []],
  28. ["VecNegf", "negate_v3", []],
  29. ["Inpf", "dot_v3v3", []],
  30. ["Crossf", "cross_v3_v3v3", []],
  31. ["Normalize", "normalize_v3", []],
  32. ["VecLength", "len_v3", []],
  33. ["VecLenf", "len_v3v3", []],
  34. ["VecMidf", "mid_v3_v3v3", []],
  35. ["VecLerpf", "interp_v3_v3v3", []],
  36. ["VecLerp3f", "interp_v3_v3v3v3", []],
  37. ["MinMax3", "minmax_v3_v3v3", []],
  38. ["VecOrthoBasisf", "ortho_basis_v3v3_v3", [1, 2, 0]],
  39. ["printvecf", "print_v3", []],
  40. ["VecIsNull", "is_zero_v3", []],
  41. ["VecEqual", "equals_v3v3", []],
  42. ["VecCompare", "compare_v3v3", []],
  43. ["VecLenCompare", "compare_len_v3v3", []],
  44. ["FloatCompare", "compare_v3v3", []],
  45. ["Projf", "project_v3_v3v3", []],
  46. ["VecBisect3", "bisect_v3_v3v3v3", []],
  47. ["VecReflect", "reflect_v3_v3v3", []],
  48. ["VecStar", "star_m3_v3", []],
  49.  
  50. ["NormalShortToFloat", "normal_short_to_float_v3", []],
  51. ["NormalFloatToShort", "normal_float_to_short_v3", []],
  52.  
  53. ["FloatCompare4", "compare_v4v4", []],
  54. ["printvec4f", "print_v4", []],
  55.  
  56. ["VecAngle2", "angle_v2v2", []],
  57. ["VecAngle3", "angle_v3v3v3", []],
  58. ["Vec2Angle3", "angle_v2v2v2", []],
  59. ["NormalizedVecAngle2", "angle_normalized_v3v3", []],
  60. ["NormalizedVecAngle2_2D", "angle_normalized_v2v2", []],
  61.  
  62. ["Mat3Clr", "zero_m3", []],
  63. ["Mat4Clr", "zero_m4", []],
  64. ["Mat3One", "unit_m3", []],
  65. ["Mat4One", "unit_m4", []],
  66. ["Mat3CpyMat3", "copy_m3_m3", []],
  67. ["Mat4CpyMat4", "copy_m4_m4", []],
  68. ["Mat4CpyMat3", "copy_m4_m3", []],
  69. ["Mat3CpyMat4", "copy_m3_m4", []],
  70.  
  71. ["Mat3AddMat3", "add_m3_m3m3", []],
  72. ["Mat4AddMat4", "add_m4_m4m4", []],
  73. ["Mat3MulMat3", "mul_m3_m3m3", []],
  74. ["Mat4MulMat4", "mul_m4_m4m4", []],
  75. ["Mat4MulMat34", "mul_m4_m3m4", []],
  76. ["Mat4MulMat43", "mul_m4_m4m3", []],
  77. ["Mat3IsMat3MulMat4", "mul_m3_m3m4", []],
  78. ["Mat3MulSerie", "mul_serie_m3", []],
  79. ["Mat4MulSerie", "mul_serie_m4", []],
  80. ["Mat4MulVecfl", "mul_m4_v3", []],
  81. ["VecMat4MulVecfl", "mul_v3_m4v3", []],
  82. ["Mat4Mul3Vecfl", "mul_mat3_m4_v3", []],
  83. ["Mat4MulVec4fl", "mul_m4_v4", []],
  84. ["Mat4MulVec3Project", "mul_project_m4_v4", []],
  85. ["Mat3MulVecfl", "mul_m3_v3", []],
  86. ["Mat3MulVecd", "mul_m3_v3_double", []],
  87. ["Mat3TransMulVecfl", "mul_transposed_m3_v3", []],
  88. ["Mat3MulFloat", "mul_m3_fl", []],
  89. ["Mat4MulFloat", "mul_m4_fl", []],
  90. ["Mat4MulFloat3", "mul_mat3_m4_fl", []],
  91. ["Mat3SwapMat3", "swap_m3m3", []],
  92. ["Mat4SwapMat4", "swap_m4m4", []],
  93.  
  94. ["Mat3Transp", "transpose_m3", []],
  95. ["Mat4Transp", "transpose_m4", []],
  96. ["Mat3Ortho", "normalize_m3", []],
  97. ["Mat4Ortho", "normalize_m4", []],
  98. ["Mat3Orthogonal", "orthogonalize_m3", []],
  99. ["Mat4Orthogonal", "orthogonalize_m4", []],
  100. ["IsMat3Orthogonal", "is_orthogonal_m3", []],
  101. ["IsMat4Orthogonal", "is_orthogonal_m4", []],
  102. ["Mat3Adj", "adjoint_m3_m3", []],
  103. ["Mat4Adj", "adjoint_m4_m4", []],
  104. ["Det2x2", "determinant_m2", []],
  105. ["Det3x3", "determinant_m3", []],
  106. ["Det4x4", "determinant_m4", []],
  107.  
  108. ["Mat3Inv", "invert_m3_m3", []],
  109. ["Mat4Invert", "invert_m4_m4", []],
  110. ["Mat4InvertSimp", "invert_m4_m4", []],
  111. ["Mat4Inv", "invert_m4_m4", []],
  112. ["Mat4InvGG", "invert_m4_m4", []],
  113.  
  114. ["Mat3Scale", "scale_m3_fl", []],
  115. ["Mat4Scale", "scale_m4_fl", []],
  116. ["Mat3ToScalef", "mat3_to_scale", []],
  117. ["Mat4ToScalef", "mat4_to_scale", []],
  118. ["SizeToMat3", "size_to_mat3", [1, 0]],
  119. ["SizeToMat4", "size_to_mat4", [1, 0]],
  120. ["Mat3ToSize", "mat3_to_size", [1, 0]],
  121. ["Mat4ToSize", "mat4_to_size", [1, 0]],
  122. ["LocEulSizeToMat4", "loc_eul_size_to_mat4", []],
  123. ["LocEulOSizeToMat4", "loc_eulO_size_to_mat4", []],
  124. ["LocQuatSizeToMat4", "loc_quat_size_to_mat4", []],
  125. ["Mat3BlendMat3", "blend_m3_m3m3", []],
  126. ["Mat4BlendMat4", "blend_m4_m4m4", []],
  127.  
  128. ["printmatrix3", "print_m3", []],
  129. ["printmatrix4", "print_m4", []],
  130.  
  131. ["MinMaxRGB", "minmax_rgb", []],
  132.  
  133. ["CalcCent3f", "cent_tri_v3", []],
  134. ["CalcCent4f", "cent_quad_v3", []],
  135. ["CalcNormFloat", "normal_tri_v3", [3, 0, 1, 2]],
  136. ["CalcNormFloat4", "normal_quad_v3", [4, 0, 1, 2, 3]],
  137. ["AreaT3Dfl", "area_tri_v3", []],
  138. ["AreaQ3Dfl", "area_quad_v3", []],
  139. ["AreaPoly3Dfl", "area_poly_v3", []],
  140. ["AreaF2Dfl", "area_tri_v2", []],
  141.  
  142. ["DistVL2Dfl", "dist_to_line_v2", []],
  143. ["PdistVL2Dfl", "dist_to_line_segment_v2", []],
  144. ["PdistVL3Dfl", "dist_to_line_segment_v3", []],
  145. ["PclosestVL3Dfl", "closest_to_line_segment_v3", []],
  146. ["lambda_cp_line_ex", "closest_to_line_v3", [3, 0, 1, 2]],
  147.  
  148. ["IsectLL2Df", "isect_line_line_v2", []],
  149. ["IsectLL2Ds", "isect_line_line_v2_short", []],
  150.  
  151. ["QuatIsNul", "is_zero_qt", []],
  152. ["QuatToEul", "quat_to_eul", [1, 0]],
  153. ["QuatOne", "unit_qt", []],
  154. ["QuatOne", "unit_qt", []],
  155. ["NormalQuat", "normalize_qt", []],
  156. ["QuatCopy", "copy_qt_qt", []],
  157. ["QuatMul", "mul_qt_qtqt", []],
  158. ["QuatMulVecf", "mul_qt_v3", []],
  159. ["QuatMulf", "mul_qt_fl", []],
  160. ["QuatMulFac", "mul_fac_qt_fl", []],
  161. ["QuatSub", "sub_qt_qtqt", []],
  162. ["QuatConj", "conjugate_qt", []],
  163. ["QuatInv", "invert_qt", []],
  164. ["QuatDot", "dot_qtqt", []],
  165. ["QuatInterpol", "interp_qt_qtqt", []],
  166. ["QuatAdd", "add_qt_qtqt", []],
  167. ["printquat", "print_qt", []],
  168. ["QuatToMat3", "quat_to_mat3", [1, 0]],
  169. ["QuatToMat4", "quat_to_mat4", [1, 0]],
  170. ["Mat3ToQuat", "mat3_to_quat", [1, 0]],
  171. ["Mat3ToQuat_is_ok", "mat3_to_quat_is_ok", [1, 0]],
  172. ["Mat4ToQuat", "mat4_to_quat", [1, 0]],
  173. ["triatoquat", "tri_to_quat", [3, 0, 1, 2]],
  174. ["vectoquat", "vec_to_quat", [3, 0, 1, 2]],
  175. ["RotationBetweenVectorsToQuat", "rotation_between_vecs_to_quat", []],
  176.  
  177. ["EulToQuat", "eul_to_quat", [1, 0]],
  178. ["EulToMat3", "eul_to_mat3", [1, 0]],
  179. ["EulToMat4", "eul_to_mat4", [1, 0]],
  180. ["QuatToEul", "quat_to_eul", [1, 0]],
  181. ["Mat3ToEul", "mat3_to_eul", [1, 0]],
  182. ["Mat4ToEul", "mat4_to_eul", [1, 0]],
  183. ["Mat3ToCompatibleEulO", "mat3_to_compatible_eulO", [1, 2, 3, 0]],
  184.  
  185. ["EulOToQuat", "eulO_to_quat", [2, 0, 1]],
  186. ["EulOToMat3", "eulO_to_mat3", [2, 0, 1]],
  187. ["EulOToMat4", "eulO_to_mat4", [2, 0, 1]],
  188. ["QuatToEulO", "quat_to_eulO", [1, 2, 0]],
  189. ["Mat3ToEulO", "mat3_to_eulO", [1, 2, 0]],
  190. ["Mat4ToEulO", "mat4_to_eulO", [1, 2, 0]],
  191. ["Mat3ToCompatibleEul", "mat3_to_compatible_eul", [1, 2, 0]],
  192. ["EulToGimbalAxis", "eulO_to_gimbal_axis", []],
  193.  
  194. ["DQuatCpyDQuat", "copy_dq_dq", []],
  195. ["DQuatNormalize", "normalize_dq", []],
  196. ["DQuatAddWeighted", "add_weighted_dq_dq", []],
  197. ["DQuatMulVecfl", "mul_v3m3_dq", [1, 2, 0]],
  198. ["Mat4ToDQuat", "mat4_to_dquat", [2, 0, 1]],
  199. ["DQuatToMat4", "dquat_to_mat4", [1, 0]],
  200.  
  201. ["AxisAngleToQuat", "axis_angle_to_quat", []],
  202. ["AxisAngleToMat3", "axis_angle_to_mat3", [2, 0, 1]],
  203. ["AxisAngleToMat4", "axis_angle_to_mat4", [2, 0, 1]],
  204. ["QuatToAxisAngle", "quat_to_axis_angle", [1, 2, 0]],
  205. ["Mat3ToAxisAngle", "mat3_to_axis_angle", [1, 2, 0]],
  206. ["Mat4ToAxisAngle", "mat4_to_axis_angle", [1, 2, 0]],
  207.  
  208. ["AxisAngleToEulO", "axis_angle_to_eulO", [2, 3, 0, 1]],
  209. ["EulOToAxisAngle", "eulO_to_axis_angle", [2, 3, 0, 1]],
  210.  
  211. ["euler_rot", "rotate_eul", [0, 2, 1]],
  212. ["eulerO_rot", "rotate_eulO", [0, 3, 2, 1]],
  213.  
  214. ["VecRotToQuat", "axis_angle_to_quat", [2, 0, 1]],
  215. ["VecRotToMat3", "vec_rot_to_mat3", [2, 0, 1]],
  216. ["VecRotToMat4", "vec_rot_to_mat4", [2, 0, 1]],
  217. ["Mat3ToVecRot", "mat3_to_vec_rot", [1, 2, 0]],
  218. ["Mat4ToVecRot", "mat4_to_vec_rot", [1, 2, 0]],
  219.  
  220.  
  221. ["tubemap", "map_to_tube", [3, 4, 0, 1, 2]],
  222. ["spheremap", "map_to_sphere", [3, 4, 0, 1, 2]],
  223.  
  224. ["IsectPT2Df", "isect_point_tri_v2", []],
  225. ["IsectPQ2Df", "isect_point_quad_v2", []],
  226. ["LineIntersectLine", "isect_line_line_v3", []],
  227. ["LineIntersectLineStrict", "isect_line_line_strict_v3", []],
  228. ["LineIntersectsTriangle", "isect_line_tri_v3", []],
  229. ["RayIntersectsTriangle", "isect_ray_tri_v3", []],
  230. ["RayIntersectsTriangleThreshold", "isect_ray_tri_threshold_v3", []],
  231. ["AabbIntersectAabb", "isect_aabb_aabb_v3", []],
  232. ["AabbIntersectAabb", "isect_aabb_aabb_v3", []],
  233. ["PointInQuad2DUV", "isect_point_quad_uv_v2", []],
  234. ["PointInFace2DUV", "isect_point_face_uv_v2", []],
  235. ["IsPointInTri2D", "isect_point_tri_v2", []],
  236. ["IsPointInTri2DInts", "isect_point_tri_v2_int", []],
  237. ["point_in_tri_prism", "isect_point_tri_prism_v3", []],
  238. ["SweepingSphereIntersectsTriangleUV", "isect_sweeping_sphere_tri_v3", []],
  239. ["AxialLineIntersectsTriangle", "isect_axial_line_tri_v3", []],
  240.  
  241. ["InterpWeightsQ3Dfl", "interp_weights_face_v3", [5, 0, 1, 2, 3, 4]],
  242. ["MeanValueWeights", "interp_weights_poly_v3", [3, 0, 1, 2]],
  243. ["VecfCubicInterpol", "interp_cubic_v3", [5, 6, 0, 1, 2, 3, 4]],
  244.  
  245. ["i_window", "perspective_m4", [6, 0, 1, 2, 3, 4, 5]],
  246. ["i_ortho", "orthographic_m4", [6, 0, 1, 2, 3, 4, 5]],
  247. ["i_polarview", "polarview_m4", [4, 0, 1, 2, 3]],
  248. ["i_lookat", "lookat_m4", [7, 0, 1, 2, 3, 4, 5, 6]],
  249. ["i_rotate", "rotate_m4", [2, 1, 0]],
  250. ["i_translate", "translate_m4", [3, 0, 1, 2]],
  251. ]
  252.  
  253. # create regular expressions
  254. subs = []
  255. subs += [["BLI_arithb.h", "BLI_math.h"]]
  256.  
  257. sdetect = "(BLI_arithb.h"
  258.  
  259. for item in items:
  260.         old, new, shuffle = item
  261.  
  262.         sfrom = r'([^A-Za-z_:])%s\s*\(' % old
  263.  
  264.         if len(shuffle):
  265.                 for s in shuffle:
  266.                         sfrom += r'(.*)'
  267.  
  268.                         if s != shuffle[-1]:
  269.                                 sfrom += r','
  270.                
  271.                 sfrom += r'\)'
  272.        
  273.         sto = r'\1%s(' % new
  274.  
  275.         if len(shuffle):
  276.                 for s in shuffle:
  277.                         sto += r'\%d' % (s+2)
  278.  
  279.                         if s != shuffle[-1]:
  280.                                 sto += r','
  281.  
  282.                 sto += r')'
  283.        
  284.         subs += [[sfrom, sto]]
  285.  
  286.         sdetect += "|" + old
  287.  
  288. sdetect += ")"
  289. rdetect = re.compile(sdetect)
  290.  
  291. for i in range(0, len(subs)):
  292.         print subs[i]
  293.         subs[i][0] = re.compile(subs[i][0])
  294.         #subs[i][1] = re.compile(subs[i][1])
  295.  
  296. # apply to files
  297. files = []
  298.  
  299. for dirpath, dirnames, filenames in os.walk("source"):
  300.         for filename in filenames:
  301.                 if filename.startswith("math_"):
  302.                         pass
  303.                 elif filename.startswith("BLI_math"):
  304.                         pass
  305.                 elif filename.endswith(".c") or filename.endswith(".cpp") or filename.endswith(".h"):
  306.                         files += [dirpath + os.sep + filename]
  307.  
  308. # default cache is too small, and there doesn't seem
  309. # to be a way to compile patterns for sub()
  310. re._MAXCACHE = len(items)*2 + 50
  311.  
  312. for file in files:
  313.         print file
  314.         f = open(file, "r")
  315.  
  316.         lines = f.readlines()
  317.         newlines = []
  318.         for line in lines:
  319.                 if rdetect.search(line):
  320.                         for sub in subs:
  321.                                 line = sub[0].sub(sub[1], line)
  322.                 newlines += [line]
  323.        
  324.         f.close()
  325.  
  326.         f = open(file, "w")
  327.         f.writelines(newlines)
  328.         f.close()
  329.  
go to heaven