@logic-pad/core 0.23.0 → 0.23.1

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.
Files changed (2) hide show
  1. package/dist/data/grid.js +73 -10
  2. package/package.json +1 -1
package/dist/data/grid.js CHANGED
@@ -924,34 +924,97 @@ export default class GridData {
924
924
  newTiles[origin.y + y][origin.x + x] = tile;
925
925
  });
926
926
  const connections = new GridConnections([
927
- ...this.connections.edges,
928
- ...grid.connections.edges.map(edge => ({
927
+ ...this.connections.edges.filter(edge => edge.x1 < origin.x ||
928
+ edge.y1 < origin.y ||
929
+ edge.x2 < origin.x ||
930
+ edge.y2 < origin.y ||
931
+ edge.x1 >= origin.x + grid.width ||
932
+ edge.y1 >= origin.y + grid.height ||
933
+ edge.x2 >= origin.x + grid.width ||
934
+ edge.y2 >= origin.y + grid.height),
935
+ ...grid.connections.edges
936
+ .map(edge => ({
929
937
  x1: edge.x1 + origin.x,
930
938
  y1: edge.y1 + origin.y,
931
939
  x2: edge.x2 + origin.x,
932
940
  y2: edge.y2 + origin.y,
933
- })),
941
+ }))
942
+ .filter(edge => edge.x1 >= 0 &&
943
+ edge.y1 >= 0 &&
944
+ edge.x2 >= 0 &&
945
+ edge.y2 >= 0 &&
946
+ edge.x1 < this.width &&
947
+ edge.y1 < this.height &&
948
+ edge.x2 < this.width &&
949
+ edge.y2 < this.height),
934
950
  ]);
935
951
  const zones = new GridZones([
936
- ...this.zones.edges,
937
- ...grid.zones.edges.map(edge => ({
952
+ ...this.zones.edges.filter(edge => edge.x1 < origin.x ||
953
+ edge.y1 < origin.y ||
954
+ edge.x2 < origin.x ||
955
+ edge.y2 < origin.y ||
956
+ edge.x1 >= origin.x + grid.width ||
957
+ edge.y1 >= origin.y + grid.height ||
958
+ edge.x2 >= origin.x + grid.width ||
959
+ edge.y2 >= origin.y + grid.height),
960
+ ...grid.zones.edges
961
+ .map(edge => ({
938
962
  x1: edge.x1 + origin.x,
939
963
  y1: edge.y1 + origin.y,
940
964
  x2: edge.x2 + origin.x,
941
965
  y2: edge.y2 + origin.y,
942
- })),
966
+ }))
967
+ .filter(edge => edge.x1 >= 0 &&
968
+ edge.y1 >= 0 &&
969
+ edge.x2 >= 0 &&
970
+ edge.y2 >= 0 &&
971
+ edge.x1 < this.width &&
972
+ edge.y1 < this.height &&
973
+ edge.x2 < this.width &&
974
+ edge.y2 < this.height),
943
975
  ]);
944
976
  const symbols = new Map(this.symbols);
945
977
  for (const [id, sourceList] of grid.symbols) {
946
- const symbolList = sourceList.map(symbol => symbol.copyWith({ x: symbol.x + origin.x, y: symbol.y + origin.y }));
978
+ const symbolList = sourceList
979
+ .filter(symbol => symbol.x + origin.x >= 0 &&
980
+ symbol.y + origin.y >= 0 &&
981
+ symbol.x + origin.x < this.width &&
982
+ symbol.y + origin.y < this.height)
983
+ .map(symbol => symbol.copyWith({ x: symbol.x + origin.x, y: symbol.y + origin.y }));
947
984
  if (symbols.has(id)) {
948
- symbols.set(id, [...symbols.get(id), ...symbolList]);
985
+ const newList = [
986
+ ...symbols
987
+ .get(id)
988
+ .filter(symbol => symbol.x < origin.x ||
989
+ symbol.y < origin.y ||
990
+ symbol.x >= origin.x + grid.width ||
991
+ symbol.y >= origin.y + grid.height),
992
+ ...symbolList,
993
+ ];
994
+ if (newList.length > 0)
995
+ symbols.set(id, newList);
996
+ else
997
+ symbols.delete(id);
949
998
  }
950
- else {
999
+ else if (symbolList.length > 0) {
951
1000
  symbols.set(id, symbolList);
952
1001
  }
953
1002
  }
954
- const rules = [...this.rules, ...grid.rules];
1003
+ for (const id of [...symbols.keys()]) {
1004
+ if (grid.symbols.has(id))
1005
+ continue;
1006
+ const newList = symbols
1007
+ .get(id)
1008
+ .filter(symbol => symbol.x < origin.x ||
1009
+ symbol.y < origin.y ||
1010
+ symbol.x >= origin.x + grid.width ||
1011
+ symbol.y >= origin.y + grid.height);
1012
+ if (newList.length > 0)
1013
+ symbols.set(id, newList);
1014
+ else
1015
+ symbols.delete(id);
1016
+ }
1017
+ const rules = GridData.deduplicateRules([...this.rules, ...grid.rules]);
955
1018
  return this.copyWith({
956
1019
  tiles: newTiles,
957
1020
  connections,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logic-pad/core",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",