I was wondering the exact same thing when I transitioned to Modern in my current game, so I decided to do some testing. I picked only that legacy, and the science yield went up by 121, so it's definitely counting previous quarters. 121 / 3 = 40 quarters, which I found low. Just in my 3 first Settlements I counted 34!
I then assumed it doesn't count tiles with overbuildable buildings as a Quarter, so I went and counted the Ageless Quarters in my entire empire, which came to around 20 - not the 40 the game decided that I have.
Perhaps it also counts the City Center / Town Center as a Quarter? That would make sense as I had 19 settlements. I wanted to get to the bottom of this, so I popped out a Settler, founded a Town, and my Science yield increased by 3 - but this came from the Town Hall. I popped down an Ageless building with the Town Hall, which made
no impact on my yield.
All that work left me none the wiser
As for your last question, I purchased a City Park and a Grocer on the same tile, but my Science yield did
not increase.
I went one further, researched Steam Engine to get another Ageless building, and put that and the Grocer on the same tile. This time my Science yield
did increase by 3, so it definitely counts Quarters with only Ageless buildings in them.