Skip to content

Factor transformations into position and area for shapes' accessible outputs - addresses #4721 #6122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

calebfoss
Copy link
Contributor

Addresses suggestion raised in #4721
Specifically this comment

Changes:

Currently, transformations are not taken into account for outputs generated through textOutput() or gridOutput(). This PR modifies _getPos and _getArea to be methods on the p5 prototype and to factor in the current transformations into their calculations.

You can see that in this example. Three squares are on the canvas in different positions with the square in the lower right being scaled down, but the text output describes only one shape because the arguments passed into square() are the same and because the color is the same.

Here's that same example with the build from this PR.

PR Checklist

@calebfoss
Copy link
Contributor Author

Tagging accessibility stewards @kungfuchicken, @cosmicbhejafry for feedback if you have a chance

if (args[1] < 0.4 * canvasHeight) {
p5.prototype._getPos = function (x, y) {
const untransformedPosition = new DOMPointReadOnly(x, y);
const currentTransform = this.drawingContext.getTransform();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might not work if this gets called when in WebGL mode. But if you detect WebGL mode, you can use new DOMMatrix(this._renderer.uMVMatrix.mat4) and the rest should work!

@calebfoss calebfoss force-pushed the transformations_for_accessible_outputs branch from 2dcdcc1 to 5a09fa4 Compare April 29, 2023 16:07
@calebfoss
Copy link
Contributor Author

calebfoss commented Apr 29, 2023

Thank you, @davepagurek! I forgot that the 2D primitive functions could also be called in WEBGL mode. I really appreciate you sharing how to get the transform matrix from the WEBGL renderer because I had no idea!

I've added a commit that accounts for WEBGL mode enough to not throw an error, but that brought me to other issues in WEBGL:

  1. Because (0, 0) is in the middle of the canvas by default, _getPos() is inaccurate as is
  2. The camera settings would affect the position of a shape on the canvas as well
  3. The area calculation would depend on the surface(s) facing the camera, their angle, and the camera settings
  4. 3D primitives are not yet supported by these accessible outputs

Currently in WEBGL (without this PR) 2D primitives get inaccurate descriptions, even without transformations.

I think generating these position and area descriptions for WEBGL would be a very big undertaking, and maybe a different format for descriptions would better fit WEBGL. In the meantime, I think it would make sense to modify textOutput() and gridOutput() to only work in 2D and to throw a friendly error if called in WEBGL (along with modification to documentation).

I'm happy to make those changes as well, if that sounds like a good plan. If so, would it be preferable for me to make those changes in a separate PR?

@davepagurek
Copy link
Contributor

Sure thing, this would be an improvement regardless of whether it works for WebGL mode! A follow-up PR sounds good to me.

@calebfoss calebfoss merged commit e4da699 into processing:main May 1, 2023
@calebfoss calebfoss deleted the transformations_for_accessible_outputs branch May 1, 2023 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants