04-09-2017, 08:57 AM
(This post was last modified: 04-09-2017, 02:32 PM by Rick Johnson.)
Thanks for the clarification, Garrett. The problem with the first code snippet makes perfect sense now.
As for code snippet 2, the docs for inverting a matrix says "If the inverse of the target matrix were concatenated with the target itself, the result would be an identity matrix." That's exactly the result I want. If I perform a transformWithOptions as in the third code snippet using an identity matrix with a pattern that has been manipulated, it does nothing, which is what I would expect; it appears that the function doesn't apply the matrix, it concatenates it. When I simply concat translations to an identity matrix, it works fine. When I get (a copy of) the art's matrix and invert it, its values appear to be correct. For example, [ 3 3 1 0 0 1 ] becomes [ -3 -3 1 -0 -0 1 ]. When I transformWithOptions using this matrix, wouldn't one expect the pattern to shift back to [ 0 0 1 0 0 1 ]? Instead its ty becomes 6. It's interesting that the error always appears in the ty value and that transform.invert() will return true and invert an identity matrix. Here's the code I ran on a transformed pattern fill. Even if the matrix variable is a copy, I'm sure it's always a fresh copy of the original.
I've been studying and experimenting for hours now trying to construct a new ArtColor object from a PatternStyle object. There are constructors for various color models, but none for gradients or patterns. Assignment with "=" doesn't work, nor do statements like hdi::core::ArtColor myColor(myPattern) because of type differences. Can you please advise how to do that? It would be really nice to be able to simply apply an identity transformation matrix to a pattern fill or point text object as in AppleScript where it removes all transformations.
As for code snippet 2, the docs for inverting a matrix says "If the inverse of the target matrix were concatenated with the target itself, the result would be an identity matrix." That's exactly the result I want. If I perform a transformWithOptions as in the third code snippet using an identity matrix with a pattern that has been manipulated, it does nothing, which is what I would expect; it appears that the function doesn't apply the matrix, it concatenates it. When I simply concat translations to an identity matrix, it works fine. When I get (a copy of) the art's matrix and invert it, its values appear to be correct. For example, [ 3 3 1 0 0 1 ] becomes [ -3 -3 1 -0 -0 1 ]. When I transformWithOptions using this matrix, wouldn't one expect the pattern to shift back to [ 0 0 1 0 0 1 ]? Instead its ty becomes 6. It's interesting that the error always appears in the ty value and that transform.invert() will return true and invert an identity matrix. Here's the code I ran on a transformed pattern fill. Even if the matrix variable is a copy, I'm sure it's always a fresh copy of the original.
Code:
hdi::core::TransformMatrix tmx;
std::cout<<"new matrix "<<tmx.tx<<" "<<tmx.ty<<" "<<tmx.a<<" "<<tmx.b<<" "<<tmx.c<<" "<<tmx.d<<std::endl;
tmx = (*iter)->path()->style().fill.color.pattern().transform;
std::cout<<"original matrix "<<tmx.tx<<" "<<tmx.ty<<" "<<tmx.a<<" "<<tmx.b<<" "<<tmx.c<<" "<<tmx.d<<std::endl;
if ((*iter)->path()->style().fill.color.pattern().transform.invert(tmx)){
std::cout<<"matrix inverted "<<tmx.tx<<" "<<tmx.ty<<" "<<tmx.a<<" "<<tmx.b<<" "<<tmx.c<<" "<<tmx.d<<std::endl;
(*iter)->transformWithOptions(tmx, hdi::core::Art::TransformOptionFillPatterns);
tmx = (*iter)->path()->style().fill.color.pattern().transform;
std::cout<<"matrix transformed "<<tmx.tx<<" "<<tmx.ty<<" "<<tmx.a<<" "<<tmx.b<<" "<<tmx.c<<" "<<tmx.d<<std::endl<<std::endl;
}
I've been studying and experimenting for hours now trying to construct a new ArtColor object from a PatternStyle object. There are constructors for various color models, but none for gradients or patterns. Assignment with "=" doesn't work, nor do statements like hdi::core::ArtColor myColor(myPattern) because of type differences. Can you please advise how to do that? It would be really nice to be able to simply apply an identity transformation matrix to a pattern fill or point text object as in AppleScript where it removes all transformations.