soravux / skylibs

Python library to handle 360° environment maps
GNU Lesser General Public License v3.0
86 stars 29 forks source link

Fixes setBackgroundColor(...) #40

Closed IanMaquignaz closed 10 months ago

IanMaquignaz commented 1 year ago

Fixes bug where setBackgroundColor(...) crashes in the event of a channel mismatch.

Change list:

Note! Using setBackgroundColor(..., valid=None) results in the re-computation of valid using worldCoordinates(). This is VERY expensive and should be avoided.

N=1000
start = time.time()
for _ in range(N):
     # Original Implementation
     if mask.sum() > 0:
         e.data[np.tile(mask[:,:,None], (1, 1, e.data.shape[2]))] = np.tile(e.backgroundColor, (mask.sum(),))
end = time.time()
dt = (end-start) / N
print(dt)

start = time.time()
for _ in range(N):
     # New Implementation
     self.data[np.invert(valid)] = backgroundColor
end = time.time()
dt = (end-start) / N
print(dt)

Output

0.010673324823379517
0.005012984275817871