Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ImageDescription.cs « Def « Imaging « Editor « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33f89b382febca34443af0013ca6a549a223286b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//

using System;

namespace Microsoft.VisualStudio.Core.Imaging
{
    public readonly struct ImageDescription : IEquatable<ImageDescription>
    {
        public readonly ImageId Id;
        public readonly int Width;
        public readonly int Height;
        public readonly ImageTags Tags;

        public ImageDescription(ImageId id, ImageTags tags)
             : this(id, 0, 0, tags)
        {
        }

        public ImageDescription(ImageId id, int size)
             : this(id, size, size, ImageTags.None)
        {
        }

        public ImageDescription(ImageId id, int size, ImageTags tags)
             : this(id, size, size, tags)
        {
        }

        public ImageDescription(ImageId id, int width, int height, ImageTags tags)
        {
            Id = id;
            Width = width;
            Height = height;
            Tags = tags;
        }

        public ImageDescription WithAdditionalTags(ImageTags tags)
            => new ImageDescription(Id, Width, Height, Tags | tags);

        public ImageDescription WithoutTags(ImageTags tags)
            => new ImageDescription(Id, Width, Height, Tags & ~tags);

        public override string ToString ()
            => $"'{Id}' @ {Width}x{Height} [{Tags}]";

        public bool Equals(ImageDescription other)
            => Width == other.Width &&
                Height == other.Height &&
                Tags == other.Tags &&
                Id.Equals(other.Id);

        public override bool Equals(object obj)
            => obj is ImageDescription other && Equals(other);

        public override int GetHashCode()
        {
            var hash = 23;
            hash = hash * 31 + Id.GetHashCode();
            hash = hash * 31 + (int)Tags;
            hash = hash * 31 + Width;
            hash = hash * 31 + Height;
            return hash;
        }

        public static bool operator ==(ImageDescription left, ImageDescription right)
            => left.Equals(right);

        public static bool operator !=(ImageDescription left, ImageDescription right)
            => !(left == right);
    }
}