Skip to content

Commit 28912c5

Browse files
committed
main
1 parent 610ff64 commit 28912c5

4 files changed

Lines changed: 74 additions & 16 deletions

File tree

src/use-cases/plan/ComputePlanEmbellishments.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export interface ComputePlanEmbellishmentsResponse {
1717
export class ComputePlanEmbellishments {
1818
private readonly frame_x_percent = 0.9;
1919
private readonly frame_y_percent = 1.5;
20+
private readonly font_size_percent = 0.0127;
21+
private readonly beacon_size_percent = 0.0127;
22+
private readonly label_size_percent = 0.0088;
23+
private readonly footer_size_percent = 0.0088;
24+
private readonly point_label_scale_percent = 0.0014;
25+
private readonly contour_label_scale_percent = 0.00488;
2026

2127
constructor(private readonly logger: Logger) {}
2228

@@ -45,15 +51,15 @@ export class ComputePlanEmbellishments {
4551

4652
// calculate area of frame
4753
const frameArea = (frameRight - frameLeft) * (frameTop - frameBottom);
48-
console.log(`Frame Area: ${frameArea}`);
54+
const areaSqrt = Math.sqrt(frameArea);
4955

5056
return {
51-
font_size: 0,
52-
beacon_size: 0,
53-
label_size: 0,
54-
footer_size: 0,
55-
point_label_scale: 0,
56-
contour_label_scale: 0,
57+
font_size: Math.ceil(areaSqrt * this.font_size_percent * 10) / 10,
58+
beacon_size: Math.ceil(areaSqrt * this.beacon_size_percent * 10) / 10,
59+
label_size: Math.ceil(areaSqrt * this.label_size_percent * 10) / 10,
60+
footer_size: Math.ceil(areaSqrt * this.footer_size_percent * 10) / 10,
61+
point_label_scale: Math.ceil(areaSqrt * this.point_label_scale_percent * 10) / 10,
62+
contour_label_scale: Math.ceil(areaSqrt * this.contour_label_scale_percent * 10) / 10,
5763
};
5864
}
5965
}

src/use-cases/plan/CreatePlan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class CreatePlan {
5353
show_spot_heights: true,
5454
point_label_scale: 0.2,
5555
show_contours: true,
56-
contour_interval: 1,
57-
major_contour: 5,
56+
contour_interval: 0.1,
57+
major_contour: 0.5,
5858
minimum_distance: 0.1,
5959
show_contours_labels: true,
6060
contour_label_scale: 0.5,

src/use-cases/plan/EditCoordinates.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CoordinateProps } from '@domain/entities/Coordinate';
22
import { Logger, RepoOptions } from '@domain/types/Common';
33
import { PlanRepositoryInterface } from '@domain/interfaces/repositories/PlanRepositoryInterface';
4-
import { Plan } from '@domain/entities/Plan';
4+
import { Plan, PlanProps, PlanType } from '@domain/entities/Plan';
55
import NotFoundError from '@domain/errors/NotFoundError';
66
import { ComputePlanEmbellishments } from '@use-cases/plan/ComputePlanEmbellishments';
77

@@ -24,6 +24,12 @@ export class EditCoordinates {
2424
async execute(data: EditCoordinatesRequest): Promise<Plan> {
2525
this.logger.info('EditCoordinates', data);
2626

27+
// fetch plan
28+
let plan = await this.planRepo.getPlanById(data.plan_id, data.options);
29+
if (!plan) {
30+
throw new NotFoundError('Plan not found');
31+
}
32+
2733
// check for duplicate coordinates
2834
const check: Record<string, boolean> = {};
2935
const updatedCoordinates: CoordinateProps[] = [];
@@ -37,9 +43,28 @@ export class EditCoordinates {
3743
}
3844

3945
// compute embellishments
40-
this.computeEmbellishments.execute({ coordinates: updatedCoordinates });
46+
const embellishmentCoordinates = [...updatedCoordinates];
47+
if (plan.type === PlanType.TOPOGRAPHIC && plan.topographic_boundary && plan.topographic_boundary.coordinates) {
48+
embellishmentCoordinates.push(...plan.topographic_boundary.coordinates);
49+
}
50+
51+
const embellishments = this.computeEmbellishments.execute({ coordinates: embellishmentCoordinates });
52+
53+
const update: Partial<PlanProps> = {
54+
coordinates: updatedCoordinates,
55+
font_size: embellishments.font_size,
56+
beacon_size: embellishments.beacon_size,
57+
label_size: embellishments.label_size,
58+
footer_size: embellishments.footer_size,
59+
};
60+
61+
if (plan.type === PlanType.TOPOGRAPHIC && plan.topographic_setting) {
62+
plan.topographic_setting.point_label_scale = embellishments.point_label_scale;
63+
plan.topographic_setting.contour_label_scale = embellishments.contour_label_scale;
64+
update.topographic_setting = plan.topographic_setting;
65+
}
4166

42-
const plan = await this.planRepo.editPlan(data.plan_id, { coordinates: updatedCoordinates }, data.options);
67+
plan = await this.planRepo.editPlan(data.plan_id, update, data.options);
4368
if (!plan) {
4469
throw new NotFoundError('Plan not found');
4570
}

src/use-cases/plan/EditTopoBoundary.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Plan, PlanType, TopographicBoundary } from '@domain/entities/Plan';
1+
import { Plan, PlanProps, PlanType, TopographicBoundary } from '@domain/entities/Plan';
22
import { Logger, RepoOptions } from '@domain/types/Common';
33
import { PlanRepositoryInterface } from '@domain/interfaces/repositories/PlanRepositoryInterface';
44
import NotFoundError from '@domain/errors/NotFoundError';
55
import BadRequestError from '@domain/errors/BadRequestError';
6+
import { ComputePlanEmbellishments } from '@use-cases/plan/ComputePlanEmbellishments';
67

78
export interface EditTopoBoundaryRequest {
89
plan_id: string;
@@ -11,16 +12,24 @@ export interface EditTopoBoundaryRequest {
1112
}
1213

1314
export class EditTopoBoundary {
15+
private readonly computeEmbellishments: ComputePlanEmbellishments;
16+
1417
constructor(
1518
private readonly logger: Logger,
1619
private readonly planRepo: PlanRepositoryInterface,
17-
) {}
20+
) {
21+
this.computeEmbellishments = new ComputePlanEmbellishments(logger);
22+
}
1823

1924
async execute(data: EditTopoBoundaryRequest): Promise<Plan> {
2025
this.logger.info('EditTopoBoundary', data);
2126

2227
const filter = data.options?.filter || {};
23-
let plan = await this.planRepo.getPlanById(data.plan_id, { projection: { type: 1 }, filter });
28+
let plan = await this.planRepo.getPlanById(data.plan_id, {
29+
projection: { type: 1, coordinates: 1, topographic_setting: 1 },
30+
filter,
31+
});
32+
2433
if (!plan) {
2534
throw new NotFoundError('Plan not found');
2635
}
@@ -46,7 +55,25 @@ export class EditTopoBoundary {
4655
data.boundary.coordinates.push(data.boundary.coordinates[0]);
4756
}
4857

49-
plan = await this.planRepo.editPlan(data.plan_id, { topographic_boundary: data.boundary }, data.options);
58+
// compute embellishments
59+
const embellishmentCoordinates = [...data.boundary.coordinates, ...(plan.coordinates || [])];
60+
const embellishments = this.computeEmbellishments.execute({ coordinates: embellishmentCoordinates });
61+
62+
const update: Partial<PlanProps> = {
63+
topographic_boundary: data.boundary,
64+
font_size: embellishments.font_size,
65+
beacon_size: embellishments.beacon_size,
66+
label_size: embellishments.label_size,
67+
footer_size: embellishments.footer_size,
68+
};
69+
70+
if (plan.topographic_setting) {
71+
plan.topographic_setting.point_label_scale = embellishments.point_label_scale;
72+
plan.topographic_setting.contour_label_scale = embellishments.contour_label_scale;
73+
update.topographic_setting = plan.topographic_setting;
74+
}
75+
76+
plan = await this.planRepo.editPlan(data.plan_id, update, data.options);
5077
if (!plan) {
5178
throw new NotFoundError('Plan not found');
5279
}

0 commit comments

Comments
 (0)