circuitscript 0.1.14 → 0.1.15

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.
@@ -416,9 +416,28 @@ class Geometry {
416
416
  [segment.end.x, segment.end.y]
417
417
  ];
418
418
  });
419
+ const lines = [];
420
+ let prevPoint;
421
+ let currentLine = [];
422
+ segments.forEach((segment, index) => {
423
+ const [pt1, pt2] = segment;
424
+ if (index === 0 || (prevPoint[0] !== pt1[0] || prevPoint[1] !== pt1[1])) {
425
+ if (currentLine.length > 0) {
426
+ lines.push(currentLine);
427
+ currentLine = [];
428
+ }
429
+ currentLine.push([pt1[0], pt1[1]]);
430
+ }
431
+ currentLine.push(pt2);
432
+ prevPoint = pt2;
433
+ });
434
+ if (currentLine.length > 0) {
435
+ lines.push(currentLine);
436
+ }
419
437
  return {
420
438
  intersectPoints,
421
439
  segments,
440
+ lines,
422
441
  };
423
442
  }
424
443
  }
@@ -106,8 +106,10 @@ var BlockTypes;
106
106
  var NetGraphicsParams;
107
107
  (function (NetGraphicsParams) {
108
108
  NetGraphicsParams["Color"] = "color";
109
- NetGraphicsParams["Highight"] = "highlight";
110
109
  NetGraphicsParams["LineWidth"] = "lineWidth";
110
+ NetGraphicsParams["Highlight"] = "highlight";
111
+ NetGraphicsParams["HighlightWidth"] = "highlightWidth";
112
+ NetGraphicsParams["HighlightOpacity"] = "highlightOpacity";
111
113
  })(NetGraphicsParams || (exports.NetGraphicsParams = NetGraphicsParams = {}));
112
114
  var FrameType;
113
115
  (function (FrameType) {
@@ -137,8 +137,19 @@ class LayoutEngine {
137
137
  const value = net.params.get(globals_js_1.NetGraphicsParams.LineWidth);
138
138
  renderNet.lineWidth = (0, helpers_js_1.milsToMM)(value).toNumber();
139
139
  }
140
- if (net.params.has(globals_js_1.NetGraphicsParams.Highight)) {
141
- renderNet.highlight = net.params.get(globals_js_1.NetGraphicsParams.Highight);
140
+ if (net.params.has(globals_js_1.NetGraphicsParams.Highlight)) {
141
+ renderNet.highlight =
142
+ net.params.get(globals_js_1.NetGraphicsParams.Highlight);
143
+ }
144
+ if (net.params.has(globals_js_1.NetGraphicsParams.HighlightWidth)) {
145
+ renderNet.highlightWidth =
146
+ (0, helpers_js_1.milsToMM)(net.params.get(globals_js_1.NetGraphicsParams.HighlightWidth))
147
+ .toNumber();
148
+ }
149
+ if (net.params.has(globals_js_1.NetGraphicsParams.HighlightOpacity)) {
150
+ renderNet.highlightOpacity =
151
+ net.params.get(globals_js_1.NetGraphicsParams.HighlightOpacity)
152
+ .toNumber();
142
153
  }
143
154
  renderNets.set(net.toString(), renderNet);
144
155
  });
@@ -192,12 +203,13 @@ class LayoutEngine {
192
203
  });
193
204
  }
