No-spam Sam

[This really needs to go on the Connect site, but it seems to be down at the moment.]

Has anyone else come accross this When I create a ScaleTransform and set one or both of its Scale* properties to a small number (<= 1e-16), the Transform.Inverse property becomes null.

This doesn't make sense at all, and has been a bit of a problem for us in our code. I assume it must be a bug We've had to work around this for now by doing inverse calculations manually (that this is do-able is why I assume the behaviour can't be 'by design').

Here's some very simple code that demonstrates the problem:

using System;

using System.Windows.Media;

public class MyClass

{

public static void Main()

{

ScaleTransform okTrans = new ScaleTransform(5, 10);

WL("Has null inverse " + (okTrans.Inverse == null).ToString());

ScaleTransform nullTrans = new ScaleTransform(1e-16, 2);

WL("Has null inverse " + (nullTrans.Inverse == null).ToString());

nullTrans = new ScaleTransform(1e-15,3);

WL("Has null inverse " + (nullTrans.Inverse == null).ToString());

nullTrans = new ScaleTransform(3,1e-16);

WL("Has null inverse " + (nullTrans.Inverse == null).ToString());

nullTrans = new ScaleTransform(1e-16,1e-16);

WL("Has null inverse " + (nullTrans.Inverse == null).ToString());

RL();

}

#region Helper methods

private static void WL(object text, params object[] args)

{

Console.WriteLine(text.ToString(), args);

}

private static void RL()

{

}

#endregion

}

### Re: Windows Presentation Foundation (WPF) ScaleTransform has null inverse when Scale property has very small value.

Douglas Stockwell

I think you will find this is related to the limited precision of the double type. The inverse operation is possibly detecting that it will be unable to ensure a "correct" inverse, or perhaps the values are negligible for 0.

### Re: Windows Presentation Foundation (WPF) ScaleTransform has null inverse when Scale property has very small value.

Sam

I'm not convinced about that: as I said in my post, I'm able to take the values out of the ScaleTransform and do the inverse calculation myself, and the precision isn't a problem.

### Re: Windows Presentation Foundation (WPF) ScaleTransform has null inverse when Scale property has very small value.

What you're hitting is that we've taken a somewhat pessimistic view of what "too close to 0" is, at least for your purposes. To compute the Inverse, we first check if the Determinant is close to 0, which, in the case of your 1e-16 x 1e-16 scale is 1e-32. We then call this "too close to 0", though you're right, in this case we could just keep going and get the right answer. Unfortunately, if your app really does need to manipulate values in this range, I think you're already doing the correct work-around. We'd be interested to understand your scenario more, in that scaling by 1e-16 does make the content pretty darn small.

### Re: Windows Presentation Foundation (WPF) ScaleTransform has null inverse when Scale property has very small value.

Sam

Actually it makes the content just the right size.

The code in question is part of a Chart Control, drawing line graphs. What I'm doing is creating Geometry objects to represent the lines, or areas on the Chart. I wanted to take full advantage of WPFs Transforming abilites, so when I create the Geometry objects, I create them in Series-Value-Space - I directly use the (x,y) coords of the points in the series as the (x,y) coords of the points in the Geometry. Then I apply said Scale Transform to scale the Geometry down (or up if the series has small values) so that it renders correctly in the screen. I can then trivially resize the chart when the Control size changes. And we just need to apply the inverse transform to get from a Hit-Test result to the original value of the Series.

Everything was working fine with this approach, until we hit a series with a maximum value of 1e27. This obviously needs to be scaled down quite a bit, and it was at this point that we hit the problem. The chart renders correctly, but it was when we were trying to use the Inverse Transform during our Hit Test that we found the problem.

Do you think you will address this in the future

Thanks,

Sam

### Re: Windows Presentation Foundation (WPF) ScaleTransform has null inverse when Scale property has very small value.

Heh - yeah, this makes sense, and I love the approach, since it does remove a (usually extraneous) level of processing. I don't know whether this will be addressed going forward, though I'll certainly bring this to the attention of the team that owns this behavior. In general, our advice is to try to avoid really large and really small numbers as they (potentially) introduce imprecision, though the definitions of "really large" and "really small" are themselves fuzzy...

It may be that there might be another sort of workaround depending on when/where you're looking for the Inverse - can you elaborate on when/why you call this That is, you may find that you can place a transform on the geometry data itself instead of on, say, the RenderTransform property (or vice versa), if this helps avoid the necessity of looking at the Inverse.