refactoring (moving stuff around)

This commit is contained in:
Jörn-Michael Miehe 2023-09-07 02:08:56 +00:00
parent 3ce2480dcc
commit f603a9947c
16 changed files with 99 additions and 93 deletions

View file

@ -24,13 +24,11 @@ import { Options, Vue } from "vue-class-component";
import DoorMapEditor from "./components/DoorMapEditor.vue"; import DoorMapEditor from "./components/DoorMapEditor.vue";
import LoginModal from "./components/LoginModal.vue"; import LoginModal from "./components/LoginModal.vue";
import MultiModal from "./components/MultiModal.vue";
@Options({ @Options({
components: { components: {
DoorMapEditor, DoorMapEditor,
LoginModal, LoginModal,
MultiModal,
}, },
}) })
export default class extends Vue { export default class extends Vue {
@ -39,7 +37,6 @@ export default class extends Vue {
declare $refs: { declare $refs: {
login_modal: LoginModal; login_modal: LoginModal;
multi_modal: MultiModal;
}; };
public mounted() { public mounted() {

View file

@ -19,12 +19,12 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Door } from "./door_map/calendar";
import CalendarDoor from "./CalendarDoor.vue"; import CalendarDoor from "./calendar/CalendarDoor.vue";
import MultiModal from "./MultiModal.vue"; import MultiModal from "./calendar/MultiModal.vue";
import ThouCanvas from "./rects/ThouCanvas.vue"; import ThouCanvas from "./calendar/ThouCanvas.vue";
@Options({ @Options({
components: { components: {

View file

@ -11,13 +11,13 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Door } from "./door_map/calendar";
import BulmaBreadcrumbs, { Step } from "./BulmaBreadcrumbs.vue"; import BulmaBreadcrumbs, { Step } from "./BulmaBreadcrumbs.vue";
import Calendar from "./Calendar.vue"; import Calendar from "./Calendar.vue";
import DoorChooser from "./door_map/DoorChooser.vue"; import DoorChooser from "./calendar/editor/DoorChooser.vue";
import DoorPlacer from "./door_map/DoorPlacer.vue"; import DoorPlacer from "./calendar/editor/DoorPlacer.vue";
@Options({ @Options({
components: { components: {

View file

@ -3,11 +3,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import { Options, Vue } from "vue-class-component"; 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({ @Options({
components: { components: {

View file

@ -9,8 +9,8 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Rectangle } from "@/lib/rectangle";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Rectangle } from "./rectangles";
@Options({ @Options({
props: { props: {

View file

@ -16,8 +16,8 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Vector2D } from "@/lib/vector2d";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Vector2D } from "./rectangles";
function get_event_thous(event: MouseEvent): Vector2D { function get_event_thous(event: MouseEvent): Vector2D {
if (event.currentTarget === null) { if (event.currentTarget === null) {

View file

@ -24,10 +24,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { Options, Vue } from "vue-class-component"; 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"; import PreviewDoor from "./PreviewDoor.vue";
@Options({ @Options({

View file

@ -21,10 +21,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { Rectangle } from "@/lib/rectangle";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Rectangle } from "../rects/rectangles";
import RectangleCanvas from "./RectangleCanvas.vue"; import RectangleCanvas from "./RectangleCanvas.vue";
import { Door } from "./calendar";
@Options({ @Options({
components: { components: {

View file

@ -30,10 +30,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Door } from "@/lib/door";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { Door } from "./calendar";
import SVGRect from "../rects/SVGRect.vue"; import SVGRect from "../SVGRect.vue";
@Options({ @Options({
components: { components: {

View file

@ -18,10 +18,12 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Rectangle } from "@/lib/rectangle";
import { Vector2D } from "@/lib/vector2d";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import SVGRect from "../rects/SVGRect.vue";
import ThouCanvas from "../rects/ThouCanvas.vue"; import SVGRect from "../SVGRect.vue";
import { Rectangle, Vector2D } from "../rects/rectangles"; import ThouCanvas from "../ThouCanvas.vue";
enum CanvasState { enum CanvasState {
Idle, Idle,

View file

@ -1,4 +1,4 @@
import { Rectangle } from "../rects/rectangles"; import { Rectangle } from "./rectangle";
export class Door { export class Door {
private _day = -1; private _day = -1;

View file

@ -1,28 +1,4 @@
export class Vector2D { import { Vector2D } from "./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;
}
}
export class Rectangle { export class Rectangle {
private readonly corner_1: Vector2D; private readonly corner_1: Vector2D;

25
ui/src/lib/vector2d.ts Normal file
View 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;
}
}

View file

@ -1,56 +1,21 @@
import { Rectangle, Vector2D } from '@/components/rects/rectangles';
import { expect } from "chai"; import { expect } from "chai";
describe("Vector2D Tests", () => { import { Rectangle } from "@/lib/rectangle";
const v = new Vector2D(1, 2); import { Vector2D } from "@/lib/vector2d";
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;
})
});
describe("Rectangle Tests", () => { describe("Rectangle Tests", () => {
const v1 = new Vector2D(1, 2); const v1 = new Vector2D(1, 2);
const v2 = new Vector2D(4, 6); const v2 = new Vector2D(4, 6);
const r1 = new Rectangle(v1, v2); const r1 = new Rectangle(v1, v2);
const r2 = new Rectangle(v2, v1); const r2 = new Rectangle(v2, v1);
function check_rectangle( function check_rectangle(
r: Rectangle, r: Rectangle,
left: number, top: number, left: number,
width: number, height: number, top: number,
width: number,
height: number,
) { ) {
expect(r.left).to.equal(left); expect(r.left).to.equal(left);
expect(r.top).to.equal(top); 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.x).to.equal(left + 0.5 * width);
expect(r.middle.y).to.equal(top + 0.5 * height); expect(r.middle.y).to.equal(top + 0.5 * height);
} }
it("should create a default rectangle", () => { it("should create a default rectangle", () => {
@ -79,7 +43,7 @@ describe("Rectangle Tests", () => {
it("should compare rectangles", () => { it("should compare rectangles", () => {
expect(r1.equals(r2)).to.be.true; expect(r1.equals(r2)).to.be.true;
expect(r1.equals(new Rectangle())).to.be.false; expect(r1.equals(new Rectangle())).to.be.false;
}) });
it("should create the same rectangle transposed", () => { it("should create the same rectangle transposed", () => {
const v1t = new Vector2D(v1.x, v2.y); const v1t = new Vector2D(v1.x, v2.y);
@ -123,4 +87,4 @@ describe("Rectangle Tests", () => {
check_rectangle(r1.move(v), 2, 3, 3, 4); check_rectangle(r1.move(v), 2, 3, 3, 4);
}); });
}); });

View 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;
});
});