本文整理汇总了TypeScript中app/scripts/common.MathUtil.round方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MathUtil.round方法的具体用法?TypeScript MathUtil.round怎么用?TypeScript MathUtil.round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/scripts/common.MathUtil
的用法示例。
在下文中一共展示了MathUtil.round方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getNodeTransforms
const nodeToLayerFn = (node: Element, transforms: ReadonlyArray<Matrix>): Layer => {
if (
!node ||
node.nodeType === Node.TEXT_NODE ||
node.nodeType === Node.COMMENT_NODE ||
node instanceof SVGDefsElement ||
node instanceof SVGUseElement
) {
return undefined;
}
const nodeTransforms = getNodeTransforms(node as SVGGraphicsElement);
transforms = [...transforms, ...nodeTransforms];
const flattenedTransforms = Matrix.flatten(transforms);
// Get the referenced clip-path ID, if one exists.
const refClipPathId = getReferencedClipPathId(node);
const maybeWrapClipPathInGroupFn = (layer: Layer) => {
if (!refClipPathId) {
return layer;
}
const paths = (clipPathMap[refClipPathId] || []).map(p => {
return new Path(
p
.mutate()
.transform(flattenedTransforms)
.build()
.getPathString(),
);
});
if (!paths.length) {
// If the clipPath has no children, then clip the entire layer.
paths.push(new Path('M 0 0 Z'));
}
const groupChildren: Layer[] = paths.map(p => {
return new ClipPathLayer({
name: makeFinalNodeIdFn(refClipPathId, 'mask'),
pathData: p,
children: [],
});
});
groupChildren.push(layer);
return new GroupLayer({
name: makeFinalNodeIdFn('wrapper', 'group'),
children: groupChildren,
});
};
if (node instanceof SVGPathElement && node.getAttribute('d')) {
const path = node.getAttribute('d');
const attrMap: Dictionary<any> = {};
const simpleAttrFn = (nodeAttr: string, contextAttr: string) => {
if (node.hasAttribute(nodeAttr)) {
attrMap[contextAttr] = node.getAttribute(nodeAttr);
}
};
simpleAttrFn('stroke', 'strokeColor');
simpleAttrFn('stroke-width', 'strokeWidth');
simpleAttrFn('stroke-linecap', 'strokeLinecap');
simpleAttrFn('stroke-linejoin', 'strokeLinejoin');
simpleAttrFn('stroke-miterlimit', 'strokeMiterLimit');
simpleAttrFn('stroke-opacity', 'strokeAlpha');
simpleAttrFn('fill', 'fillColor');
simpleAttrFn('fill-opacity', 'fillAlpha');
simpleAttrFn('fill-rule', 'fillType');
// Set the default values as specified by the SVG spec. Note that some of these default
// values are different than the default values used by VectorDrawables.
const fillColor =
'fillColor' in attrMap ? ColorUtil.svgToAndroidColor(attrMap['fillColor']) : '#000';
const strokeColor =
'strokeColor' in attrMap ? ColorUtil.svgToAndroidColor(attrMap['strokeColor']) : undefined;
const fillAlpha = 'fillAlpha' in attrMap ? Number(attrMap['fillAlpha']) : 1;
let strokeWidth = 'strokeWidth' in attrMap ? Number(attrMap['strokeWidth']) : 1;
const strokeAlpha = 'strokeAlpha' in attrMap ? Number(attrMap['strokeAlpha']) : 1;
const strokeLinecap: StrokeLineCap =
'strokeLinecap' in attrMap ? attrMap['strokeLinecap'] : 'butt';
const strokeLinejoin: StrokeLineJoin =
'strokeLinejoin' in attrMap ? attrMap['strokeLinecap'] : 'miter';
const strokeMiterLimit =
'strokeMiterLimit' in attrMap ? Number(attrMap['strokeMiterLimit']) : 4;
const fillRuleToFillTypeFn = (fillRule: string) => {
return fillRule === 'evenodd' ? 'evenOdd' : 'nonZero';
};
const fillType: FillType =
'fillType' in attrMap ? fillRuleToFillTypeFn(attrMap['fillType']) : 'nonZero';
let pathData = new Path(path);
if (transforms.length) {
pathData = new Path(
pathData
.mutate()
.transform(flattenedTransforms)
.build()
.getPathString(),
);
strokeWidth = MathUtil.round(strokeWidth * flattenedTransforms.getScaleFactor());
}
//.........这里部分代码省略.........