• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MorganKryze / ConsoleAppVisuals / 8158191062

05 Mar 2024 02:47PM UTC coverage: 86.165% (+0.9%) from 85.231%
8158191062

push

github

MorganKryze
📖 (readme) update roadmap

931 of 1144 branches covered (81.38%)

Branch coverage included in aggregate %.

1803 of 2029 relevant lines covered (88.86%)

412.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/ConsoleAppVisuals/models/Position.cs
1
/*
2
    GNU GPL License 2024 MorganKryze(Yann Vidamment)
3
    For full license information, please visit: https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/LICENSE
4
*/
5
namespace ConsoleAppVisuals.Models;
6

7
/// <summary>
8
/// A class that stores the position into X and Y parameters of a position.
9
/// </summary>
10
/// <remarks>
11
/// For more information, refer to the following resources:
12
/// <list type="bullet">
13
/// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
14
/// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
15
/// </list>
16
/// </remarks>
17
public struct Position : IEquatable<Position>
18
{
19
    #region Attributes
20
    /// <summary>
21
    /// The x coordinate of the position.
22
    /// </summary>
23
    public int X { get; set; }
140✔
24

25
    /// <summary>
26
    /// The y coordinate of the position.
27
    /// </summary>
28
    public int Y { get; set; }
108✔
29
    #endregion
30

31
    #region Constructors
32
    /// <summary>
33
    /// Initializes a new instance of the <see cref="Position"/> class with 2 coordinates.
34
    /// </summary>
35
    /// <param name="x">The x coordinate of the position.</param>
36
    /// <param name="y">The y coordinate of the position.</param>
37
    /// <remarks>
38
    /// For more information, refer to the following resources:
39
    /// <list type="bullet">
40
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
41
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
42
    /// </list>
43
    /// </remarks>
44
    public Position(int x, int y)
45
    {
46
        X = x;
50✔
47
        Y = y;
50✔
48
    }
50✔
49

50
    /// <summary>
51
    /// Initializes a new instance of the <see cref="Position"/> class with another instance of the <see cref="Position"/> class.
52
    /// </summary>
53
    /// <param name="pos">The position to copy.</param>
54
    /// <remarks>
55
    /// For more information, refer to the following resources:
56
    /// <list type="bullet">
57
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
58
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
59
    /// </list>
60
    /// </remarks>
61
    public Position(Position pos)
62
    {
63
        X = pos.X;
2✔
64
        Y = pos.Y;
2✔
65
    }
2✔
66
    #endregion
67

68
    #region Methods
69
    /// <summary>
70
    /// This method is used to convert the position to a string.
71
    /// </summary>
72
    /// <returns>The position as a string.</returns>
73
    /// <remarks>
74
    /// For more information, refer to the following resources:
75
    /// <list type="bullet">
76
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
77
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
78
    /// </list>
79
    /// </remarks>
80
    public override readonly string ToString() => $"Line : {X} ; Column : {Y}";
2✔
81

82
    /// <summary>
83
    /// This method is used to check if the position is equal to another position.
84
    /// </summary>
85
    /// <param name="obj">The position to compare to.</param>
86
    /// <returns>True if the positions are equal, false otherwise.</returns>
87
    /// <remarks>
88
    /// For more information, refer to the following resources:
89
    /// <list type="bullet">
90
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
91
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
92
    /// </list>
93
    /// </remarks>
94
    public override readonly bool Equals(object? obj) =>
95
        obj is Position position && X == position.X && Y == position.Y;
14✔
96

97
    /// <summary>
98
    /// Implementation of the IEquatable interface.
99
    /// </summary>
100
    /// <returns>An integer representing the hash code of the position.</returns>
101
    /// <remarks>
102
    /// For more information, refer to the following resources:
103
    /// <list type="bullet">
104
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
105
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
106
    /// </list>
107
    /// </remarks>
108
    public override readonly int GetHashCode() => HashCode.Combine(X, Y);
8✔
109

110
    /// <summary>
111
    /// Implementation of the IEquatable interface.
112
    /// </summary>
113
    /// <param name="other">The position to compare to.</param>
114
    /// <returns>True if the positions are equal, false otherwise.</returns>
115
    readonly bool IEquatable<Position>.Equals(Position other) => Equals(other);
2✔
116

117
    /// <summary>
118
    /// This operator is used to check if the position is equal to another position.
119
    /// </summary>
120
    /// <param name="left">The first position to compare.</param>
121
    /// <param name="right">The second position to compare.</param>
122
    /// <returns>True if the positions are equal, false otherwise.</returns>
123
    public static bool operator ==(Position left, Position right)
124
    {
125
        return left.Equals(right);
8✔
126
    }
127

128
    /// <summary>
129
    /// This operator is used to check if the position is not equal to another position.
130
    /// </summary>
131
    /// <param name="left">The first position to compare.</param>
132
    /// <param name="right">The second position to compare.</param>
133
    /// <returns>True if the positions are not equal, false otherwise.</returns>
134
    public static bool operator !=(Position left, Position right)
135
    {
136
        return !(left == right);
4✔
137
    }
138
    #endregion
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc