-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathRenderingParameters.cs
127 lines (112 loc) · 4.68 KB
/
RenderingParameters.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
VectSharp - A light library for C# vector graphics.
Copyright (C) 2020-2022 Giorgio Bianchini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
namespace VectSharp.Canvas
{
internal class RenderingParameters : IEquatable<RenderingParameters>
{
public static float Tolerance = 1e-5f;
public float Left { get; }
public float Top { get; }
public float Width { get; }
public float Height { get; }
public float Scale { get; }
public int RenderWidth { get; }
public int RenderHeight { get; }
public RenderingParameters(float left, float top, float width, float height, float scale, int renderWidth, int renderHeight)
{
this.Left = left;
this.Top = top;
this.Width = width;
this.Height = height;
this.Scale = scale;
this.RenderWidth = renderWidth;
this.RenderHeight = renderHeight;
}
public RenderingParameters Clone()
{
return new RenderingParameters(this.Left, this.Top, this.Width, this.Height, this.Scale, this.RenderWidth, this.RenderHeight);
}
public bool Equals(RenderingParameters other)
{
if (!object.ReferenceEquals(other, null))
{
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;
}
else
{
return false;
}
}
public override bool Equals(object obj)
{
if (obj is RenderingParameters other)
{
return this.Equals(other);
}
else
{
return false;
}
}
public override int GetHashCode()
{
int hash = 13;
unchecked
{
hash = (hash * 7) + this.Left.GetHashCode();
hash = (hash * 7) + this.Top.GetHashCode();
hash = (hash * 7) + this.Width.GetHashCode();
hash = (hash * 7) + this.Height.GetHashCode();
hash = (hash * 7) + this.Scale.GetHashCode();
hash = (hash * 7) + this.RenderWidth.GetHashCode();
hash = (hash * 7) + this.RenderHeight.GetHashCode();
}
return hash;
}
public static bool operator ==(RenderingParameters param1, RenderingParameters param2)
{
if (object.ReferenceEquals(param1, null))
{
return object.ReferenceEquals(param2, null);
}
else
{
return param1.Equals(param2);
}
}
public static bool operator !=(RenderingParameters param1, RenderingParameters param2)
{
if (!object.ReferenceEquals(param1, null) && !object.ReferenceEquals(param2, null))
{
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;
}
else
{
return !(object.ReferenceEquals(param1, null) && object.ReferenceEquals(param2, null));
}
}
public bool GoodEnough(RenderingParameters other)
{
if (this.Scale == other.Scale)
{
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);
}
else
{
return false;
}
}
}
}