mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-21 16:05:44 +01:00
31 lines
847 B
TypeScript
31 lines
847 B
TypeScript
import {Materializer} from "cad/craft/schema/types/index";
|
|
import {CoreContext} from "context";
|
|
import {OperationParamsErrorReporter} from "cad/craft/schema/schema";
|
|
import Vector from "math/vector";
|
|
import {MObject} from "cad/model/mobject";
|
|
import {ObjectTypeSchema} from "cad/craft/schema/types/objectType";
|
|
|
|
type VectorInput = {
|
|
vectorEntity: MObject,
|
|
flip: boolean
|
|
}
|
|
|
|
export function VectorResolver(ctx: CoreContext,
|
|
value: VectorInput,
|
|
md: ObjectTypeSchema,
|
|
reportError: OperationParamsErrorReporter,
|
|
materializer: Materializer): Vector {
|
|
|
|
if (!value.vectorEntity) {
|
|
return null;
|
|
}
|
|
|
|
let vector = value.vectorEntity.toDirection();
|
|
if (!vector) {
|
|
throw 'unsupported entity type: ' + value.vectorEntity.TYPE;
|
|
}
|
|
if (value.flip) {
|
|
vector = vector.negate();
|
|
}
|
|
return vector;
|
|
}
|