Comments (7)
Thanks for the improvement suggestions!
toString() is kinda an exception to this "no allocations" rule, which is also stated on the JOML readme above the paragraph that you quoted, for the following reasons:
- toString() should only be used for debugging purposes (which is also the case why they use a formatter, in order to nicely align the columns when printing them on stdout/stderr)
- a client should not rely on toString() in its "hot path"
- by design, Object.toString() always allocates a String (and additionally an implicit StringBuffer in all but the most trivial cases)
Especially because of the last point we have lost anyway, because we cannot completely get rid of allocations in toString(), and because of the other points I saw no point in trying to make it allocate "the least amount" of memory.
But I went with another version of toString() taking a NumberFormat as parameter, which allows a client to externally specify how numbers should be formatted. Regarding String.format, we cannot currently use this unless we give up on being 1.4 compatible.
And if we take a look at String.format()'s source in a >= 1.5 JDK, we see that it also allocates a Formatter.
The vector and quaternion toString() methods make no use of formatting, because they need no number layouting.
from joml.
Regarding your last statement, I don't think vectors and quaternions "need no number layouting". It is currently a pain comparing them in the console (where I print one object every line), because the values don't align. I think it would not be much work but very useful especially for debugging to also have toString(NumberFormat)
methods for these classes.
from joml.
Thanks for your comment!
Please make a GitHub fork of JOML. There you can add any methods needed by you to it and afterwards make a GitHub Pull Request to have them included in the upstream.
Thanks!
from joml.
I've changed the formatting of the matrix values to really always align perfectly.
See: a69ab48 and 24ab853
from joml.
Looks a lot nicer now. However, the quaternions and AngleAxis4f still have the commas. Is this intended?
from joml.
I removed the commas in this pull request: #11.
from joml.
Closing this now, since with the advent of toString(NumberFormat), the client is now able to specify the format which avoids that allocation.
from joml.
Related Issues (20)
- Matrix3f class missing set(float m[], int off) method HOT 1
- Make Matrix4f element-fields "mxy" public like in Matrix3f HOT 1
- Matrix4f.getEulerAnglesYXZ HOT 1
- The function getTransposedToAddress() does not exist HOT 2
- AABB Intersections HOT 1
- [PR Reminder] You can instatiate instances of the Math utility class
- Can't figure out interesting behavior by Matrix4f.transpose() HOT 1
- A simpler way to create a Vector2d from a Vector3d HOT 6
- Optimize Vector Multiplication? HOT 20
- rotation matrix scaling HOT 1
- Vector3d.div() incorrectly takes in Vector3d instead of Vector3dc HOT 1
- Long counterpart to integer components HOT 2
- Matrix4f.setFrustum with zNear values < 1.0f creates distortions HOT 4
- Quaternionf fromAxisAngleDeg angle parameter description discrepancy HOT 1
- Bug in MemUtilUnsafe.put3x4 HOT 1
- Consistent Array Constructors/Accessors
- Scala Operators
- [Suggestion/Discussion] Matrix Consumer Actions
- Using JOML without Kotlin HOT 3
- JOML 1.10.7 no longer works with OSGI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joml.