@vertexvis/geometry 0.10.2-canary.1 → 0.10.2-canary.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,6 +101,23 @@ function scale(pt, scaleX, scaleY) {
101
101
  x: pt.x * scaleX,
102
102
  y: pt.y * scaleY,
103
103
  };
104
+ }
105
+ /**
106
+ * Parses a JSON string representation of a Point and returns an object.
107
+ *
108
+ * @param json A JSON string, either in the form `[x,y]` or `{"x": 0, "y": 0}`
109
+ * @returns A parsed Point.
110
+ */
111
+ function fromJson(json) {
112
+ var obj = JSON.parse(json);
113
+ if (Array.isArray(obj)) {
114
+ var x = obj[0], y = obj[1];
115
+ return create(x, y);
116
+ }
117
+ else {
118
+ var x = obj.x, y = obj.y;
119
+ return create(x, y);
120
+ }
104
121
  }
105
122
 
106
123
  var point = /*#__PURE__*/Object.freeze({
@@ -113,7 +130,8 @@ var point = /*#__PURE__*/Object.freeze({
113
130
  isEqual: isEqual,
114
131
  lerp: lerp$1,
115
132
  negate: negate,
116
- scale: scale
133
+ scale: scale,
134
+ fromJson: fromJson
117
135
  });
118
136
 
119
137
  /**
@@ -737,7 +755,7 @@ function fromMatrixPosition(matrix) {
737
755
  * @param json A JSON string, either in the form `[x,y,z]` or `{"x": 0, "y": 0, "z": 0}`
738
756
  * @returns A parsed Vector3.
739
757
  */
740
- function fromJson(json) {
758
+ function fromJson$1(json) {
741
759
  var obj = JSON.parse(json);
742
760
  if (Array.isArray(obj)) {
743
761
  var x = obj[0], y = obj[1], z = obj[2];
@@ -1033,7 +1051,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
1033
1051
  isValid: isValid,
1034
1052
  fromMatrixScale: fromMatrixScale,
1035
1053
  fromMatrixPosition: fromMatrixPosition,
1036
- fromJson: fromJson,
1054
+ fromJson: fromJson$1,
1037
1055
  fromArray: fromArray,
1038
1056
  toArray: toArray,
1039
1057
  right: right,
@@ -1250,6 +1268,32 @@ function isLandscape(rect) {
1250
1268
  */
1251
1269
  function isSquare(rect) {
1252
1270
  return rect.width === rect.height;
1271
+ }
1272
+ /**
1273
+ * Pads a rectangle by the given amount, maintaining the center position.
1274
+ *
1275
+ * @param rect The rectangle to apply padding to.
1276
+ * @param padding The padding to add.
1277
+ */
1278
+ function pad(rect, padding) {
1279
+ return create$3(rect.x - padding, rect.y - padding, rect.width + padding * 2, rect.height + padding * 2);
1280
+ }
1281
+ /**
1282
+ * Parses a JSON string representation of a Rectangle and returns an object.
1283
+ *
1284
+ * @param json A JSON string, either in the form `[x,y,width,height]` or `{"x": 0, "y": 0, "width": 10, "height": 10}`
1285
+ * @returns A parsed Point.
1286
+ */
1287
+ function fromJson$2(json) {
1288
+ var obj = JSON.parse(json);
1289
+ if (Array.isArray(obj)) {
1290
+ var x = obj[0], y = obj[1], width = obj[2], height = obj[3];
1291
+ return create$3(x, y, width, height);
1292
+ }
1293
+ else {
1294
+ var x = obj.x, y = obj.y, width = obj.width, height = obj.height;
1295
+ return create$3(x, y, width, height);
1296
+ }
1253
1297
  }
1254
1298
 
1255
1299
  var rectangle = /*#__PURE__*/Object.freeze({
@@ -1270,7 +1314,9 @@ var rectangle = /*#__PURE__*/Object.freeze({
1270
1314
  bottomRight: bottomRight,
1271
1315
  isPortrait: isPortrait,
1272
1316
  isLandscape: isLandscape,
1273
- isSquare: isSquare
1317
+ isSquare: isSquare,
1318
+ pad: pad,
1319
+ fromJson: fromJson$2
1274
1320
  });
1275
1321
 
1276
1322
  /**
@@ -1555,7 +1601,7 @@ function fromRotationMatrix(matrix, order) {
1555
1601
  * @param json A JSON object.
1556
1602
  * @returns A euler angle.
1557
1603
  */
1558
- function fromJson$1(json) {
1604
+ function fromJson$3(json) {
1559
1605
  var obj = JSON.parse(json);
1560
1606
  if (Array.isArray(obj)) {
1561
1607
  var x = obj[0], y = obj[1], z = obj[2], _a = obj[3], order = _a === void 0 ? 'xyz' : _a;
@@ -1584,7 +1630,7 @@ var euler = /*#__PURE__*/Object.freeze({
1584
1630
  create: create$5,
1585
1631
  fromDegrees: fromDegrees,
1586
1632
  fromRotationMatrix: fromRotationMatrix,
1587
- fromJson: fromJson$1,
1633
+ fromJson: fromJson$3,
1588
1634
  isType: isType$1
1589
1635
  });
1590
1636
 
@@ -1854,7 +1900,7 @@ function create$a(value) {
1854
1900
  * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
1855
1901
  * @returns A parsed `Quaternion`.
1856
1902
  */
1857
- function fromJson$2(json) {
1903
+ function fromJson$4(json) {
1858
1904
  var obj = JSON.parse(json);
1859
1905
  if (Array.isArray(obj)) {
1860
1906
  var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
@@ -2014,7 +2060,7 @@ function isType$2(obj) {
2014
2060
  var quaternion = /*#__PURE__*/Object.freeze({
2015
2061
  __proto__: null,
2016
2062
  create: create$a,
2017
- fromJson: fromJson$2,
2063
+ fromJson: fromJson$4,
2018
2064
  fromAxisAngle: fromAxisAngle,
2019
2065
  fromMatrixRotation: fromMatrixRotation,
2020
2066
  fromEuler: fromEuler,