That is also an option, but testing for a flag itself takes time (and adds a degree of complexity).
My preference for this sort of thing is to have an internal method (eg _setpixel) that gets called to do the real work once all sanity checks have been performed, and where appropriate to expose that in documentation with suitable warnings.
Quite often one method invokes other methods in the same class with parameters it has already checked for sanity, so the availability of such internal methods can also give a free speed boost even when external users do not invoke them directly.
|