194
205
  else {
195
- const { intersectPoints, segments } = geometry_js_1.Geometry.mergeWires(allLines);
206
+ const { intersectPoints, segments, lines } = geometry_js_1.Geometry.mergeWires(allLines);
196
207
  mergedWires.push({
197
208
  netName: netName,
198
209
  segments,
199
210
  intersectPoints,
200
211
  net: renderNet,
212
+ lines,
201
213
  });
202
214
  intersectPoints.forEach(([x, y]) => {
203
215
  junctions.push(new RenderJunction((0, ParamDefinition_js_1.numeric)(x), (0, ParamDefinition_js_1.numeric)(y), renderNet));
@@ -181,12 +181,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
181
181
  const mergedWireHighlightGroup = canvas.group();
182
182
  const mergedWireGroup = canvas.group();
183
183
  mergedWires.forEach(tmpItem => {
184
- const { segments, intersectPoints, net = null } = tmpItem;
184
+ const { intersectPoints, net = null, lines = null } = tmpItem;
185
185
  let useJunctionColor = globals_js_1.ColorScheme.JunctionColor;
186
186
  let useColor = globals_js_1.ColorScheme.WireColor;
187
187
  let useLineWidth = globals_js_1.defaultWireLineWidth;
188
188
  let displayHighlight = false;
189
189
  let displayHighlightColor = null;
190
+ let displayHighlightOpacity = 0.3;
191
+ let displayHighlightWidth = 5 * globals_js_1.MilsToMM;
190
192
  if (net !== null) {
191
193
  useColor = net.color ?? globals_js_1.ColorScheme.WireColor;
192
194
  useJunctionColor = net.color ?? globals_js_1.ColorScheme.JunctionColor;
@@ -194,25 +196,29 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
194
196
  if (net.highlight !== null) {
195
197
  displayHighlight = true;
196
198
  displayHighlightColor = net.highlight ?? null;
199
+ if (net.highlightOpacity !== undefined) {
200
+ displayHighlightOpacity = net.highlightOpacity;
201
+ }
202
+ if (net.highlightWidth !== undefined) {
203
+ displayHighlightWidth = net.highlightWidth;
204
+ }
197
205
  }
198
206
  }
199
207
  const pathItems = [];
200
- const highlightExtraSize = 5 * globals_js_1.MilsToMM;
201
- segments.forEach(segment => {
202
- const pt1 = segment[0];
203
- const pt2 = segment[1];
204
- pathItems.push(...[
205
- 'M', pt1[0], pt1[1],
206
- 'L', pt2[0], pt2[1]
207
- ]);
208
+ const useLines = lines ?? [];
209
+ useLines.forEach(line => {
210
+ line.forEach((point, index) => {
211
+ const commandType = (index === 0) ? 'M' : 'L';
212
+ pathItems.push(...[commandType, point[0], point[1]]);
213
+ });
208
214
  });
209
215
  if (displayHighlight) {
210
216
  mergedWireHighlightGroup.path(pathItems)
211
217
  .stroke({
212
- width: useLineWidth + highlightExtraSize,
218
+ width: useLineWidth + displayHighlightWidth,
213
219
  color: displayHighlightColor,
214
- opacity: 0.3,
215
- linecap: 'square'
220
+ opacity: displayHighlightOpacity,
221
+ linecap: 'butt'
216
222
  })
217
223
  .fill('none');
218
224
  }
@@ -220,11 +226,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
220
226
  .stroke({
221
227
  width: useLineWidth,
222
228
  color: useColor,
223
- linecap: 'square'
229
+ linecap: 'butt'
224
230
  })
225
231
  .fill('none');
226
232
  const halfJunctionSize = globals_js_1.junctionSize.half();
227
- const highlightJunctionSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.junctionSize.toNumber() + highlightExtraSize);
233
+ const highlightJunctionSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.junctionSize.toNumber() + displayHighlightWidth);
228
234
  const tmpHighlightExtraSize = highlightJunctionSize.half();
229
235
  intersectPoints.forEach(point => {
230
236
  const [x, y,] = point;
@@ -416,9 +416,28 @@ export class Geometry {
416
416
  [segment.end.x, segment.end.y]
417
417
  ];
418
418
  });
419
+ const lines = [];
420
+ let prevPoint;
421
+ let currentLine = [];
422
+ segments.forEach((segment, index) => {
423
+ const [pt1, pt2] = segment;
424
+ if (index === 0 || (prevPoint[0] !== pt1[0] || prevPoint[1] !== pt1[1])) {
425
+ if (currentLine.length > 0) {
426
+ lines.push(currentLine);
427
+ currentLine = [];
428
+ }
429
+ currentLine.push([pt1[0], pt1[1]]);
430
+ }
431
+ currentLine.push(pt2);
432
+ prevPoint = pt2;
433
+ });
434
+ if (currentLine.length > 0) {
435
+ lines.push(currentLine);
436
+ }
419
437
  return {
420
438
  intersectPoints,
421
439
  segments,
440
+ lines,
422
441
  };
423
442
  }
424
443
  }
@@ -103,8 +103,10 @@ export var BlockTypes;
103
103
  export var NetGraphicsParams;
104
104
  (function (NetGraphicsParams) {
105
105
  NetGraphicsParams["Color"] = "color";
106
- NetGraphicsParams["Highight"] = "highlight";
107
106
  NetGraphicsParams["LineWidth"] = "lineWidth";
107
+ NetGraphicsParams["Highlight"] = "highlight";
108
+ NetGraphicsParams["HighlightWidth"] = "highlightWidth";
109
+ NetGraphicsParams["HighlightOpacity"] = "highlightOpacity";
108
110
  })(NetGraphicsParams || (NetGraphicsParams = {}));
109
111
  export var FrameType;
110
112
  (function (FrameType) {
@@ -112,8 +112,19 @@ export class LayoutEngine {
112
112
  const value = net.params.get(NetGraphicsParams.LineWidth);
113
113
  renderNet.lineWidth = milsToMM(value).toNumber();
114
114
  }
115
- if (net.params.has(NetGraphicsParams.Highight)) {
116
- renderNet.highlight = net.params.get(NetGraphicsParams.Highight);
115
+ if (net.params.has(NetGraphicsParams.Highlight)) {
116
+ renderNet.highlight =
117
+ net.params.get(NetGraphicsParams.Highlight);
118
+ }
119
+ if (net.params.has(NetGraphicsParams.HighlightWidth)) {
120
+ renderNet.highlightWidth =
121
+ milsToMM(net.params.get(NetGraphicsParams.HighlightWidth))
122
+ .toNumber();
123
+ }
124
+ if (net.params.has(NetGraphicsParams.HighlightOpacity)) {
125
+ renderNet.highlightOpacity =
126
+ net.params.get(NetGraphicsParams.HighlightOpacity)
127
+ .toNumber();
117
128
  }
118
129
  renderNets.set(net.toString(), renderNet);
119
130
  });
@@ -167,12 +178,13 @@ export class LayoutEngine {
167
178
  });
168
179
  }
169
180
  else {
170
- const { intersectPoints, segments } = Geometry.mergeWires(allLines);
181
+ const { intersectPoints, segments, lines } = Geometry.mergeWires(allLines);
171
182
  mergedWires.push({
172
183
  netName: netName,
173
184
  segments,
174
185
  intersectPoints,
175
186
  net: renderNet,
187
+ lines,
176
188
  });
177
189
  intersectPoints.forEach(([x, y]) => {
178
190
  junctions.push(new RenderJunction(numeric(x), numeric(y), renderNet));
@@ -172,12 +172,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
172
172
  const mergedWireHighlightGroup = canvas.group();
173
173
  const mergedWireGroup = canvas.group();
174
174
  mergedWires.forEach(tmpItem => {
175
- const { segments, intersectPoints, net = null } = tmpItem;
175
+ const { intersectPoints, net = null, lines = null } = tmpItem;
176
176
  let useJunctionColor = ColorScheme.JunctionColor;
177
177
  let useColor = ColorScheme.WireColor;
178
178
  let useLineWidth = defaultWireLineWidth;
179
179
  let displayHighlight = false;
180
180
  let displayHighlightColor = null;
181
+ let displayHighlightOpacity = 0.3;
182
+ let displayHighlightWidth = 5 * MilsToMM;
181
183
  if (net !== null) {
182
184
  useColor = net.color ?? ColorScheme.WireColor;
183
185
  useJunctionColor = net.color ?? ColorScheme.JunctionColor;
@@ -185,25 +187,29 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
185
187
  if (net.highlight !== null) {
186
188
  displayHighlight = true;
187
189
  displayHighlightColor = net.highlight ?? null;
190
+ if (net.highlightOpacity !== undefined) {
191
+ displayHighlightOpacity = net.highlightOpacity;
192
+ }
193
+ if (net.highlightWidth !== undefined) {
194
+ displayHighlightWidth = net.highlightWidth;
195
+ }
188
196
  }
189
197
  }
190
198
  const pathItems = [];
191
- const highlightExtraSize = 5 * MilsToMM;
192
- segments.forEach(segment => {
193
- const pt1 = segment[0];
194
- const pt2 = segment[1];
195
- pathItems.push(...[
196
- 'M', pt1[0], pt1[1],
197
- 'L', pt2[0], pt2[1]
198
- ]);
199
+ const useLines = lines ?? [];
200
+ useLines.forEach(line => {
201
+ line.forEach((point, index) => {
202
+ const commandType = (index === 0) ? 'M' : 'L';
203
+ pathItems.push(...[commandType, point[0], point[1]]);
204
+ });
199
205
  });
200
206
  if (displayHighlight) {
201
207
  mergedWireHighlightGroup.path(pathItems)
202
208
  .stroke({
203
- width: useLineWidth + highlightExtraSize,
209
+ width: useLineWidth + displayHighlightWidth,
204
210
  color: displayHighlightColor,
205
- opacity: 0.3,
206
- linecap: 'square'
211
+ opacity: displayHighlightOpacity,
212
+ linecap: 'butt'
207
213
  })
208
214
  .fill('none');
209
215
  }
@@ -211,11 +217,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
211
217
  .stroke({
212
218
  width: useLineWidth,
213
219
  color: useColor,
214
- linecap: 'square'
220
+ linecap: 'butt'
215
221
  })
216
222
  .fill('none');
217
223
  const halfJunctionSize = junctionSize.half();
218
- const highlightJunctionSize = numeric(junctionSize.toNumber() + highlightExtraSize);
224
+ const highlightJunctionSize = numeric(junctionSize.toNumber() + displayHighlightWidth);
219
225
  const tmpHighlightExtraSize = highlightJunctionSize.half();
220
226
  intersectPoints.forEach(point => {
221
227
  const [x, y,] = point;
@@ -200,7 +200,7 @@ export declare class SymbolDrawingCommands extends SymbolDrawing {
200
200
  clone(): SymbolDrawingCommands;
201
201
  eq(other: SymbolDrawingCommands): boolean;
202
202
  }
203
- type SimplePoint = [x: number, y: number];
203
+ export type SimplePoint = [x: number, y: number];
204
204
  type SymbolPinLayout = {
205
205
  pinId: number;
206
206
  angle: number;
@@ -2,6 +2,7 @@ import Flatten from '@flatten-js/core';
2
2
  import { Box } from '@svgdotjs/svg.js';
3
3
  import { NumericValue } from './objects/ParamDefinition.js';
4
4
  import { PinTypes } from './objects/PinTypes.js';
5
+ import { SimplePoint } from './draw_symbols.js';
5
6
  export type Segment = Flatten.Segment;
6
7
  export type Polygon = Flatten.Polygon;
7
8
  export type Multiline = Flatten.Multiline;
@@ -76,7 +77,8 @@ export declare class Geometry {
76
77
  y: NumericValue;
77
78
  }[][]): {
78
79
  intersectPoints: WirePointCount[];
79
- segments: [x: number, y: number][][];
80
+ segments: SimplePoint[][];
81
+ lines: SimplePoint[][];
80
82
  };
81
83
  }
82
84
  type WirePointCount = [x: number, y: number, count: number];
@@ -90,8 +90,10 @@ export declare enum BlockTypes {
90
90
  }
91
91
  export declare enum NetGraphicsParams {
92
92
  Color = "color",
93
- Highight = "highlight",
94
- LineWidth = "lineWidth"
93
+ LineWidth = "lineWidth",
94
+ Highlight = "highlight",
95
+ HighlightWidth = "highlightWidth",
96
+ HighlightOpacity = "highlightOpacity"
95
97
  }
96
98
  export declare enum FrameType {
97
99
  Frame = 1,
@@ -1,5 +1,5 @@
1
1
  import { Graph } from '@dagrejs/graphlib';
2
- import { SymbolGraphic, SymbolText, SymbolDrawingCommands } from "./draw_symbols.js";
2
+ import { SymbolGraphic, SymbolText, SymbolDrawingCommands, SimplePoint } from "./draw_symbols.js";
3
3
  import { ClassComponent } from "./objects/ClassComponent.js";
4
4
  import { SequenceItem } from "./objects/ExecutionScope.js";
5
5
  import { WireAutoDirection } from './globals.js';
@@ -61,6 +61,7 @@ export type RenderNet = {
61
61
  lineWidth?: number;
62
62
  highlight?: string;
63
63
  highlightOpacity?: number;
64
+ highlightWidth?: number;
64
65
  };
65
66
  export declare class RenderWire extends RenderObject {
66
67
  id: number;
@@ -85,9 +86,10 @@ export declare class RenderWire extends RenderObject {
85
86
  }
86
87
  export type MergedWire = {
87
88
  netName: string;
88
- segments: [x: number, y: number][][];
89
+ segments: SimplePoint[][];
89
90
  intersectPoints: [x: number, y: number, count: number][];
90
91
  net: RenderNet;
92
+ lines?: SimplePoint[][];
91
93
  };
92
94
  export declare class RenderComponent extends RenderObject {
93
95
  component: ClassComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {