mercredi 21 juin 2017

Multiple if conditions depending on parameter

I have the following problem. I have a paramter frc_size. Depending on the size of fcr_size more distances have to be checked in the if conditions. Is there a way to handle that smart?. For example for fcr_size = 3 the if conditions would look like:

minusscore = 2

                for coords in full_box:

                        mindist = float("inf")



                        for m in range(len(lineSegmentPairs[0])):

                            newdist = dist(lineSegmentPairs[0][m], lineSegmentPairs[1][m], coords)

                            if newdist<mindist: 
                                mindist=newdist

                        if mindist <= radius :

                                val1 = int(sparse1.get(coords,"0")[0]) - minusscore
                                sparse1[coords] = [str(val1)]


                        elif mindist <= (radius +1) :
                                val1 = int(sparse1.get(coords,"0")[0]) + 3
                                sparse1[coords] = [str(val1)]


                        elif mindist <= (radius +2) :
                                val1 = int(sparse1.get(coords,"0")[0]) + 2
                                sparse1[coords] = [str(val1)]

                        elif mindist <= (radius +3) :
                                val1 = int(sparse1.get(coords,"0")[0]) + 1
                                sparse1[coords] = [str(val1)]



                        elif mindist > (radius +3) :
                                continue

But if the fcr_size would be 4, than a additional if condition would be necessary like:

                         elif mindist <= (radius +4) :
                                val1 = int(sparse1.get(coords,"0")[0]) + 1
                                sparse1[coords] = [str(val1)]

Aucun commentaire:

Enregistrer un commentaire