This commit is contained in:
parent
171fbf1927
commit
8bf3e3b705
40 changed files with 1443 additions and 1497 deletions
49
src/lib/planning.ts
Normal file
49
src/lib/planning.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { buildGeometry } from './geometry';
|
||||
import { planFlooringOptions } from './flooring';
|
||||
import { planSkirting } from './skirting';
|
||||
import type { FlooringOptions } from './flooring';
|
||||
import type { Geometry, Project, SkirtingPlan } from './types';
|
||||
|
||||
/** One calculator per editor. Compare calculation inputs, excluding names and progress. */
|
||||
export function createPlanCalculator() {
|
||||
let previous: Project | undefined;
|
||||
let geometries: Geometry[] = [];
|
||||
let flooringOptions: FlooringOptions;
|
||||
let skirting: SkirtingPlan;
|
||||
return (project: Project) => {
|
||||
const sameOutlines =
|
||||
previous &&
|
||||
previous.tolerance === project.tolerance &&
|
||||
previous.rooms.length === project.rooms.length &&
|
||||
project.rooms.every(
|
||||
(room, i) => room.id === previous!.rooms[i].id && room.walls === previous!.rooms[i].walls,
|
||||
);
|
||||
const sameDirections =
|
||||
sameOutlines &&
|
||||
project.rooms.every((room, i) => room.direction === previous!.rooms[i].direction);
|
||||
const sameFlooring =
|
||||
previous &&
|
||||
Object.entries(project.flooring).every(
|
||||
([key, value]) => key === 'optimisation' || Reflect.get(previous!.flooring, key) === value,
|
||||
);
|
||||
if (!sameOutlines)
|
||||
geometries = project.rooms.map((room, i) =>
|
||||
previous?.tolerance === project.tolerance &&
|
||||
previous.rooms[i]?.id === room.id &&
|
||||
previous.rooms[i]?.walls === room.walls
|
||||
? geometries[i]
|
||||
: buildGeometry(room, project.tolerance),
|
||||
);
|
||||
if (!sameDirections || !sameFlooring)
|
||||
flooringOptions = planFlooringOptions(
|
||||
project.rooms,
|
||||
project.flooring,
|
||||
project.tolerance,
|
||||
geometries,
|
||||
);
|
||||
if (!sameOutlines || previous?.skirting !== project.skirting)
|
||||
skirting = planSkirting(project.rooms, project.skirting, project.tolerance, geometries);
|
||||
previous = project;
|
||||
return { geometries, flooringOptions: flooringOptions!, skirting: skirting! };
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue