Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional types #185

Open
wants to merge 4 commits into
base: release_1.6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/dotTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DotTypes } from "../types";
export default {
dots: "dots",
rounded: "rounded",
verticalLines: "vertical-lines",
classy: "classy",
classyRounded: "classy-rounded",
square: "square",
Expand Down
37 changes: 37 additions & 0 deletions src/figures/dot/QRDot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class QRDot {
case dotTypes.rounded:
drawFunction = this._drawRounded;
break;
case dotTypes.verticalLines:
drawFunction = this._drawVerticalLines;
break;
case dotTypes.extraRounded:
drawFunction = this._drawExtraRounded;
break;
Expand Down Expand Up @@ -212,6 +215,40 @@ export default class QRDot {
}
}

_drawVerticalLines({ x, y, size, getNeighbor }: DrawArgs): void {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

const leftNeighbor = getNeighbor ? +getNeighbor(-1, 0) : 0;
const rightNeighbor = getNeighbor ? +getNeighbor(1, 0) : 0;
const topNeighbor = getNeighbor ? +getNeighbor(0, -1) : 0;
const bottomNeighbor = getNeighbor ? +getNeighbor(0, 1) : 0;

const neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + bottomNeighbor;

if (
neighborsCount === 0 ||
(leftNeighbor && !(topNeighbor || bottomNeighbor)) ||
(rightNeighbor && !(topNeighbor || bottomNeighbor))
) {
this._basicDot({ x, y, size, rotation: 0 });
return;
}

if (topNeighbor && bottomNeighbor) {
this._basicSquare({ x, y, size, rotation: 0 });
return;
}

if (topNeighbor && !bottomNeighbor) {
const rotation = Math.PI / 2;
this._basicSideRounded({ x, y, size, rotation });
return;
}

if (bottomNeighbor && !topNeighbor) {
const rotation = -Math.PI / 2;
this._basicSideRounded({ x, y, size, rotation });
return;
}
}
_drawExtraRounded({ x, y, size, getNeighbor }: DrawArgs): void {
const leftNeighbor = getNeighbor ? +getNeighbor(-1, 0) : 0;
const rightNeighbor = getNeighbor ? +getNeighbor(1, 0) : 0;
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface UnknownObject {
[key: string]: any;
}

export type DotType = "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded";
export type DotType = "dots" | "rounded" | "vertical-lines" | "classy" | "classy-rounded" | "square" | "extra-rounded";
export type CornerDotType = "dot" | "square";
export type CornerSquareType = "dot" | "square" | "extra-rounded";
export type FileExtension = "svg" | "png" | "jpeg" | "webp";
Expand Down