Archive for April, 2008

Alignment of Rectangular Objects

April 30, 2008 Leave a comment

In my editing program, the objects that can be manipulated with the mouse are called "selectables", and they implement this interface:

public interface ISelectable
    IEnumerable<IGrip> Grips { get; }

    void Offset(Vector v);

Read more…

Categories: C# Tags:

WPF and Symmetry in Coordinate Systems

April 29, 2008 Leave a comment

WPF provides some types for representing geometrical concepts. The simplest one is Point, which is roughly like this:

public struct Point
    public double X { get; set; }
    public double Y { get; set; }

This is fine but it misses an important fact about the X and the Y fields, which is that if you tip your head over 90 degrees and look at your monitor sideways, the X and the Y swap over. Which is which is merely a matter of your point of view. And so it is frequently useful to support exactly the same operations in both dimensions, which means that you have to write very nearly exactly the same code twice.

Read more…

Categories: C#, WPF Tags: ,

Coroutines with IEnumerable and yield return

April 9, 2008 2 comments

There was a brief flurry of excitement about the fancy yield return syntax when the C# 2.0 specification was first published some years ago, and the idea of it being used for creating coroutines.

This quickly died down, as far as I can see anyway. Either people forgot the idea, or it became such boringly standard practice that no one ever thinks to discuss it anymore. I don’t know which, but I think it deserves more attention either way.

There were a few people at the time saying that it was a shame that C# appeared to only support coroutines in a special case where the function returns some weird IEnumerable<T> thing, and wouldn’t it have been better if it was more general?

Read more…

Categories: C#, yield return Tags: ,