{"action":"created","issue":{"url":"https://api.github.com/repos/moagrius/TileView/issues/304","repository_url":"https://api.github.com/repos/moagrius/TileView","labels_url":"https://api.github.com/repos/moagrius/TileView/issues/304/labels{/name}","comments_url":"https://api.github.com/repos/moagrius/TileView/issues/304/comments","events_url":"https://api.github.com/repos/moagrius/TileView/issues/304/events","html_url":"https://github.com/moagrius/TileView/issues/304","id":154071168,"number":304,"title":"Real to relative coordinates","user":{"login":"peterLaurence","id":15638794,"avatar_url":"https://avatars.githubusercontent.com/u/15638794?v=3","gravatar_id":"","url":"https://api.github.com/users/peterLaurence","html_url":"https://github.com/peterLaurence","followers_url":"https://api.github.com/users/peterLaurence/followers","following_url":"https://api.github.com/users/peterLaurence/following{/other_user}","gists_url":"https://api.github.com/users/peterLaurence/gists{/gist_id}","starred_url":"https://api.github.com/users/peterLaurence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterLaurence/subscriptions","organizations_url":"https://api.github.com/users/peterLaurence/orgs","repos_url":"https://api.github.com/users/peterLaurence/repos","events_url":"https://api.github.com/users/peterLaurence/events{/privacy}","received_events_url":"https://api.github.com/users/peterLaurence/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-05-10T18:10:54Z","updated_at":"2016-05-11T06:00:30Z","closed_at":null,"body":"I am embarrassed because i just found an error in the newly added `translateAbsoluteToRelativeX` and `translateAbsoluteToRelativeY`, despite the code review.\r\nI was astonished to get the same relative coordinates whatever the real coordinates were given to those methods. Look at this :\r\n```\r\npublic double translateAbsoluteToRelativeY( int y ) {\r\n  double factor = y / mHeight;\r\n  return mTop + (factor * mDiffY);\r\n```\r\n\r\n`y` and `mHeight` are `int`s. And, in a normal use case (touch inside the TileView), `y` < `mHeight`. So `factor` = 0 and we always get `mTop` as returned value. Sorry i haven't noticed that Mike.\r\n\r\nOn top of that, the recent comment of @ohoedneboe should have warned us :\r\n\r\n> Just one comment on issue #288. I see that there has been added methods\r\npublic double translateAndScaleAbsoluteToRelativeY( int y, float scale ) \r\nbut do these functions really take the pan into effect?\r\nI did my own implementation of this, like described in the issue thread, but I had to add the pan factor, or I got the wrong answer. My method looked like this \r\npublic double realToRelativeY(int y, float scale, double relativeOffset)\r\n\r\nSo, @ohoedneboe, i suppose you have your own implementation of those methods, right? Because right now, the official methods can't work.\r\n\r\nOnce i fixed that issue, by just having :\r\n\r\n```\r\npublic double translateAbsoluteToRelativeY( int y ) {\r\n  return mTop + (y * mDiffY / mHeight);\r\n}\r\n```\r\ni noticed a precision loss when getting relative coordinates from a scale different than 1 **and** when working with detail levels defined for scales > 1\r\nFor example, let's say we have a map which dimension at scale 1 is 1000px width and 1000px height.\r\nWe zoom to scale 30 so the dimensions of the map is 30000px squared.\r\nWe touch the map somewhere at X=15000px\r\nFollowing the current implementation, the unscaled X is (int) (15000 / 30 + 0.5) = 500\r\nSo we see that to get a difference of 1px to the unscaled X, the delta of two touch event must be greater than (1 - 0.5) * 30 = 15px\r\nIf the second touch is at 15014px, we will get the same relative coordinates.\r\nThis particular issue won't happen for detail levels defined for scales < 1.\r\n\r\nFixing this was simple but required a **breaking change** :\r\n\r\n```\r\npublic double translateAndScaleAbsoluteToRelativeY( float y, float scale ) {\r\n  return translateAbsoluteToRelativeY( y / scale);\r\n}\r\n```\r\n\r\n```\r\npublic double translateAbsoluteToRelativeY( float y ) {\r\n  return mTop + (y * mDiffY / mHeight);\r\n}\r\n```\r\n\r\nAlso, when getting a `MotionEvent`, `getX` and `getY` already return `float` values, so no more cast is required.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/moagrius/TileView/issues/comments/218369288","html_url":"https://github.com/moagrius/TileView/issues/304#issuecomment-218369288","issue_url":"https://api.github.com/repos/moagrius/TileView/issues/304","id":218369288,"user":{"login":"ohoedneboe","id":11346689,"avatar_url":"https://avatars.githubusercontent.com/u/11346689?v=3","gravatar_id":"","url":"https://api.github.com/users/ohoedneboe","html_url":"https://github.com/ohoedneboe","followers_url":"https://api.github.com/users/ohoedneboe/followers","following_url":"https://api.github.com/users/ohoedneboe/following{/other_user}","gists_url":"https://api.github.com/users/ohoedneboe/gists{/gist_id}","starred_url":"https://api.github.com/users/ohoedneboe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ohoedneboe/subscriptions","organizations_url":"https://api.github.com/users/ohoedneboe/orgs","repos_url":"https://api.github.com/users/ohoedneboe/repos","events_url":"https://api.github.com/users/ohoedneboe/events{/privacy}","received_events_url":"https://api.github.com/users/ohoedneboe/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T06:00:29Z","updated_at":"2016-05-11T06:00:29Z","body":"Just a quick answer on the following question early in the thread:\r\n\"So, @ohoedneboe, i suppose you have your own implementation of those methods, right? Because right now, the official methods can't work.\"\r\n\r\nYes, I still have my own implementation of this, as it worked great, also with pan. Of course my problem will be that I have to merge in my changes as new versions of TileView comes out, but for now that is fine."}}