Mechanism of self-association and filament capping by flagellar HAP2.