简体   繁体   English

你什么时候使用AffineTransform getScaleX()?

[英]When would you use AffineTransform getScaleX()?

Is there a legitimate use case for AffineTransform.getScaleX() and family? AffineTransform.getScaleX()和系列是否有合法的用例?

It returns the m00 or the top left corner element of the transform matrix and that is pretty useless for determining the scaling the matrix does. 它返回变换矩阵的m00或左上角元素,这对于确定矩阵的缩放非常无用。 Consider for example a trivial 90 degree rotation matrix and both getScaleX() and getScaleY() return 0. 考虑例如一个普通的90度旋转矩阵,并且getScaleX()getScaleY()返回0。

I would never use this call as it is confusing to the code reader who may not be familiar with the fact that it does not return scaling in a meaningful way, much better to getMatrix(m) and then access the m[0], because most people likely to read code that uses transformations are familiar with matrix math. 我永远不会使用这个调用,因为它让代码阅读器感到困惑,因为代码阅读器可能不熟悉它不会以有意义的方式返回缩放的事实,更好的是getMatrix(m)然后访问m [0],因为大多数人可能阅读使用转换的代码都熟悉矩阵数学。

There must be a use case for this, but I just don't get it. 必须有一个用例,但我只是没有得到它。

As you wrote, the notion of the x scaling factor is quite meaningless in the general case. 正如你所写的那样,x缩放因子的概念在一般情况下毫无意义。 It is only relevant for the special case of scaling matrixes. 它仅与缩放矩阵的特殊情况相关。 iE those for which getType returns TYPE_GENERAL_SCALE or TYPE_UNIFORM_SCALE . iE getType返回TYPE_GENERAL_SCALETYPE_UNIFORM_SCALE (A translation could be added, too) In other cases, getScaleX is "correct" in the sense that it does what the docs say, but usesless and misleading regarding its name. (也可以添加翻译)在其他情况下, getScaleX是“正确的”,因为它执行文档所说的内容,但对其名称没有用处和误导性。 Analogous reasoning applies to getShearX , which only makes senses in context of shearing matrixes. 类似的推理适用于getShearX ,它只能在剪切矩阵的上下文中产生感觉。 getTranslateX is a bit different, since one could argue that this is where the origin gets translated to, regardless of all other transformations the matrix implies. getTranslateX有点不同,因为有人可能认为这是原点转换到的地方,而不管矩阵所暗示的所有其他转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM