Skip to content

Commit

Permalink
Merge pull request #21822 from aaronfranke/mono-pascal
Browse files Browse the repository at this point in the history
[Mono] Various style changes and naming standardization
  • Loading branch information
neikeq authored Sep 10, 2018
2 parents 96014b6 + 627ed98 commit 8366da5
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 285 deletions.
72 changes: 36 additions & 36 deletions modules/mono/glue/cs_files/AABB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ public bool Encloses(AABB with)
src_max.z > dst_max.z;
}

public AABB Expand(Vector3 to_point)
public AABB Expand(Vector3 point)
{
Vector3 begin = _position;
Vector3 end = _position + _size;

if (to_point.x < begin.x)
begin.x = to_point.x;
if (to_point.y < begin.y)
begin.y = to_point.y;
if (to_point.z < begin.z)
begin.z = to_point.z;
if (point.x < begin.x)
begin.x = point.x;
if (point.y < begin.y)
begin.y = point.y;
if (point.z < begin.z)
begin.z = point.z;

if (to_point.x > end.x)
end.x = to_point.x;
if (to_point.y > end.y)
end.y = to_point.y;
if (to_point.z > end.z)
end.z = to_point.z;
if (point.x > end.x)
end.x = point.x;
if (point.y > end.y)
end.y = point.y;
if (point.z > end.z)
end.z = point.z;

return new AABB(begin, end - begin);
}
Expand Down Expand Up @@ -347,29 +347,29 @@ public bool IntersectsSegment(Vector3 from, Vector3 to)

for (int i = 0; i < 3; i++)
{
real_t seg_from = from[i];
real_t seg_to = to[i];
real_t box_begin = _position[i];
real_t box_end = box_begin + _size[i];
real_t segFrom = from[i];
real_t segTo = to[i];
real_t boxBegin = _position[i];
real_t boxEnd = boxBegin + _size[i];
real_t cmin, cmax;

if (seg_from < seg_to)
if (segFrom < segTo)
{
if (seg_from > box_end || seg_to < box_begin)
if (segFrom > boxEnd || segTo < boxBegin)
return false;

real_t length = seg_to - seg_from;
cmin = seg_from < box_begin ? (box_begin - seg_from) / length : 0f;
cmax = seg_to > box_end ? (box_end - seg_from) / length : 1f;
real_t length = segTo - segFrom;
cmin = segFrom < boxBegin ? (boxBegin - segFrom) / length : 0f;
cmax = segTo > boxEnd ? (boxEnd - segFrom) / length : 1f;
}
else
{
if (seg_to > box_end || seg_from < box_begin)
if (segTo > boxEnd || segFrom < boxBegin)
return false;

real_t length = seg_to - seg_from;
cmin = seg_from > box_end ? (box_end - seg_from) / length : 0f;
cmax = seg_to < box_begin ? (box_begin - seg_from) / length : 1f;
real_t length = segTo - segFrom;
cmin = segFrom > boxEnd ? (boxEnd - segFrom) / length : 0f;
cmax = segTo < boxBegin ? (boxBegin - segFrom) / length : 1f;
}

if (cmin > min)
Expand All @@ -388,21 +388,21 @@ public bool IntersectsSegment(Vector3 from, Vector3 to)

public AABB Merge(AABB with)
{
Vector3 beg_1 = _position;
Vector3 beg_2 = with._position;
var end_1 = new Vector3(_size.x, _size.y, _size.z) + beg_1;
var end_2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg_2;
Vector3 beg1 = _position;
Vector3 beg2 = with._position;
var end1 = new Vector3(_size.x, _size.y, _size.z) + beg1;
var end2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg2;

var min = new Vector3(
beg_1.x < beg_2.x ? beg_1.x : beg_2.x,
beg_1.y < beg_2.y ? beg_1.y : beg_2.y,
beg_1.z < beg_2.z ? beg_1.z : beg_2.z
beg1.x < beg2.x ? beg1.x : beg2.x,
beg1.y < beg2.y ? beg1.y : beg2.y,
beg1.z < beg2.z ? beg1.z : beg2.z
);

var max = new Vector3(
end_1.x > end_2.x ? end_1.x : end_2.x,
end_1.y > end_2.y ? end_1.y : end_2.y,
end_1.z > end_2.z ? end_1.z : end_2.z
end1.x > end2.x ? end1.x : end2.x,
end1.y > end2.y ? end1.y : end2.y,
end1.z > end2.z ? end1.z : end2.z
);

return new AABB(min, max - min);
Expand Down
90 changes: 45 additions & 45 deletions modules/mono/glue/cs_files/Basis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,51 +378,51 @@ public Vector3 XformInv(Vector3 v)
);
}

public Quat Quat() {
real_t trace = _x[0] + _y[1] + _z[2];

if (trace > 0.0f) {
real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_z[1] - _y[2]) * inv_s,
(_x[2] - _z[0]) * inv_s,
(_y[0] - _x[1]) * inv_s,
s * 0.25f
);
}

