Skip to content

System.Drawing.Drawing2D.Matrix.Transform*(ReadOnlySpan) methods mutate the ReadOnlySpan #15226

Open

Description

@rickbrew

Background and motivation

The System.Drawing.Drawing2D.Matrix.TransformPoints and TransformVectors methods are intended to transform the array of values in-place, and that's clearly what the code is doing. The T[] overloads even call the ReadOnlySpan overloads to do the work. But because of the mutation, the span overloads should take Spans, not ReadOnlySpans.

It may also be worth doing a sweep through System.Drawing to see if anything else was transcribed incorrectly like this.

I'm seeing this in .NET 10 and .NET 11-rc1. I don't know when these APIs were originally added.

API Proposal

namespace System.Drawing.Drawing2D;

public sealed class Matrix
{
    // Remove or mark [Obsolete("Use the Span overloads", true)]
    // Also add [EditorBrowsable(EditorBrowsableState.Never)]
    public void TransformPoints(params ReadOnlySpan<PointF> pts);
    public void TransformPoints(params ReadOnlySpan<Point> pts);
    public void TransformVectors(params ReadOnlySpan<PointF> pts);
    public void TransformVectors(params ReadOnlySpan<Point> pts);

    // Add these, and also tag with [OverloadResolutionPriority(1)] if not deleting the ReadOnlySpan overloads
    public void TransformPoints(params Span<PointF> pts);
    public void TransformPoints(params Span<Point> pts);
    public void TransformVectors(params Span<PointF> pts);
    public void TransformVectors(params Span<Point> pts);
}

API Usage

APIs would be consumed in the same way they are today. I'm guessing most uses are going through the array overloads or via implicit cast to ReadOnlySpan from arrays or mutable Spans.

Alternative Designs

No response

Risks

Removing the methods risks breaking any code that was using them. At compile time it may be fine, but it will definitely break binary compatibility.

Will this feature affect UI controls?

No

Activity

  1. added
    api-suggestion(1) Early API idea and discussion, it is NOT ready for implementation
    untriagedThe team needs to look at this issue in the next triage
    on Oct 6, 2026
  2. LeafShi1 commented on Oct 12, 2026

    @LeafShi1
    Member

    The ReadOnlySpan<T> overload was introduced in #11416 and is public on .NET 9+, and the transformation modifies the points in place.
    So I think the concern here is valid. We may need to consider whether this should use Span<T> instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestion(1) Early API idea and discussion, it is NOT ready for implementationuntriagedThe team needs to look at this issue in the next triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions