Tanoda
Margins.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity.Geometry {
12
13 public struct Margins {
14
15 public float left;
16 public float right;
17 public float top;
18 public float bottom;
19
20 public static readonly Margins zero = Margins.All(0f);
21 public static readonly Margins one = Margins.All(1f);
22
23 public Margins(float left, float right, float top, float bottom) {
24 this.left = left; this.right = right; this.top = top; this.bottom = bottom;
25 }
26
27 public static Margins All(float margin) {
28 return new Margins() {
29 left = margin, right = margin, top = margin, bottom = margin
30 };
31 }
32
33 public static Margins operator *(Margins m, float factor) {
34 return new Margins(m.left * factor, m.right * factor, m.top * factor,
35 m.bottom * factor);
36 }
37
38 public static Margins operator *(float factor, Margins m) {
39 return new Margins(m.left * factor, m.right * factor, m.top * factor,
40 m.bottom * factor);
41 }
42
43 public static Margins operator -(Margins m) {
44 return m * -1f;
45 }
46
47 }
48
49 public static class MarginExtensions {
50
51 public static LocalRect PadOuter(this LocalRect r, Margins margins) {
52 return new LocalRect(
53 center: r.center + new Vector3(
54 (margins.right - margins.left) / 2f,
55 (margins.top - margins.bottom) / 2f,
56 0f
57 ),
58 radii: new Vector2(
59 r.radii.x + (margins.right + margins.left) / 2f,
60 r.radii.y + (margins.top + margins.bottom) / 2f
61 )
62 );
63 }
64
65 public static LocalRect PadInner(this LocalRect r, Margins margins) {
66 return r.PadOuter(-margins);
67 }
68
69 }
70
71}
static readonly Margins one
Definition: Margins.cs:21
static Margins operator-(Margins m)
Definition: Margins.cs:43
static Margins operator*(Margins m, float factor)
Definition: Margins.cs:33
static readonly Margins zero
Definition: Margins.cs:20
static Margins All(float margin)
Definition: Margins.cs:27
Margins(float left, float right, float top, float bottom)
Definition: Margins.cs:23