mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-22 15:53:01 +00:00
refactoring (moving stuff around)
This commit is contained in:
parent
3ce2480dcc
commit
f603a9947c
16 changed files with 99 additions and 93 deletions
|
@ -24,13 +24,11 @@ import { Options, Vue } from "vue-class-component";
|
|||
|
||||
import DoorMapEditor from "./components/DoorMapEditor.vue";
|
||||
import LoginModal from "./components/LoginModal.vue";
|
||||
import MultiModal from "./components/MultiModal.vue";
|
||||
|
||||
@Options({
|
||||
components: {
|
||||
DoorMapEditor,
|
||||
LoginModal,
|
||||
MultiModal,
|
||||
},
|
||||
})
|
||||
export default class extends Vue {
|
||||
|
@ -39,7 +37,6 @@ export default class extends Vue {
|
|||
|
||||
declare $refs: {
|
||||
login_modal: LoginModal;
|
||||
multi_modal: MultiModal;
|
||||
};
|
||||
|
||||
public mounted() {
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Door } from "./door_map/calendar";
|
||||
|
||||
import CalendarDoor from "./CalendarDoor.vue";
|
||||
import MultiModal from "./MultiModal.vue";
|
||||
import ThouCanvas from "./rects/ThouCanvas.vue";
|
||||
import CalendarDoor from "./calendar/CalendarDoor.vue";
|
||||
import MultiModal from "./calendar/MultiModal.vue";
|
||||
import ThouCanvas from "./calendar/ThouCanvas.vue";
|
||||
|
||||
@Options({
|
||||
components: {
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Door } from "./door_map/calendar";
|
||||
|
||||
import BulmaBreadcrumbs, { Step } from "./BulmaBreadcrumbs.vue";
|
||||
import Calendar from "./Calendar.vue";
|
||||
import DoorChooser from "./door_map/DoorChooser.vue";
|
||||
import DoorPlacer from "./door_map/DoorPlacer.vue";
|
||||
import DoorChooser from "./calendar/editor/DoorChooser.vue";
|
||||
import DoorPlacer from "./calendar/editor/DoorPlacer.vue";
|
||||
|
||||
@Options({
|
||||
components: {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { AxiosError } from "axios";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Door } from "./door_map/calendar";
|
||||
|
||||
import SVGRect from "./rects/SVGRect.vue";
|
||||
import SVGRect from "./SVGRect.vue";
|
||||
|
||||
@Options({
|
||||
components: {
|
|
@ -9,8 +9,8 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Rectangle } from "@/lib/rectangle";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Rectangle } from "./rectangles";
|
||||
|
||||
@Options({
|
||||
props: {
|
|
@ -16,8 +16,8 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vector2D } from "@/lib/vector2d";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Vector2D } from "./rectangles";
|
||||
|
||||
function get_event_thous(event: MouseEvent): Vector2D {
|
||||
if (event.currentTarget === null) {
|
|
@ -24,10 +24,10 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Door } from "./calendar";
|
||||
|
||||
import ThouCanvas from "../rects/ThouCanvas.vue";
|
||||
import ThouCanvas from "../ThouCanvas.vue";
|
||||
import PreviewDoor from "./PreviewDoor.vue";
|
||||
|
||||
@Options({
|
|
@ -21,10 +21,11 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { Rectangle } from "@/lib/rectangle";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Rectangle } from "../rects/rectangles";
|
||||
|
||||
import RectangleCanvas from "./RectangleCanvas.vue";
|
||||
import { Door } from "./calendar";
|
||||
|
||||
@Options({
|
||||
components: {
|
|
@ -30,10 +30,10 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Door } from "@/lib/door";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Door } from "./calendar";
|
||||
|
||||
import SVGRect from "../rects/SVGRect.vue";
|
||||
import SVGRect from "../SVGRect.vue";
|
||||
|
||||
@Options({
|
||||
components: {
|
|
@ -18,10 +18,12 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Rectangle } from "@/lib/rectangle";
|
||||
import { Vector2D } from "@/lib/vector2d";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import SVGRect from "../rects/SVGRect.vue";
|
||||
import ThouCanvas from "../rects/ThouCanvas.vue";
|
||||
import { Rectangle, Vector2D } from "../rects/rectangles";
|
||||
|
||||
import SVGRect from "../SVGRect.vue";
|
||||
import ThouCanvas from "../ThouCanvas.vue";
|
||||
|
||||
enum CanvasState {
|
||||
Idle,
|
|
@ -1,4 +1,4 @@
|
|||
import { Rectangle } from "../rects/rectangles";
|
||||
import { Rectangle } from "./rectangle";
|
||||
|
||||
export class Door {
|
||||
private _day = -1;
|
|
@ -1,28 +1,4 @@
|
|||
export class Vector2D {
|
||||
public readonly x: number;
|
||||
public readonly y: number;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public plus(other: Vector2D): Vector2D {
|
||||
return new Vector2D(this.x + other.x, this.y + other.y);
|
||||
}
|
||||
|
||||
public minus(other: Vector2D): Vector2D {
|
||||
return new Vector2D(this.x - other.x, this.y - other.y);
|
||||
}
|
||||
|
||||
public scale(other: number): Vector2D {
|
||||
return new Vector2D(this.x * other, this.y * other);
|
||||
}
|
||||
|
||||
public equals(other: Vector2D): boolean {
|
||||
return this.x === other.x && this.y === other.y;
|
||||
}
|
||||
}
|
||||
import { Vector2D } from "./vector2d";
|
||||
|
||||
export class Rectangle {
|
||||
private readonly corner_1: Vector2D;
|
25
ui/src/lib/vector2d.ts
Normal file
25
ui/src/lib/vector2d.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
export class Vector2D {
|
||||
public readonly x: number;
|
||||
public readonly y: number;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public plus(other: Vector2D): Vector2D {
|
||||
return new Vector2D(this.x + other.x, this.y + other.y);
|
||||
}
|
||||
|
||||
public minus(other: Vector2D): Vector2D {
|
||||
return new Vector2D(this.x - other.x, this.y - other.y);
|
||||
}
|
||||
|
||||
public scale(other: number): Vector2D {
|
||||
return new Vector2D(this.x * other, this.y * other);
|
||||
}
|
||||
|
||||
public equals(other: Vector2D): boolean {
|
||||
return this.x === other.x && this.y === other.y;
|
||||
}
|
||||
}
|
|
@ -1,56 +1,21 @@
|
|||
import { Rectangle, Vector2D } from '@/components/rects/rectangles';
|
||||
import { expect } from "chai";
|
||||
|
||||
describe("Vector2D Tests", () => {
|
||||
const v = new Vector2D(1, 2);
|
||||
|
||||
it("should create a default vector", () => {
|
||||
const v0 = new Vector2D();
|
||||
expect(v0.x).to.equal(0);
|
||||
expect(v0.y).to.equal(0);
|
||||
});
|
||||
|
||||
it("should create a vector", () => {
|
||||
expect(v.x).to.equal(1);
|
||||
expect(v.y).to.equal(2);
|
||||
});
|
||||
|
||||
it("should add vectors", () => {
|
||||
const v2 = v.plus(new Vector2D(3, 4));
|
||||
expect(v2.x).to.equal(4);
|
||||
expect(v2.y).to.equal(6);
|
||||
});
|
||||
|
||||
it("should subtract vectors", () => {
|
||||
const v2 = v.minus(new Vector2D(3, 4));
|
||||
expect(v2.x).to.equal(-2);
|
||||
expect(v2.y).to.equal(-2);
|
||||
});
|
||||
|
||||
it("should scale vectors", () => {
|
||||
const v2 = v.scale(3);
|
||||
expect(v2.x).to.equal(3);
|
||||
expect(v2.y).to.equal(6);
|
||||
});
|
||||
|
||||
it("should compare vectors", () => {
|
||||
expect(v.equals(v.scale(1))).to.be.true;
|
||||
expect(v.equals(v.scale(2))).to.be.false;
|
||||
})
|
||||
});
|
||||
import { Rectangle } from "@/lib/rectangle";
|
||||
import { Vector2D } from "@/lib/vector2d";
|
||||
|
||||
describe("Rectangle Tests", () => {
|
||||
const v1 = new Vector2D(1, 2);
|
||||
const v2 = new Vector2D(4, 6);
|
||||
|
||||
|
||||
const r1 = new Rectangle(v1, v2);
|
||||
const r2 = new Rectangle(v2, v1);
|
||||
|
||||
function check_rectangle(
|
||||
r: Rectangle,
|
||||
left: number, top: number,
|
||||
width: number, height: number,
|
||||
left: number,
|
||||
top: number,
|
||||
width: number,
|
||||
height: number,
|
||||
) {
|
||||
expect(r.left).to.equal(left);
|
||||
expect(r.top).to.equal(top);
|
||||
|
@ -61,7 +26,6 @@ describe("Rectangle Tests", () => {
|
|||
|
||||
expect(r.middle.x).to.equal(left + 0.5 * width);
|
||||
expect(r.middle.y).to.equal(top + 0.5 * height);
|
||||
|
||||
}
|
||||
|
||||
it("should create a default rectangle", () => {
|
||||
|
@ -79,7 +43,7 @@ describe("Rectangle Tests", () => {
|
|||
it("should compare rectangles", () => {
|
||||
expect(r1.equals(r2)).to.be.true;
|
||||
expect(r1.equals(new Rectangle())).to.be.false;
|
||||
})
|
||||
});
|
||||
|
||||
it("should create the same rectangle transposed", () => {
|
||||
const v1t = new Vector2D(v1.x, v2.y);
|
||||
|
|
41
ui/tests/unit/vector2d.spec.ts
Normal file
41
ui/tests/unit/vector2d.spec.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { expect } from "chai";
|
||||
|
||||
import { Vector2D } from "@/lib/vector2d";
|
||||
|
||||
describe("Vector2D Tests", () => {
|
||||
const v = new Vector2D(1, 2);
|
||||
|
||||
it("should create a default vector", () => {
|
||||
const v0 = new Vector2D();
|
||||
expect(v0.x).to.equal(0);
|
||||
expect(v0.y).to.equal(0);
|
||||
});
|
||||
|
||||
it("should create a vector", () => {
|
||||
expect(v.x).to.equal(1);
|
||||
expect(v.y).to.equal(2);
|
||||
});
|
||||
|
||||
it("should add vectors", () => {
|
||||
const v2 = v.plus(new Vector2D(3, 4));
|
||||
expect(v2.x).to.equal(4);
|
||||
expect(v2.y).to.equal(6);
|
||||
});
|
||||
|
||||
it("should subtract vectors", () => {
|
||||
const v2 = v.minus(new Vector2D(3, 4));
|
||||
expect(v2.x).to.equal(-2);
|
||||
expect(v2.y).to.equal(-2);
|
||||
});
|
||||
|
||||
it("should scale vectors", () => {
|
||||
const v2 = v.scale(3);
|
||||
expect(v2.x).to.equal(3);
|
||||
expect(v2.y).to.equal(6);
|
||||
});
|
||||
|
||||
it("should compare vectors", () => {
|
||||
expect(v.equals(v.scale(1))).to.be.true;
|
||||
expect(v.equals(v.scale(2))).to.be.false;
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue