One of the things that makes sailboat racing so interesting/tactical/complicated/aggravating (depending on your point of view) is that the right-of-way between boats changes instantly when the relative positions of the boats hardly changes at all.
For instance: (i) a boat that is clear astern of another has to keep clear, but then moves forward a few inches and becomes overlapped to leeward and is immediately the right-of-way boat; or (ii) a port tack boat that tacks to leeward, or directly in front of a starboard tack boat immediately becomes the right-of-way boat when her tack is complete.
It is an important principle under the rules that a boat does not have to anticipate the action(s) of another boat; she only has to start to keep clear when the other boat becomes right-of-way. That means that when a boat gains right-of-way through her own action she must give the other boat enough room that the now give-way boat can take avoiding action.
In the two scenarios cited above:
If you gain right-of-way because of the other boat’s manoeuvre then there is no requirement for you to give that other boat room. That is why overtaking close to windward of another boat is a risky thing to do, as is tacking close to windward of another boat.
There are a number of World Sailing and RYA cases that consider gaining right-of-way situations which you can read. If you have further questions then contact your Regional Rules Advisor about talks and courses on the topic.
If you'd like Chris to give a talk on rules at your club please contact him