I think I get what you're saying; you're saying that if you walk into a patch of grass that happens to have a wild Pokemon battle, and that patch of grass also happens to be on a trainer's path, will the trainer notice you first (& therefore battle you) or will the wild battle happen first. Am I right?
If so, I've found that it's the Pokemon battle that comes first. After the battle, the trainer will then immediately notice you & challenge you.
I don't know if there's some kind of uniformity within the games, but I've only had this happen to me in older games and they're rather glitchy.