if (_x[0] > _y[1] && _x[0] > _z[2]) {
real_t s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
s * 0.25f,
(_x[1] + _y[0]) * inv_s,
(_x[2] + _z[0]) * inv_s,
(_z[1] - _y[2]) * inv_s
);
}

if (_y[1] > _z[2]) {
real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_x[1] + _y[0]) * inv_s,
s * 0.25f,
(_y[2] + _z[1]) * inv_s,
(_x[2] - _z[0]) * inv_s
);
} else {
real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_x[2] + _z[0]) * inv_s,
(_y[2] + _z[1]) * inv_s,
s * 0.25f,
(_y[0] - _x[1]) * inv_s
);
}
}
public Quat Quat() {
real_t trace = _x[0] + _y[1] + _z[2];

if (trace > 0.0f) {
real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_z[1] - _y[2]) * inv_s,
(_x[2] - _z[0]) * inv_s,
(_y[0] - _x[1]) * inv_s,
s * 0.25f
);
}

if (_x[0] > _y[1] && _x[0] > _z[2]) {
real_t s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
s * 0.25f,
(_x[1] + _y[0]) * inv_s,
(_x[2] + _z[0]) * inv_s,
(_z[1] - _y[2]) * inv_s
);
}

if (_y[1] > _z[2]) {
real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_x[1] + _y[0]) * inv_s,
s * 0.25f,
(_y[2] + _z[1]) * inv_s,
(_x[2] - _z[0]) * inv_s
);
} else {
real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
real_t inv_s = 1f / s;
return new Quat(
(_x[2] + _z[0]) * inv_s,
(_y[2] + _z[1]) * inv_s,
s * 0.25f,
(_y[0] - _x[1]) * inv_s
);
}
}

public Basis(Quat quat)
{
Expand Down
28 changes: 14 additions & 14 deletions modules/mono/glue/cs_files/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,12 @@ public string ToHtml(bool include_alpha = true)
{
var txt = string.Empty;

txt += _to_hex(r);
txt += _to_hex(g);
txt += _to_hex(b);
txt += ToHex32(r);
txt += ToHex32(g);
txt += ToHex32(b);

if (include_alpha)
txt = _to_hex(a) + txt;
txt = ToHex32(a) + txt;

return txt;
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public Color(long rgba)
r = (rgba & 0xFFFF) / 65535.0f;
}

private static int _parse_col(string str, int ofs)
private static int ParseCol8(string str, int ofs)
{
int ig = 0;

Expand Down Expand Up @@ -448,7 +448,7 @@ private static int _parse_col(string str, int ofs)
return ig;
}

private String _to_hex(float val)
private String ToHex32(float val)
{
int v = Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255));

Expand Down Expand Up @@ -490,17 +490,17 @@ internal static bool HtmlIsValid(string color)

if (alpha)
{
if (_parse_col(color, 0) < 0)
if (ParseCol8(color, 0) < 0)
return false;
}

int from = alpha ? 2 : 0;

if (_parse_col(color, from + 0) < 0)
if (ParseCol8(color, from + 0) < 0)
return false;
if (_parse_col(color, from + 2) < 0)
if (ParseCol8(color, from + 2) < 0)
return false;
if (_parse_col(color, from + 4) < 0)
if (ParseCol8(color, from + 4) < 0)
return false;

return true;
Expand Down Expand Up @@ -542,7 +542,7 @@ public Color(string rgba)

if (alpha)
{
a = _parse_col(rgba, 0) / 255f;
a = ParseCol8(rgba, 0) / 255f;

if (a < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba);
Expand All @@ -554,17 +554,17 @@ public Color(string rgba)

int from = alpha ? 2 : 0;

r = _parse_col(rgba, from + 0) / 255f;
r = ParseCol8(rgba, from + 0) / 255f;

if (r < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba);

g = _parse_col(rgba, from + 2) / 255f;
g = ParseCol8(rgba, from + 2) / 255f;

if (g < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba);

b = _parse_col(rgba, from + 4) / 255f;
b = ParseCol8(rgba, from + 4) / 255f;

if (b < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba);
Expand Down
32 changes: 16 additions & 16 deletions modules/mono/glue/cs_files/GodotSynchronizationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace Godot
{
public class GodotSynchronizationContext : SynchronizationContext
{
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
public class GodotSynchronizationContext : SynchronizationContext
{
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();

public override void Post(SendOrPostCallback d, object state)
{
queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
}
public override void Post(SendOrPostCallback d, object state)
{
queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
}

public void ExecutePendingContinuations()
{
KeyValuePair<SendOrPostCallback, object> workItem;
while (queue.TryTake(out workItem))
{
workItem.Key(workItem.Value);
}
}
}
public void ExecutePendingContinuations()
{
KeyValuePair<SendOrPostCallback, object> workItem;
while (queue.TryTake(out workItem))
{
workItem.Key(workItem.Value);
}
}
}
}
Loading

0 comments on commit 8366da5

Please sign in to comment.