{"action":"created","issue":{"url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/3","labels_url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/3/comments","events_url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/3/events","html_url":"https://github.com/web-cat/sofia-graphics/issues/3","id":78394539,"number":3,"title":"BayazitDecomposer: IndexOutOfBoundsException for a triangle using PolygonShape","user":{"login":"rjschof","id":11164693,"avatar_url":"https://avatars.githubusercontent.com/u/11164693?v=3","gravatar_id":"","url":"https://api.github.com/users/rjschof","html_url":"https://github.com/rjschof","followers_url":"https://api.github.com/users/rjschof/followers","following_url":"https://api.github.com/users/rjschof/following{/other_user}","gists_url":"https://api.github.com/users/rjschof/gists{/gist_id}","starred_url":"https://api.github.com/users/rjschof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjschof/subscriptions","organizations_url":"https://api.github.com/users/rjschof/orgs","repos_url":"https://api.github.com/users/rjschof/repos","events_url":"https://api.github.com/users/rjschof/events{/privacy}","received_events_url":"https://api.github.com/users/rjschof/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-20T06:28:18Z","updated_at":"2015-05-21T16:18:42Z","closed_at":null,"body":"I was working on a new design for the TriangleShape class, as you suggested. I ran into the following problem. Also, I had another idea for the design of the class, which I will explain on the page for the pull request shortly. \r\n\r\nI used the following code to try and create an instance of a PolygonShape object on the screen for an app: \r\n```java\r\nPolygonShape pShape = new PolygonShape(50, 50, 25, 100, 75, 100);\r\npShape.setFillColor(Color.maroon);\r\npShape.setColor(Color.black);\r\nadd(pShape);\r\n```\r\n\r\nThe following stack trace was printed as a result of executing the above code. I spent some time attempting to diagnose the problem, but I ultimately do not know enough about how this class is supposed to work to come up with a solution myself. I feel like the problem occurs because the class that calls it (Polygon.java) is attempting to decompose something that is already in its simplest form. That's just my guess, though.\r\n```\r\n FATAL EXCEPTION: main\r\n Process: org.awesomeco.trianglesmash, PID: 2581\r\n java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1\r\n     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)\r\n     at java.util.ArrayList.get(ArrayList.java:308)\r\n     at sofia.graphics.Polygon.get(Polygon.java:215)\r\n     at sofia.graphics.internal.BayazitDecomposer.isReflex(BayazitDecomposer.java:391)\r\n     at sofia.graphics.internal.BayazitDecomposer.decompose(BayazitDecomposer.java:91)\r\n     at sofia.graphics.internal.BayazitDecomposer.decompose(BayazitDecomposer.java:230)\r\n     at sofia.graphics.internal.BayazitDecomposer.<init>(BayazitDecomposer.java:53)\r\n     at sofia.graphics.Polygon.convexDecomposition(Polygon.java:195)\r\n     at org.awesomeco.trianglesmash.PolygonShape.createFixtures(PolygonShape.java:143)\r\n     at sofia.graphics.Shape$1.run(Shape.java:100)\r\n     at sofia.graphics.ShapeField.runOnceUnlocked(ShapeField.java:617)\r\n     at sofia.graphics.Shape.createB2Body(Shape.java:96)\r\n     at sofia.graphics.ShapeField.handleShapesAdded(ShapeField.java:571)\r\n     at sofia.graphics.ShapeField.add(ShapeField.java:150)\r\n     at sofia.graphics.ShapeView.add(ShapeView.java:399)\r\n     at sofia.app.ShapeScreen.add(ShapeScreen.java:160)\r\n     at org.awesomeco.trianglesmash.TriangleSmashScreen.initialize(TriangleSmashScreen.java:61)\r\n     at java.lang.reflect.Method.invoke(Native Method)\r\n     at java.lang.reflect.Method.invoke(Method.java:372)\r\n     at sofia.internal.events.EventDispatcher$MethodTransformer.invoke(EventDispatcher.java:474)\r\n     at sofia.internal.events.EventDispatcher.invokeTransformer(EventDispatcher.java:136)\r\n     at sofia.internal.events.EventDispatcher.dispatch(EventDispatcher.java:109)\r\n     at sofia.app.internal.ScreenMixin.invokeInitialize(ScreenMixin.java:561)\r\n     at sofia.app.Screen$1.run(Screen.java:199)\r\n     at android.os.Handler.handleCallback(Handler.java:739)\r\n     at android.os.Handler.dispatchMessage(Handler.java:95)\r\n     at android.os.Looper.loop(Looper.java:135)\r\n     at android.app.ActivityThread.main(ActivityThread.java:5257)\r\n     at java.lang.reflect.Method.invoke(Native Method)\r\n     at java.lang.reflect.Method.invoke(Method.java:372)\r\n     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)\r\n     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/comments/104341797","html_url":"https://github.com/web-cat/sofia-graphics/issues/3#issuecomment-104341797","issue_url":"https://api.github.com/repos/web-cat/sofia-graphics/issues/3","id":104341797,"user":{"login":"allevato","id":1062427,"avatar_url":"https://avatars.githubusercontent.com/u/1062427?v=3","gravatar_id":"","url":"https://api.github.com/users/allevato","html_url":"https://github.com/allevato","followers_url":"https://api.github.com/users/allevato/followers","following_url":"https://api.github.com/users/allevato/following{/other_user}","gists_url":"https://api.github.com/users/allevato/gists{/gist_id}","starred_url":"https://api.github.com/users/allevato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allevato/subscriptions","organizations_url":"https://api.github.com/users/allevato/orgs","repos_url":"https://api.github.com/users/allevato/repos","events_url":"https://api.github.com/users/allevato/events{/privacy}","received_events_url":"https://api.github.com/users/allevato/received_events","type":"User","site_admin":false},"created_at":"2015-05-21T16:18:42Z","updated_at":"2015-05-21T16:18:42Z","body":"Unfortunately I don't think I'll have time in the foreseeable future to take a deep look into why you're getting that error; it's been a while since I've looked at that code, and it was ported from an example I found elsewhere on line (which describes the algorithm in more detail).\r\n\r\nThat being said, it's possible to work around it in this particular (triangle) case. For any three points there is a single unique triangle that passes through them, and a triangle can never be concave. That means we wouldn't actually need to run the decomposition in that situation. (It wouldn't surprise me if some part of the Bayazit algorithm, at least at the top level, assumes that it has more vertices due to that fact. Or it could just be buggy :) )\r\n\r\nSo a reasonable fix (which would be a bit more efficient too, in all likelihood) would be to simply not run the decomposition if the polygon has less than 4 vertices. In that case, the decomposition would simply be the polygon itself; the best place to do this would be to add a check in `Polygon.convexDecomposition` to return a singleton list containing a copy of `this`."}}