Skip to content

Commit

Permalink
RectEx upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
slavniyteo committed Feb 3, 2018
1 parent 38b6768 commit 95a39d2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
18 changes: 10 additions & 8 deletions Assets/RectEx/ColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
using RectEx.Internal;

namespace RectEx {
public static class ColumnExtensions {
public static class ColumnExtensions {

public static Rect[] Column(this Rect rect, int count, float space = 2){
private const float SPACE = 2f;

public static Rect[] Column(this Rect rect, int count, float space = SPACE){
rect = rect.Invert();
var result = rect.Row(count, space);
return result.Select(x => x.Invert()).ToArray();
}

public static Rect[] Column(this Rect rect, float[] weights, float space = 2){
return Column(rect, weights, null, space);
}
public static Rect[] Column(this Rect rect, float[] weights, float space = SPACE){
return Column(rect, weights, null, space);
}

public static Rect[] Column(this Rect rect, float[] weights, float[] widthes, float space = 2) {
public static Rect[] Column(this Rect rect, float[] weights, float[] widthes, float space = SPACE) {
rect = rect.Invert();
var result = rect.Row(weights, widthes, space);
return result.Select(x => x.Invert()).ToArray();
}

}
}
}
}
12 changes: 7 additions & 5 deletions Assets/RectEx/CutFromExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace RectEx {
public static class CutFromExtensions {

public static Rect[] CutFromRight(this Rect rect, float width, float space = 5){
private const float SPACE = 2;

public static Rect[] CutFromRight(this Rect rect, float width, float space = SPACE){
var second = Rect.MinMaxRect(
xmin:rect.xMax - width,
xmax:rect.xMax,
Expand All @@ -21,7 +23,7 @@ public static Rect[] CutFromRight(this Rect rect, float width, float space = 5){
return new Rect[]{first, second};
}

public static Rect[] CutFromBottom(this Rect rect, float height, float space = 5){
public static Rect[] CutFromBottom(this Rect rect, float height, float space = SPACE){
var second = Rect.MinMaxRect(
xmin:rect.xMin,
xmax:rect.xMax,
Expand All @@ -38,7 +40,7 @@ public static Rect[] CutFromBottom(this Rect rect, float height, float space = 5
return new Rect[]{first, second};
}

public static Rect[] CutFromLeft(this Rect rect, float width, float space = 5){
public static Rect[] CutFromLeft(this Rect rect, float width, float space = SPACE){
var first = Rect.MinMaxRect(
xmin:rect.xMin,
xmax:rect.xMin + width,
Expand All @@ -55,7 +57,7 @@ public static Rect[] CutFromLeft(this Rect rect, float width, float space = 5){
return new Rect[]{first, second};
}

public static Rect[] CutFromTop(this Rect rect, float height, float space = 5){
public static Rect[] CutFromTop(this Rect rect, float height, float space = SPACE){
var first = Rect.MinMaxRect(
xmin:rect.xMin,
xmax:rect.xMax,
Expand All @@ -72,4 +74,4 @@ public static Rect[] CutFromTop(this Rect rect, float height, float space = 5){
return new Rect[]{first, second};
}
}
}
}
12 changes: 7 additions & 5 deletions Assets/RectEx/GridExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using RectEx.Internal;

namespace RectEx {
public static class GridExtensions {
public static class GridExtensions {

public static Rect[,] Grid(this Rect rect, int rows, int columns, float space = 5){
private const float SPACE = 2f;

public static Rect[,] Grid(this Rect rect, int rows, int columns, float space = SPACE){
return Grid(rect, rows, columns, space, space);
}

Expand All @@ -26,9 +28,9 @@ public static class GridExtensions {
return result;
}

public static Rect[,] Grid(this Rect rect, int size, float space = 5){
public static Rect[,] Grid(this Rect rect, int size, float space = SPACE){
return Grid(rect, size, size, space, space);
}

}
}
}
}
6 changes: 3 additions & 3 deletions Assets/RectEx/Internal/IEnumerableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;

namespace RectEx.Internal {
public static class IEnumerableExtension {
public static class IEnumerableExtension {
public static IEnumerable<TResult> Merge<TFirst, TSecond, TResult> (this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TSecond, TResult> selector){
Expand All @@ -12,5 +12,5 @@ public static IEnumerable<TResult> Merge<TFirst, TSecond, TResult> (this IEnumer
yield return selector(firstEnumerator.Current, secondEnumerator.Current);
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions Assets/RectEx/MiscellaniousExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;

namespace RectEx {
public static class MiscellaniousExtensions {
public static class MiscellaniousExtensions {
public static Rect Abs(this Rect rect){
if (rect.width < 0) {
rect.x += rect.width;
Expand Down Expand Up @@ -77,5 +77,5 @@ public static Rect Extend(this Rect rect, float border){
);
}

}
}
}
}
10 changes: 6 additions & 4 deletions Assets/RectEx/MoveToExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
namespace RectEx {
public static class MoveToExtensions {

public static Rect MoveRight(this Rect rect, float space = 2){
private const float SPACE = 2f;

public static Rect MoveRight(this Rect rect, float space = SPACE){
rect = rect.Abs();
rect.x += rect.width + space;
return rect;
}

public static Rect MoveLeft(this Rect rect, float space = 2){
public static Rect MoveLeft(this Rect rect, float space = SPACE){
rect = rect.Abs();
rect.x -= rect.width + space;
return rect;
}

public static Rect MoveUp(this Rect rect, float space = 2){
public static Rect MoveUp(this Rect rect, float space = SPACE){
rect = rect.Abs();
rect.y -= rect.height + space;
return rect;
}

public static Rect MoveDown(this Rect rect, float space = 2){
public static Rect MoveDown(this Rect rect, float space = SPACE){
rect = rect.Abs();
rect.y += rect.height + space;
return rect;
Expand Down
24 changes: 13 additions & 11 deletions Assets/RectEx/RowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using RectEx.Internal;

namespace RectEx {
public static class RowExtensions {
public static class RowExtensions {

public static Rect[] Row(this Rect rect, int count, float space = 5){
private const float SPACE = 2f;

public static Rect[] Row(this Rect rect, int count, float space = SPACE){
rect = rect.Abs();
switch (count) {
case 1: {
Expand All @@ -28,11 +30,11 @@ public static Rect[] Row(this Rect rect, int count, float space = 5){
}
}

public static Rect[] Row(this Rect rect, float[] weights, float space = 5){
return Row(rect, weights, null, space);
}
public static Rect[] Row(this Rect rect, float[] weights, float space = SPACE){
return Row(rect, weights, null, space);
}

public static Rect[] Row(this Rect rect, float[] weights, float[] widthes, float space = 5) {
public static Rect[] Row(this Rect rect, float[] weights, float[] widthes, float space = SPACE) {
if (weights == null){
throw new ArgumentException("Weights is null. You must specify it");
}
Expand All @@ -45,7 +47,7 @@ public static Rect[] Row(this Rect rect, float[] weights, float[] widthes, float
return RowSafe(rect, weights, widthes, space);
}

private static Rect[] RowTwoSlices(Rect rect, float space = 5) {
private static Rect[] RowTwoSlices(Rect rect, float space) {
var first = new Rect(
x: rect.x,
y: rect.y,
Expand All @@ -61,7 +63,7 @@ private static Rect[] RowTwoSlices(Rect rect, float space = 5) {
return new Rect[] {first, second};
}

private static Rect[] RowThreeSlices(Rect rect, float space = 5) {
private static Rect[] RowThreeSlices(Rect rect, float space) {
var first = new Rect(
x: rect.x,
y: rect.y,
Expand All @@ -83,7 +85,7 @@ private static Rect[] RowThreeSlices(Rect rect, float space = 5) {
return new Rect[] {first, second, third};
}

private static Rect[] RowSafe(Rect rect, float[] weights, float[] widthes, float space = 5) {
private static Rect[] RowSafe(Rect rect, float[] weights, float[] widthes, float space) {
var cells = weights.Merge(widthes, (weight, width) => new Cell(weight, width)).Where( cell => cell.HasWidth);

float weightUnit = GetWeightUnit(rect.width, cells, space);
Expand Down Expand Up @@ -133,5 +135,5 @@ public float GetWidth(float weightUnit) {
}
}

}
}
}
}

0 comments on commit 95a39d2

Please sign in to comment.