Skip to content

Commit fe416b3

Browse files
committed
If only I had *already declared a RootHalf constant*!
Also small optimisation tweaks.
1 parent baf3bb5 commit fe416b3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/flitter/render/window/models.pyx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ cdef class Trim(UnaryOperation):
686686
h = max(0, self.fillet+d)
687687
distance = min(-self.fillet, max(distance, d)) + sqrt(g*g + h*h)
688688
elif self.chamfer:
689-
distance = max(max(distance, d), (distance + self.chamfer + d)*sqrt(0.5))
689+
distance = max(max(distance, d), (distance + self.chamfer + d)*RootHalf)
690690
else:
691691
distance = max(distance, d)
692692
return distance
@@ -815,38 +815,41 @@ cdef class BooleanOperation(Model):
815815
d = (<Model>self.models[i]).signed_distance(x, y, z)
816816
if self.operation is 'union':
817817
if self.smooth:
818-
h = min(max(0, 0.5+0.5*(d-distance)/self.smooth), 1)
819-
distance = h*distance + (1-h)*d - self.smooth*h*(1-h)
818+
g = min(max(0, 0.5+0.5*(d-distance)/self.smooth), 1)
819+
h = 1-g
820+
distance = g*distance + h*d - self.smooth*g*h
820821
elif self.fillet:
821822
g = max(0, self.fillet-distance)
822823
h = max(0, self.fillet-d)
823824
distance = max(self.fillet, min(distance, d)) - sqrt(g*g + h*h)
824825
elif self.chamfer:
825-
distance = min(min(distance, d), (distance - self.chamfer + d)*sqrt(0.5))
826+
distance = min(min(distance, d), (distance - self.chamfer + d)*RootHalf)
826827
else:
827828
distance = min(distance, d)
828829
elif self.operation is 'intersect':
829830
if self.smooth:
830-
h = min(max(0, 0.5+0.5*(d-distance)/self.smooth), 1)
831-
distance = h*d + (1-h)*distance + self.smooth*h*(1-h)
831+
g = min(max(0, 0.5+0.5*(d-distance)/self.smooth), 1)
832+
h = 1-g
833+
distance = g*d + h*distance + self.smooth*g*h
832834
if self.fillet:
833835
g = max(0, self.fillet+distance)
834836
h = max(0, self.fillet+d)
835837
distance = min(-self.fillet, max(distance, d)) + sqrt(g*g + h*h)
836838
elif self.chamfer:
837-
distance = max(max(distance, d), (distance + self.chamfer + d)*sqrt(0.5))
839+
distance = max(max(distance, d), (distance + self.chamfer + d)*RootHalf)
838840
else:
839841
distance = max(distance, d)
840842
elif self.operation is 'difference':
841843
if self.smooth:
842-
h = min(max(0, 0.5+0.5*(-d-distance)/self.smooth), 1)
843-
distance = -h*d + (1-h)*distance + self.smooth*h*(1-h)
844+
g = min(max(0, 0.5+0.5*(-d-distance)/self.smooth), 1)
845+
h = 1-g
846+
distance = -g*d + h*distance + self.smooth*g*h
844847
if self.fillet:
845848
g = max(0, self.fillet+distance)
846849
h = max(0, self.fillet-d)
847850
distance = min(-self.fillet, max(distance, -d)) + sqrt(g*g + h*h)
848851
elif self.chamfer:
849-
distance = max(max(distance, -d), (distance + self.chamfer - d)*sqrt(0.5))
852+
distance = max(max(distance, -d), (distance + self.chamfer - d)*RootHalf)
850853
else:
851854
distance = max(distance, -d)
852855
return distance

0 commit comments

Comments
 (0)