VectSharp  2.2.1
A light library for C# vector graphics
RenderingParameters.cs
1 /*
2  VectSharp - A light library for C# vector graphics.
3  Copyright (C) 2020-2022 Giorgio Bianchini
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, version 3.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 using System;
19 
20 namespace VectSharp.Canvas
21 {
22  internal class RenderingParameters : IEquatable<RenderingParameters>
23  {
24  public static float Tolerance = 1e-5f;
25  public float Left { get; }
26  public float Top { get; }
27  public float Width { get; }
28  public float Height { get; }
29  public float Scale { get; }
30  public int RenderWidth { get; }
31  public int RenderHeight { get; }
32 
33  public RenderingParameters(float left, float top, float width, float height, float scale, int renderWidth, int renderHeight)
34  {
35  this.Left = left;
36  this.Top = top;
37  this.Width = width;
38  this.Height = height;
39  this.Scale = scale;
40  this.RenderWidth = renderWidth;
41  this.RenderHeight = renderHeight;
42  }
43 
44  public RenderingParameters Clone()
45  {
46  return new RenderingParameters(this.Left, this.Top, this.Width, this.Height, this.Scale, this.RenderWidth, this.RenderHeight);
47  }
48 
49  public bool Equals(RenderingParameters other)
50  {
51  if (!object.ReferenceEquals(other, null))
52  {
53  return this.Scale == other.Scale && this.Left == other.Left && this.Top == other.Top && this.Width == other.Width && this.Height == other.Height && this.RenderWidth == other.RenderWidth && this.RenderHeight == other.RenderHeight;
54  }
55  else
56  {
57  return false;
58  }
59  }
60 
61  public override bool Equals(object obj)
62  {
63  if (obj is RenderingParameters other)
64  {
65  return this.Equals(other);
66  }
67  else
68  {
69  return false;
70  }
71  }
72 
73  public override int GetHashCode()
74  {
75  int hash = 13;
76 
77  unchecked
78  {
79  hash = (hash * 7) + this.Left.GetHashCode();
80  hash = (hash * 7) + this.Top.GetHashCode();
81  hash = (hash * 7) + this.Width.GetHashCode();
82  hash = (hash * 7) + this.Height.GetHashCode();
83  hash = (hash * 7) + this.Scale.GetHashCode();
84  hash = (hash * 7) + this.RenderWidth.GetHashCode();
85  hash = (hash * 7) + this.RenderHeight.GetHashCode();
86  }
87 
88  return hash;
89  }
90 
91  public static bool operator ==(RenderingParameters param1, RenderingParameters param2)
92  {
93  if (object.ReferenceEquals(param1, null))
94  {
95  return object.ReferenceEquals(param2, null);
96  }
97  else
98  {
99  return param1.Equals(param2);
100  }
101  }
102 
103  public static bool operator !=(RenderingParameters param1, RenderingParameters param2)
104  {
105  if (!object.ReferenceEquals(param1, null) && !object.ReferenceEquals(param2, null))
106  {
107  return param1.Scale != param2.Scale || param1.Left != param2.Left || param1.Top != param2.Top || param1.Width != param2.Width || param1.Height != param2.Height || param1.RenderWidth != param2.RenderWidth || param1.RenderHeight != param2.RenderHeight;
108  }
109  else
110  {
111  return !(object.ReferenceEquals(param1, null) && object.ReferenceEquals(param2, null));
112  }
113  }
114 
115  public bool GoodEnough(RenderingParameters other)
116  {
117  if (this.Scale == other.Scale)
118  {
119  return (this.Left <= other.Left && (this.Left + this.Width - other.Left - other.Width) / (this.Left + this.Width + other.Left + other.Width) >= -Tolerance && this.Top <= other.Top && (this.Top + this.Height - other.Top - other.Height) / (this.Top + this.Height + other.Top + other.Height) >= -Tolerance);
120  }
121  else
122  {
123  return false;
124  }
125  }
126  }
127 }
VectSharp.Canvas
Definition: AvaloniaContext.cs:29
VectSharp.TextAnchors.Left
@ Left
The current coordinate will determine the position of the left side of the text string.
VectSharp.TextBaselines.Top
@ Top
The current vertical coordinate determines where the top of the text string will be placed.