-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: FilterOptions type error #481
base: main
Are you sure you want to change the base?
Conversation
In general, this is a good change. While this PR satisfies the types, it does not, for instance, actually pass any of those parameters to constructor's |
Indeed, I overlooked that. How about this modification? export class AdjustmentFilter extends Filter
{
......
constructor(options?: AdjustmentFilterOptions)
{
options = { ...AdjustmentFilter.DEFAULT_OPTIONS, ...options };
const gpuProgram = GpuProgram.from({
vertex: {
source: wgslVertex,
entryPoint: 'mainVertex',
},
fragment: {
source,
entryPoint: 'mainFragment',
},
});
const glProgram = GlProgram.from({
vertex,
fragment,
name: 'adjustment-filter'
});
super({
+ ...options,
gpuProgram,
glProgram,
resources: {
adjustmentUniforms: {
uGamma: { value: options.gamma, type: 'f32' },
uContrast: { value: options.contrast, type: 'f32' },
uSaturation: { value: options.saturation, type: 'f32' },
uBrightness: { value: options.brightness, type: 'f32' },
uColor: {
value: [
options.red,
options.green,
options.blue,
options.alpha,
],
type: 'vec4<f32>',
},
}
},
});
this.uniforms = this.resources.adjustmentUniforms.uniforms;
}
......
}
|
We probably want more something like this: const { contrast, gamma, saturation, brightness, red, blue, green, alpha, ...rest } = { ...AdjustmentFilter.DEFAULT_OPTIONS, ...options };
//...
super({
glProgram,
gpuProgram,
resources,
...rest,
}) This is a bigger change, but using the rest args allows us to only pass in the relevant props to super, as opposed to everything in options. I also prefer adding rest args last in super as it allows a user to override things like the programs or resources for debugging purposes. |
Got it, do you mind if I go ahead and finish this part? |
Please! And thank you! This will be great for setting resolution and other base Filter props. |
@oubenruing might you be able to take a look at this? If you don't no worries, I'd be happy to wrap it up. Let me know. |
Hi @bigtimebuddy. Sorry for the delayed reply. I can take care of it. Would it be alright if you give me a day or two? I've been busy with other things recently. |
Hi @bigtimebuddy , In the latest commit, I've destructured options and passed the rest parameters to super. 1. Object.assign in the custructor Most filters use Object.assign(this, options); at the end of the constructor to add properties. Do you think I should do anything else here to exclude the rest parameters that are passed to super? 2. About DEFAULT_OPTIONS`s type DEFAULT_OPTIONS has an explicit type, but the fields in the options type are all optional. // ...
export interface AdjustmentFilterOptions extends FilterOptions
{
gamma?: number;
contrast?: number;
//...
} This could lead to the destructured properties being undefined, even though DEFAULT_OPTIONS clearly provides values. I was thinking it might be a good idea to remove the type from DEFAULT_OPTIONS so that TypeScript can better infer the types. What do you think? /** Default values for options. */
- public static readonly DEFAULT_OPTIONS : AdjustmentFilterOptions = {
+ public static readonly DEFAULT_OPTIONS = {
gamma: 1,
contrast: 1,
saturation: 1,
brightness: 1,
red: 1,
green: 1,
blue: 1,
alpha: 1,
}; |
|
Changes are done. Please review. Thanks! |
Fixes #480
Make the option`s interface of filters extends from FilterOptions.