Part of #118145. This adds a bunch of duplication, but it significantly simplifies the next step of specializing each filter operation per geometry type. That will reduce some of the logic duplication too by extracting it to separate shared functions.