diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index 70a22887..dd179cd0 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -42,7 +42,7 @@ def getId(facein, surfaces): s.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): return s.Index @@ -53,7 +53,7 @@ def getId(facein, surfaces): s.Surf, dtol=tol.cyl_distance, atol=tol.cyl_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): return s.Index @@ -64,14 +64,14 @@ def getId(facein, surfaces): s.Surf, dtol=tol.kne_distance, atol=tol.kne_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): return s.Index elif surfin[0:6] == "Sphere": for s in surfaces["Sph"]: if BF.isSameSphere( - facein, s.Surf, tol.sph_distance, relTol=tol.relativeTol + facein, s.Surf, tol.sph_distance, rel_tol=tol.relativeTol ): return s.Index @@ -82,7 +82,7 @@ def getId(facein, surfaces): s.Surf, dtol=tol.tor_distance, atol=tol.tor_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): return s.Index diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index 72679024..73029855 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -77,7 +77,7 @@ def getId(face_in, Surfaces): s.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): return s.Index diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part1.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part1.py index f5ccfc99..d94794d7 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part1.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part1.py @@ -10,57 +10,57 @@ def isSameValue(v1, v2, tolerance=1e-6): return abs(v1 - v2) < tolerance -def isOposite(Vector1, Vector2, tolerance=1e-6): - return abs(Vector1.getAngle(-Vector2)) < tolerance +def isOposite(vector_1, vector_2, tolerance=1e-6): + return abs(vector_1.getAngle(-vector_2)) < tolerance -def isParallel(Vector1, Vector2, tolerance=1e-6): - angle = abs(Vector1.getAngle(Vector2)) +def isParallel(vector_1, vector_2, tolerance=1e-6): + angle = abs(vector_1.getAngle(vector_2)) return angle < tolerance or isSameValue(angle, math.pi, tolerance) -def isInLine(Point, Dir, Pnt_line, tolerance=1e-6): - r12 = Point - Pnt_line - return isParallel(Dir, r12) or (r12.Length < tolerance) +def isInLine(point, dir, pnt_line, tolerance=1e-6): + r12 = point - pnt_line + return isParallel(dir, r12) or (r12.Length < tolerance) -def isInPoints(point, Points, tolerance=1e-5): - if len(Points) > 0: - for P in Points: - if point.isEqual(P, tolerance): +def isInPoints(point, points, tolerance=1e-5): + if len(points) > 0: + for p in points: + if point.isEqual(p, tolerance): return True return False -def isInEdge(Edge1, Edge2, tolerance=1e-8): - Ver1 = Edge1.Vertexes - Ver2 = Edge2.Vertexes - con1 = Ver1[0].Point.isEqual(Ver2[0].Point, tolerance) or Ver1[0].Point.isEqual( - Ver2[1].Point, tolerance +def isInEdge(edge1, edge2, tolerance=1e-8): + ver1 = edge1.Vertexes + ver2 = edge2.Vertexes + con1 = ver1[0].Point.isEqual(ver2[0].Point, tolerance) or ver1[0].Point.isEqual( + ver2[1].Point, tolerance ) - con2 = Ver1[1].Point.isEqual(Ver2[0].Point, tolerance) or Ver1[1].Point.isEqual( - Ver2[1].Point, tolerance + con2 = ver1[1].Point.isEqual(ver2[0].Point, tolerance) or ver1[1].Point.isEqual( + ver2[1].Point, tolerance ) return con1 and con2 -def isInPlane(Point, plane, dtolerance=1e-7): - return abs(Point.distanceToPlane(plane.Surf.Position, plane.Surf.Axis)) < dtolerance +def isInPlane(point, plane, d_tolerance=1e-7): + return abs(point.distanceToPlane(plane.Surf.Position, plane.Surf.Axis)) < d_tolerance -def isInTolerance(val, tol, fuzzyLow, fuzzyHigh): - if abs(val) < fuzzyLow: +def isInTolerance(val, tol, fuzzy_low, fuzzy_high): + if abs(val) < fuzzy_low: return True, False # 1) isintolerance 2) fuzzy elif abs(val) < tol: return True, True - elif abs(val) > fuzzyHigh: + elif abs(val) > fuzzy_high: return False, False else: return False, True -def signPlane(Point, plane): - value = plane.Surf.Axis.dot(Point - plane.Surf.Position) +def signPlane(point, plane): + value = plane.Surf.Axis.dot(point - plane.Surf.Position) if value >= 0.0: sign = 1 else: @@ -68,8 +68,8 @@ def signPlane(Point, plane): return sign -def pointsToCoeffs(Points): - p1, p2, p3 = Points[0:3] +def pointsToCoeffs(points): + p1, p2, p3 = points[0:3] scf = (p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z) # mcnp implementation to convert 3 point plane to @@ -95,11 +95,11 @@ def pointsToCoeffs(Points): xm = 1 / tpp[4 - i] coeff[4 - i] = tpp[4 - i] * xm - Axis = FreeCAD.Vector(coeff[0:3]) - Distance = coeff[3] / Axis.Length - Axis.normalize() + axis = FreeCAD.Vector(coeff[0:3]) + distance = coeff[3] / axis.Length + axis.normalize() - return Axis, Distance + return axis, distance class Plane3PtsParams: diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 430e1303..a5a1cb7d 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -15,7 +15,7 @@ ) from ..Write.Functions import MCNPSurface -sameSurfFic = open("fuzzySurfaces", "w") +same_surf_fic = open("fuzzySurfaces", "w") def Fuzzy(index, dtype, surf1, surf2, val, tol): @@ -28,7 +28,7 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol): line = "Same surface : {}\nPlane distance / Tolerance : {} {}\n {}\n {}\n\n".format( same, val, tol, p1str, p2str ) - sameSurfFic.write(line) + same_surf_fic.write(line) elif dtype == "cylRad": cyl1str = MCNPSurface(index, "Cylinder", surf1) @@ -36,7 +36,7 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol): line = "Same surface : {}\nDiff Radius / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) - sameSurfFic.write(line) + same_surf_fic.write(line) elif dtype == "cylAxs": cyl1str = MCNPSurface(index, "Cylinder", surf1) @@ -44,62 +44,62 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol): line = "Same surface : {}\nDist Axis / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) - sameSurfFic.write(line) + same_surf_fic.write(line) -def isSamePlane(p1, p2, dtol=1e-6, atol=1e-6, relTol=True, fuzzy=(False, 0)): +def isSamePlane(p1, p2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): if isParallel(p1.Axis, p2.Axis, atol): d1 = p1.Axis.dot(p1.Position) d2 = p2.Axis.dot(p2.Position) if isOposite(p1.Axis, p2.Axis, atol): d2 = -d2 d = abs(d1 - d2) - if relTol: + if rel_tol: tol = dtol * max(p2.dim1, p2.dim2) else: tol = dtol - isSame, isFuzzy = isInTolerance(d, tol, 0.5 * tol, 2 * tol) - if isFuzzy and fuzzy[0]: + isSame, is_fuzzy = isInTolerance(d, tol, 0.5 * tol, 2 * tol) + if is_fuzzy and fuzzy[0]: Fuzzy(fuzzy[1], "plane", p2, p1, d, tol) return isSame return False -def isSameCylinder(cyl1, cyl2, dtol=1e-6, atol=1e-6, relTol=True, fuzzy=(False, 0)): - if relTol: +def isSameCylinder(cyl1, cyl2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): + if rel_tol: rtol = dtol * max(cyl2.Radius, cyl1.Radius) else: rtol = dtol - isSameRad, isFuzzy = isInTolerance( + is_same_rad, is_fuzzy = isInTolerance( cyl2.Radius - cyl1.Radius, rtol, 0.5 * rtol, 2 * rtol ) - if isFuzzy and fuzzy[0]: + if is_fuzzy and fuzzy[0]: Fuzzy(fuzzy[1], "cylRad", cyl2, cyl1, abs(cyl2.Radius - cyl1.Radius), rtol) - if isSameRad: + if is_same_rad: if isParallel(cyl1.Axis, cyl2.Axis, atol): c12 = cyl1.Center - cyl2.Center d = cyl1.Axis.cross(c12).Length - if relTol: + if rel_tol: tol = dtol * max(cyl1.Center.Length, cyl2.Center.Length) else: tol = dtol - isSameCenter, isFuzzy = isInTolerance(d, tol, 0.5 * tol, 2 * tol) - if isFuzzy and fuzzy[0]: + is_same_center, is_fuzzy = isInTolerance(d, tol, 0.5 * tol, 2 * tol) + if is_fuzzy and fuzzy[0]: Fuzzy(fuzzy[1], "cylAxs", cyl1, cyl2, d, tol) - return isSameCenter + return is_same_center return False -def isSameCone(cone1, cone2, dtol=1e-6, atol=1e-6, relTol=True): +def isSameCone(cone1, cone2, dtol=1e-6, atol=1e-6, rel_tol=True): if isSameValue(cone1.SemiAngle, cone2.SemiAngle, atol): if isParallel(cone1.Axis, cone2.Axis, atol): - if relTol: + if rel_tol: tol = dtol * max(cone1.Apex.Length, cone2.Apex.Length) else: tol = dtol @@ -107,13 +107,13 @@ def isSameCone(cone1, cone2, dtol=1e-6, atol=1e-6, relTol=True): return False -def isSameSphere(sph1, sph2, tolerance=1e-6, relTol=True): - if relTol: +def isSameSphere(sph1, sph2, tolerance=1e-6, rel_tol=True): + if rel_tol: rtol = tolerance * max(sph2.Radius, sph1.Radius) else: rtol = tolerance if isSameValue(sph1.Radius, sph2.Radius, rtol): - if relTol: + if rel_tol: ctol = tolerance * max(sph2.Center.Length, sph1.Center.Length) else: ctol = tolerance @@ -122,11 +122,11 @@ def isSameSphere(sph1, sph2, tolerance=1e-6, relTol=True): return False -def isSameTorus(tor1, tor2, dtol=1e-6, atol=1e-6, relTol=True): +def isSameTorus(tor1, tor2, dtol=1e-6, atol=1e-6, rel_tol=True): if isParallel(tor1.Axis, tor2.Axis, atol): if tor1.Axis.dot(tor2.Axis) < 0: return False # Assume same cone with oposite axis as different - if relTol: + if rel_tol: Rtol = dtol * max(tor1.MajorRadius, tor2.MajorRadius) rtol = dtol * max(tor1.MinorRadius, tor2.MinorRadius) else: @@ -136,7 +136,7 @@ def isSameTorus(tor1, tor2, dtol=1e-6, atol=1e-6, relTol=True): if isSameValue(tor1.MajorRadius, tor2.MajorRadius, Rtol) and isSameValue( tor1.MinorRadius, tor2.MinorRadius, rtol ): - if relTol: + if rel_tol: ctol = dtol * max(tor1.Center.Length, tor2.Center.Length) else: ctol = dtol @@ -167,53 +167,53 @@ def isDuplicateInList(num_str1, i, lista): return False -def isInFaces(face, Faces): +def isInFaces(face, faces): - if Faces == []: + if faces == []: return False vector_nulo = FreeCAD.Vector(0, 0, 0) surface = face.Surface kind_surf = str(face.Surface) if kind_surf == "": - Axis = surface.Axis - Position = surface.Position + axis = surface.Axis + position = surface.Position elif kind_surf == "": - Axis = surface.Axis - Radius = surface.Radius - Center = surface.Center + axis = surface.Axis + radius = surface.Radius + center = surface.Center elif kind_surf == "": - Axis = surface.Axis - Apex = surface.Apex - SemiAngle = surface.SemiAngle + axis = surface.Axis + apex = surface.Apex + semi_angle = surface.SemiAngle elif kind_surf[0:6] == "Sphere": - Center = surface.Center - Radius = surface.Radius + center = surface.Center + radius = surface.Radius elif kind_surf == "": - Axis = surface.Axis - Center = surface.Center - MajorRadius = surface.MajorRadius - MinorRadius = surface.MinorRadius + axis = surface.Axis + center = surface.Center + major_radius = surface.MajorRadius + minor_radius = surface.MinorRadius - for elem in Faces: + for elem in faces: surf = elem.Surface ##print surf if str(surf) == "" and kind_surf == "": - vector_cross = Axis.cross(surf.Axis) - if vector_cross == vector_nulo and isInPlane(Position, surf): + vector_cross = axis.cross(surf.Axis) + if vector_cross == vector_nulo and isInPlane(position, surf): return True elif str(surf) == "" and kind_surf == "": dir = surf.Axis rad = surf.Radius pnt = surf.Center - vector_cross = Axis.cross(surf.Axis) + vector_cross = axis.cross(surf.Axis) if ( vector_cross == vector_nulo - and Radius == rad - and isInLine(Center, dir, pnt) + and radius == rad + and isInLine(center, dir, pnt) ): return True elif str(surf) == "" and kind_surf == "": @@ -222,81 +222,81 @@ def isInFaces(face, Faces): punta = surf.Apex semiangle = surf.SemiAngle if ( - Axis.isEqual(dir, 1e-5) - and Apex.isEqual(punta, 1e-5) - and (SemiAngle - semiangle) < 1e-6 + axis.isEqual(dir, 1e-5) + and apex.isEqual(punta, 1e-5) + and (semi_angle - semiangle) < 1e-6 ): return True elif str(surf)[0:6] == "Sphere" and kind_surf[0:6] == "Sphere": # corresponding logic for sphere rad = surf.Radius pnt = surf.Center - if Center == pnt and Radius == rad: + if center == pnt and radius == rad: return True elif str(surf) == "" and kind_surf == "": # corresponding logic for Torus - radMaj = surf.MajorRadius - radMin = surf.MinorRadius + rad_maj = surf.MajorRadius + rad_min = surf.MinorRadius pnt = surf.Center dir = surf.Axis if ( - Axis.isEqual(dir, 1e-5) - and Center.isEqual(pnt, 1e-5) - and (MajorRadius - radMaj) < 1e-6 - ) and (MinorRadius - radMin) < 1e-6: + axis.isEqual(dir, 1e-5) + and center.isEqual(pnt, 1e-5) + and (major_radius - rad_maj) < 1e-6 + ) and (minor_radius - rad_min) < 1e-6: return True return False -def isInFaces2(face, Faces): +def isInFaces2(face, faces): - if Faces == []: + if faces == []: return False vector_nulo = FreeCAD.Vector(0, 0, 0) surface = face kind_surf = face.type if kind_surf == "": - Axis = surface.Axis - Position = surface.Position + axis = surface.Axis + position = surface.Position elif kind_surf == "": - Axis = surface.Axis - Radius = surface.Radius - Center = surface.Center + axis = surface.Axis + radius = surface.Radius + center = surface.Center elif kind_surf == "": - Axis = surface.Axis - Apex = surface.Apex - SemiAngle = surface.SemiAngle + axis = surface.Axis + apex = surface.Apex + semi_angle = surface.SemiAngle elif kind_surf[0:6] == "Sphere": - Center = surface.Center - Radius = surface.Radius + center = surface.Center + radius = surface.Radius elif kind_surf == "": - Axis = surface.Axis - Center = surface.Center - MajorRadius = surface.MajorRadius - MinorRadius = surface.MinorRadius + axis = surface.Axis + center = surface.Center + major_radius = surface.MajorRadius + minor_radius = surface.MinorRadius - for elem in Faces: + for elem in faces: ##print surf if elem.type == "" and kind_surf == "": - vector_cross = Axis.cross(elem.Axis) - if vector_cross == vector_nulo and isInPlane(Position, elem.Surface): + vector_cross = axis.cross(elem.Axis) + if vector_cross == vector_nulo and isInPlane(position, elem.Surface): # if (isParallel(elem.Axis,elem.Surface.Axis) and isInPlane(Position,elem.Surface)): return True elif elem.type == "" and kind_surf == "": dir = elem.Axis rad = elem.Radius pnt = elem.Center - vector_cross = Axis.cross(elem.Axis) + vector_cross = axis.cross(elem.Axis) if ( vector_cross == vector_nulo - and Radius == rad - and isInLine(Center, dir, pnt) + and radius == rad + and isInLine(center, dir, pnt) ): return True elif elem.type == "" and kind_surf == "": @@ -305,27 +305,27 @@ def isInFaces2(face, Faces): punta = elem.Apex semiangle = elem.SemiAngle if ( - Axis.isEqual(dir, 1e-5) - and Apex.isEqual(punta, 1e-5) - and (SemiAngle - semiangle) < 1e-6 + axis.isEqual(dir, 1e-5) + and apex.isEqual(punta, 1e-5) + and (semi_angle - semiangle) < 1e-6 ): return True elif elem.type == "Sphere" and kind_surf == "Sphere": # corresponding logic for sphere rad = elem.Radius pnt = elem.Center - if Center == pnt and Radius == rad: + if center == pnt and radius == rad: return True elif elem.type == "" and kind_surf == "": # corresponding logic for Torus - radMaj = elem.MajorRadius - radMin = elem.MinorRadius + rad_maj = elem.MajorRadius + rad_min = elem.MinorRadius pnt = elem.Center dir = elem.Axis if ( - Axis.isEqual(dir, 1e-5) - and Center.isEqual(pnt, 1e-5) - and (MajorRadius - radMaj) < 1e-6 - ) and (MinorRadius - radMin) < 1e-6: + axis.isEqual(dir, 1e-5) + and center.isEqual(pnt, 1e-5) + and (major_radius - rad_maj) < 1e-6 + ) and (minor_radius - rad_min) < 1e-6: return True return False diff --git a/src/geouned/GEOUNED/Utils/Functions.py b/src/geouned/GEOUNED/Utils/Functions.py index baad95f9..9a6b3562 100644 --- a/src/geouned/GEOUNED/Utils/Functions.py +++ b/src/geouned/GEOUNED/Utils/Functions.py @@ -451,7 +451,7 @@ def addPlane(self, plane, fuzzy=False): p.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, fuzzy=(fuzzy, p.Index), ): addPlane = False @@ -473,7 +473,7 @@ def addPlane(self, plane, fuzzy=False): p.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, fuzzy=(fuzzy, p.Index), ): addPlane = False @@ -495,7 +495,7 @@ def addPlane(self, plane, fuzzy=False): p.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, fuzzy=(fuzzy, p.Index), ): addPlane = False @@ -517,7 +517,7 @@ def addPlane(self, plane, fuzzy=False): p.Surf, dtol=tol.pln_distance, atol=tol.pln_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, fuzzy=(fuzzy, p.Index), ): addPlane = False @@ -544,7 +544,7 @@ def addCylinder(self, cyl, fuzzy=False): c.Surf, dtol=tol.cyl_distance, atol=tol.cyl_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, fuzzy=(fuzzy, c.Index), ): addCyl = False @@ -570,7 +570,7 @@ def addCone(self, cone): c.Surf, dtol=tol.kne_distance, atol=tol.kne_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): addCone = False index = c.Index @@ -590,7 +590,7 @@ def addSphere(self, sph): addSphere = True for i, s in enumerate(self["Sph"]): if BF.isSameSphere( - sph.Surf, s.Surf, tol.sph_distance, relTol=tol.relativeTol + sph.Surf, s.Surf, tol.sph_distance, rel_tol=tol.relativeTol ): addSphere = False index = s.Index @@ -614,7 +614,7 @@ def addTorus(self, tor): s.Surf, dtol=tol.tor_distance, atol=tol.tor_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): addTorus = False index = s.Index diff --git a/src/geouned/GEOUNED/Utils/Geometry_GU.py b/src/geouned/GEOUNED/Utils/Geometry_GU.py index 87af49f9..ff3b70ee 100644 --- a/src/geouned/GEOUNED/Utils/Geometry_GU.py +++ b/src/geouned/GEOUNED/Utils/Geometry_GU.py @@ -126,7 +126,7 @@ def __sameTorusSurf__(self, torusList): self.Faces[j].Surface, dtol=tol.tor_distance, atol=tol.tor_angle, - relTol=tol.relativeTol, + rel_tol=tol.relativeTol, ): current.append(j) for c in current: @@ -169,17 +169,17 @@ def __mergeNoPeriodicUV__(self, parameter, faceList): i1 = 2 i2 = 4 - Vmin, Vmax = self.Faces[faceList[0]].ParameterRange[i1:i2] + v_min, v_max = self.Faces[faceList[0]].ParameterRange[i1:i2] for face in faceList[1:]: V0, V1 = self.Faces[face].ParameterRange[i1:i2] - Vmin = min(Vmin, V0) - Vmax = max(Vmax, V1) - mergedParams = (False, (Vmin, Vmax)) + v_min = min(v_min, V0) + v_max = max(v_max, V1) + mergedParams = (False, (v_min, v_max)) return mergedParams def __mergePeriodicUV__(self, parameter, faceList): - twoPi = 2.0 * math.pi + two_pi = 2.0 * math.pi if parameter == "U": i1 = 0 i2 = 2 @@ -197,23 +197,23 @@ def __mergePeriodicUV__(self, parameter, faceList): params.sort() V0 = params[0][0] V1 = params[-1][1] - if arcLength >= twoPi * (1.0 - tol.relativePrecision): - mergedParams = (True, (V0, V0 + twoPi)) + if arcLength >= two_pi * (1.0 - tol.relativePrecision): + mergedParams = (True, (V0, V0 + two_pi)) else: if isSameValue(V0, 0.0, tol.relativePrecision) and isSameValue( - V1, twoPi, tol.relativePrecision + V1, two_pi, tol.relativePrecision ): for i in range(len(params) - 1): if not isSameValue( params[i][1], params[i + 1][0], tol.relativePrecision ): break - Vmin = params[i + 1][0] - twoPi - Vmax = params[i][1] + v_min = params[i + 1][0] - two_pi + v_max = params[i][1] else: - Vmin = params[0][0] - Vmax = params[-1][1] - mergedParams = (False, (Vmin, Vmax)) + v_min = params[0][0] + v_max = params[-1][1] + mergedParams = (False, (v_min, v_max)) return mergedParams diff --git a/src/geouned/GEOUNED/Utils/booleanFunction.py b/src/geouned/GEOUNED/Utils/booleanFunction.py index 98b2ca7a..f5ef3217 100644 --- a/src/geouned/GEOUNED/Utils/booleanFunction.py +++ b/src/geouned/GEOUNED/Utils/booleanFunction.py @@ -80,21 +80,21 @@ def append(self, *seq): self.elements.append(s) self.level = max(self.level, level + 1) - def assign(self, Seq): + def assign(self, seq): """Assign the BoolSequence Seq to the self instance BoolSequence""" - if type(Seq) is bool: + if type(seq) is bool: self.operator == "AND" - self.elements = Seq + self.elements = seq self.level = -1 return - self.operator = Seq.operator - self.elements = Seq.elements - self.level = Seq.level + self.operator = seq.operator + self.elements = seq.elements + self.level = seq.level - def update(self, Seq, pos): + def update(self, seq, pos): if len(pos) == 0: - self.assign(Seq) + self.assign(seq) return elif len(pos) == 1: base = self @@ -106,13 +106,13 @@ def update(self, Seq, pos): for i in reversed(indexes): del base.elements[i] - if type(Seq.elements) is bool: - base.elements = Seq.elements + if type(seq.elements) is bool: + base.elements = seq.elements base.level = -1 else: - base.append(Seq) + base.append(seq) base.joinOperators() - self.clean(selfLevel=True) + self.clean(self_level=True) return def getElement(self, pos): @@ -179,85 +179,85 @@ def simplifySequence(self, CT=None): self.clean() return - surfNames = self.getSurfacesNumbers() - if not surfNames: + surf_names = self.getSurfacesNumbers() + if not surf_names: return - newNames = surfNames - for valname in surfNames: - if valname in newNames: + newNames = surf_names + for val_name in surf_names: + if val_name in newNames: if CT is None: - trueSet = {abs(valname): True} - falseSet = {abs(valname): False} + true_set = {abs(val_name): True} + false_set = {abs(val_name): False} else: - trueSet, falseSet = CT.getConstraintSet(valname) + true_set, false_set = CT.getConstraintSet(val_name) - if not self.doFactorize(valname, trueSet, falseSet): + if not self.doFactorize(val_name, true_set, false_set): continue - self.factorize(valname, trueSet, falseSet) + self.factorize(val_name, true_set, false_set) if type(self.elements) is bool: return newNames = self.getSurfacesNumbers() - def doFactorize(self, valname, trueSet, falseSet): + def doFactorize(self, val_name, true_set, false_set): """For level 0 sequence check if the factorization would lead to a simplification.""" if self.level > 0: return True - if trueSet is None and falseSet is None: - print(f"{valname} is not true nor false") + if true_set is None and false_set is None: + print(f"{val_name} is not true nor false") return False - if trueSet is None or falseSet is None: + if true_set is None or false_set is None: return True - valSet = self.getSurfacesNumbers() - TSet = set(trueSet.keys()) & valSet - FSet = set(falseSet.keys()) & valSet + val_set = self.getSurfacesNumbers() + t_set = set(true_set.keys()) & val_set + f_set = set(false_set.keys()) & val_set - if len(TSet) == 1 and len(FSet) == 1: + if len(t_set) == 1 and len(f_set) == 1: return False value = None for val in self.elements: - if abs(val) == valname: + if abs(val) == val_name: value = val break if value is None: return False - if len(TSet) == 1: + if len(t_set) == 1: if self.operator == "AND": - # if value > 0 and TSet[valname] or value < 0 and not TSet[valname] : return False + # if value > 0 and t_set[val_name] or value < 0 and not t_set[val_name] : return False if value > 0: return False # TrueSet[Valname] always True else: - # if value < 0 and TSet[valname] or value > 0 and not TSet[valname] : return False + # if value < 0 and t_set[val_name] or value > 0 and not t_set[val_name] : return False if value < 0: return False - elif len(FSet) == 1: + elif len(f_set) == 1: if self.operator == "AND": - # if value > 0 and FSet[valname] or value < 0 and not FSet[valname] : return False + # if value > 0 and f_set[val_name] or value < 0 and not f_set[val_name] : return False if value < 0: return False else: - # if value < 0 and FSet[valname] or value > 0 and not FSet[valname] : return False + # if value < 0 and f_set[val_name] or value > 0 and not f_set[val_name] : return False if value > 0: return False return True - # check if level 0 sequence have oposite value a & -a = 0 , a|-a = 1 + # check if level 0 sequence have opposite value a & -a = 0 , a|-a = 1 # return the value of the sequence None(unknown), True, False def check(self, level0=False): """Check BoolSequence in level 0 have oposite values a & -a = 0 , a|-a = 1.""" if type(self.elements) is bool: return self.elements if self.level == 0: - signedSurf = set(self.elements) - surfname = self.getSurfacesNumbers() - if len(signedSurf) == len(surfname): + signed_surf = set(self.elements) + surf_name = self.getSurfacesNumbers() + if len(signed_surf) == len(surf_name): return None # means same surface has not positive and negative value elif self.operator == "AND": self.elements = False @@ -269,7 +269,7 @@ def check(self, level0=False): return True elif not level0: self.groupSingle() - noneVal = False + none_val = False for e in reversed(self.elements): e.check() if type(e.elements) is bool: @@ -278,7 +278,7 @@ def check(self, level0=False): res = None if res is None: - noneVal = True + none_val = True elif self.operator == "AND" and res is False: self.level = -1 self.elements = False @@ -290,7 +290,7 @@ def check(self, level0=False): else: self.elements.remove(e) - if noneVal: + if none_val: return None elif self.operator == "AND": self.level = -1 @@ -322,15 +322,15 @@ def substitute(self, var, val): else: if name == e: - boolValue = val + bool_value = val else: - boolValue = not val + bool_value = not val - if self.operator == "AND" and not boolValue: + if self.operator == "AND" and not bool_value: self.elements = False self.level = -1 return - elif self.operator == "OR" and boolValue: + elif self.operator == "OR" and bool_value: self.elements = True self.level = -1 return @@ -345,18 +345,18 @@ def substitute(self, var, val): self.level = -1 return - self.clean(selfLevel=True) + self.clean(self_level=True) self.check(level0=True) - self.joinOperators(selfLevel=True) + self.joinOperators(self_level=True) - def clean(self, selfLevel=False): + def clean(self, self_level=False): """Remove sequences whom elements are boolean values instead of list.""" if type(self.elements) is bool: return self.elements for e in reversed(self.elements): if type(e) is int: continue - eVal = e if selfLevel else e.clean() + eVal = e if self_level else e.clean() if type(eVal) is not bool: eVal = eVal.elements @@ -381,11 +381,11 @@ def clean(self, selfLevel=False): else: return self - def joinOperators(self, selfLevel=False): + def joinOperators(self, self_level=False): """Join redundant operators in found in the sequence.""" if type(self.elements) is bool: return - self.clean(selfLevel=True) + self.clean(self_level=True) self.levelUpdate() if self.level == 0: return @@ -425,7 +425,7 @@ def joinOperators(self, selfLevel=False): self.check() return - if not selfLevel: + if not self_level: if type(self.elements) is bool: return for e in self.elements: @@ -433,11 +433,11 @@ def joinOperators(self, selfLevel=False): def getSubSequence(self, setIn): if type(setIn) is set: - valSet = setIn + val_set = setIn elif type(setIn) is int: - valSet = {setIn} + val_set = {setIn} else: - valSet = set(setIn.keys()) + val_set = set(setIn.keys()) if self.level == 0: return ([], self) @@ -447,41 +447,41 @@ def getSubSequence(self, setIn): for pos, e in enumerate(self.elements): surf = e.getSurfacesNumbers() - if len(surf & valSet) != 0: + if len(surf & val_set) != 0: subSeq.append(e) position.append(pos) if len(position) == 1 and subSeq.elements[0].level > 0: - subList, subSeq = subSeq.elements[0].getSubSequence(valSet) + subList, subSeq = subSeq.elements[0].getSubSequence(val_set) subList.insert(0, position[0]) else: subList = [position] return subList, subSeq - def factorize(self, valname, trueSet, falseSet): + def factorize(self, valname, true_set, false_set): """Make the factorization of the Sequence on variable valname using Shannon's theorem.""" - if trueSet is None: # valname cannot take True value - falseFunc = self.evaluate(falseSet) + if true_set is None: # valname cannot take True value + falseFunc = self.evaluate(false_set) self.assign(falseFunc) return True - if falseSet is None: # valname cannot take false value - trueFunc = self.evaluate(trueSet) + if false_set is None: # valname cannot take false value + trueFunc = self.evaluate(true_set) self.assign(trueFunc) return True - valSet = set(trueSet.keys()) - valSet.update(falseSet.keys()) - pos, subSeq = self.getSubSequence(valSet) + val_set = set(true_set.keys()) + val_set.update(false_set.keys()) + pos, subSeq = self.getSubSequence(val_set) updt = True if len(pos) == 0: subSeq = self updt = False - trueFunc = subSeq.evaluate(trueSet) + trueFunc = subSeq.evaluate(true_set) - falseFunc = subSeq.evaluate(falseSet) + falseFunc = subSeq.evaluate(false_set) if trueFunc is False: newSeq = BoolSequence(operator="AND") @@ -492,7 +492,7 @@ def factorize(self, valname, trueSet, falseSet): newSeq.level = -1 else: newSeq.append(-valname, falseFunc) - newSeq.joinOperators(selfLevel=True) + newSeq.joinOperators(self_level=True) if updt: self.update(newSeq, pos) @@ -509,7 +509,7 @@ def factorize(self, valname, trueSet, falseSet): newSeq.append(valname) else: newSeq.append(valname, falseFunc) - newSeq.joinOperators(selfLevel=True) + newSeq.joinOperators(self_level=True) if updt: self.update(newSeq, pos) @@ -526,7 +526,7 @@ def factorize(self, valname, trueSet, falseSet): newSeq.level = -1 else: newSeq.append(valname, trueFunc) - newSeq.joinOperators(selfLevel=True) + newSeq.joinOperators(self_level=True) if updt: self.update(newSeq, pos) else: @@ -542,7 +542,7 @@ def factorize(self, valname, trueSet, falseSet): newSeq.append(-valname) else: newSeq.append(-valname, trueFunc) - newSeq.joinOperators(selfLevel=True) + newSeq.joinOperators(self_level=True) if updt: self.update(newSeq, pos) else: @@ -712,12 +712,12 @@ def outterTerms(expression, value="number"): terms = [] pos = 0 while True: - newpos = expr.find(":", pos) - if newpos == -1: + new_pos = expr.find(":", pos) + if new_pos == -1: terms.append(expression[pos:].strip()) break - terms.append(expression[pos:newpos].strip()) - pos = newpos + 1 + terms.append(expression[pos:new_pos].strip()) + pos = new_pos + 1 return (terms, "OR") else: terms = [] @@ -736,14 +736,14 @@ def redundant(m, geom): term = m.group() # Find first valid character at the left of the parenthese - leftOK = True + left_ok = True left = m.start() - 1 while left > -1: if geom[left] in ("\n", "C", "$", " "): left -= 1 else: if geom[left] not in ("(", ":"): - leftOK = False + left_ok = False break # check if no ':' (or) are inside the parenthese @@ -752,21 +752,21 @@ def redundant(m, geom): return True # Find first valid character at the right of the parenthese - rightOK = True + right_ok = True right = m.end() while right < len(geom): if geom[right] in ("\n", "C", "$", " "): right += 1 else: if geom[right] not in (")", ":"): - rightOK = False + right_ok = False break # if parentheses are like: # {( or : } ( ....... ) {) or :} # parentheses are redundants - if leftOK and rightOK: + if left_ok and right_ok: return True else: return False