/** 등분(DIVIDE)·길이분할(MEASURE) — 객체를 자르지 않고 점만 놓는다 */ import { toast } from 'react-toastify'; import { dividePoints, measurePoints, sampleEntityPoints, } from '../../helpers/geometry/sample-entity'; import { addEntities } from '../../state'; import { Tool } from '../../tools'; import { pointEntity } from '../factories/entity-factory'; import { createSequenceTool } from '../factories/sequence-tool'; export const divideToolStateMachine = createSequenceTool({ tool: Tool.DIVIDE, helpers: false, steps: [ { kind: 'entity', instructions: '등분할 객체를 선택하십시오.' }, { kind: 'number', instructions: '세그먼트 수를 입력하십시오 <4>.', defaultValue: 4 }, ], commit: (input) => { const points = dividePoints(sampleEntityPoints(input.entity(0)), input.number(1)); if (!points.length) { toast.warn('등분할 수 없는 객체입니다.'); return; } addEntities(points.map(pointEntity), true); }, }); export const measureLengthToolStateMachine = createSequenceTool({ tool: Tool.MEASURE_LENGTH, helpers: false, steps: [ { kind: 'entity', instructions: '길이로 분할할 객체를 선택하십시오.' }, { kind: 'number', instructions: '세그먼트 길이를 입력하십시오 <10>.', defaultValue: 10 }, ], commit: (input) => { const points = measurePoints(sampleEntityPoints(input.entity(0)), input.number(1)); if (!points.length) { toast.warn('지정한 길이로 나눌 수 없습니다.'); return; } addEntities(points.map(pointEntity), true); }, });