Skip to content

Commit ca2f413

Browse files
committed
refactor: move mmToPix const to a common file
1 parent e0c934f commit ca2f413

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

src/7segment-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css, customElement, html, LitElement, property, svg } from 'lit-element';
22
import { ElementPin } from './pin';
3+
import { mmToPix } from './utils/units';
34

45
@customElement('wokwi-7segment')
56
export class SevenSegmentElement extends LitElement {
@@ -42,7 +43,6 @@ export class SevenSegmentElement extends LitElement {
4243
const col = (n - 1) % cols;
4344
const row = 1 - Math.floor((n - 1) / cols);
4445
const xOffset = 1.27;
45-
const mmToPix = 3.78;
4646
const x = startX + xOffset + (row ? col : cols - col - 1) * 2.54;
4747
const y = this.pins === 'top' ? (row ? bottomY + 1 : 1) : row ? bottomY + 2 : 0;
4848
return { number: n, x: x * mmToPix, y: y * mmToPix };

src/led-ring-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { customElement, html, LitElement, property, svg } from 'lit-element';
22
import { ElementPin } from './pin';
33
import { RGB } from './types/rgb';
4+
import { mmToPix } from './utils/units';
45

56
const pinHeight = 3;
67
const pcbWidth = 6;
@@ -39,7 +40,6 @@ export class LEDRingElement extends LitElement {
3940

4041
get pinInfo(): ElementPin[] {
4142
const { radius } = this;
42-
const mmToPix = 3.78;
4343
const pinSpacing = 2.54;
4444
const y = (radius * 2 + pinHeight) * mmToPix;
4545
const cx = radius * mmToPix;

src/neopixel-matrix-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { css, customElement, html, LitElement, property, svg } from 'lit-element';
22
import { ElementPin, GND, VCC } from './pin';
33
import { RGB } from './types/rgb';
4+
import { mmToPix } from './utils/units';
45

56
const pixelWidth = 5.66;
67
const pixelHeight = 5;
@@ -52,7 +53,6 @@ export class NeopixelMatrixElement extends LitElement {
5253

5354
get pinInfo(): ElementPin[] {
5455
const { cols, rows, rowSpacing, colSpacing } = this;
55-
const mmToPix = 3.78;
5656
const pinSpacing = 2.54;
5757
const p = pinSpacing * mmToPix;
5858
const cx = ((cols * (colSpacing + pixelWidth)) / 2) * mmToPix;

src/utils/units.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const mmToPix = 3.78;

0 commit comments

Comments
 (0)