From b9a8682f7eeb3c30a84753888aca0029dff04b70 Mon Sep 17 00:00:00 2001 From: Yuan Date: Thu, 14 Dec 2023 13:46:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=B8=E9=99=84=E7=82=B9=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/graphic/AbsorbablePosition.d.ts | 2 +- lib/index.js | 50 ++++++++++++++++++++++++++++- src/graphic/AbsorbablePosition.ts | 5 ++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/graphic/AbsorbablePosition.d.ts b/lib/graphic/AbsorbablePosition.d.ts index b4d8baf..3b45108 100644 --- a/lib/graphic/AbsorbablePosition.d.ts +++ b/lib/graphic/AbsorbablePosition.d.ts @@ -34,7 +34,7 @@ export declare const AbsorbablePointParam: { /** * 可吸附点 */ -export default class AbsorbablePoint extends Graphics implements AbsorbablePosition, VectorGraphic { +export declare class AbsorbablePoint extends Graphics implements AbsorbablePosition, VectorGraphic { _point: Point; absorbRange: number; scaledListenerOn: boolean; diff --git a/lib/index.js b/lib/index.js index e216c89..a9dac03 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2579,6 +2579,54 @@ const AbsorbablePointGraphic = new Graphics(); AbsorbablePointGraphic.beginFill(AbsorbablePointParam.fillColor); AbsorbablePointGraphic.drawCircle(0, 0, AbsorbablePointParam.radius); AbsorbablePointGraphic.endFill(); +/** + * 可吸附点 + */ +class AbsorbablePoint extends Graphics { + _point; + absorbRange; + scaledListenerOn = false; + /** + * + * @param point 画布坐标 + * @param absorbRange + */ + constructor(point, absorbRange = 10) { + super(AbsorbablePointGraphic.geometry); + this._point = new Point(point.x, point.y); + this.absorbRange = absorbRange; + this.position.copyFrom(this._point); + this.interactive; + VectorGraphicUtil.handle(this); + } + compareTo(other) { + if (other instanceof AbsorbablePoint) { + return this.absorbRange - other.absorbRange; + } + throw new Error('非可吸附点'); + } + isOverlapping(other) { + if (other instanceof AbsorbablePoint) { + return (this._point.equals(other._point) && + this.absorbRange === other.absorbRange); + } + return false; + } + tryAbsorb(...objs) { + for (let i = 0; i < objs.length; i++) { + const obj = objs[i]; + const canvasPosition = obj.getPositionOnCanvas(); + if (distance(this._point.x, this._point.y, canvasPosition.x, canvasPosition.y) < this.absorbRange) { + obj.updatePositionByCanvasPosition(this._point); + } + } + } + updateOnScaled() { + const scaled = this.getAllParentScaled(); + const scale = Math.max(scaled.x, scaled.y); + this.scale.set(1 / scale, 1 / scale); + } +} /** * 可吸附线 */ @@ -7654,4 +7702,4 @@ function newDrawApp(options) { return new JlDrawApp(options); } -export { AbsorbableCircle, AbsorbableLine, AbsorbablePointParam, AnimationManager, AppConsts, AppDragEvent, AppInteractionPlugin, AppWsMsgBroker, BezierCurveEditPlugin, BoundsGraphic, ChildTransform, ClientEngine, CombinationKey, CommonMouseTool, ContextMenu, ContextMenuPlugin, DOWN, DashedLine, DefaultWhiteMenuOptions, DefaultWhiteStyleOptions, DragPlugin, DraggablePoint, DraggablePointParam, GlobalKeyboardHelper, GraphicAnimation, GraphicCopyPlugin, GraphicDataUpdateOperation, GraphicDrawAssistant, GraphicEditPlugin, GraphicIdGenerator, GraphicInteractionPlugin, GraphicRelation, GraphicRelationParam, GraphicStore, GraphicTransform, GraphicTransformEvent, GraphicTransformPlugin, IdGenerator, InteractionPluginBase, InteractionPluginType, JlGraphic, JlGraphicAppKeyboardPlugin, JlGraphicTemplate, JlOperation, KeyListener, LEFT, LineEditPlugin, OperationRecord, OtherInteractionPlugin, OutOfBound, PolylineEditPlugin, RIGHT, RelationManage, ScaleData, ShiftData, TransformPoints, UP, VectorGraphicUtil, VectorText, ViewportMovePlugin, WsMsgCli, addBezierWayPoint, addLineWayPoint, addPolygonSegmentingPoint, addWayPoint, angleOfIncludedAngle, angleToAxisx, assertBezierPoints, calculateBezierPoints, calculateDistanceFromPointToLine, calculateFootPointFromPointToLine, calculateIntersectionPointOfCircleAndLine, calculateIntersectionPointOfCircleAndPoint, calculateLineMidpoint, calculateLineSegmentingPoint, calculateMirrorPoint, calculateMirrorPointBasedOnAxis, calculateOneBezierPoints, circlePoint, circlePoint2, clearWayPoint, convertLineToPolygonPoints, convertRectangleToPolygonPoints, convertToBezierParams, debounce, deserializeTransformInto, distance, distance2, epsilon, floatEquals, getCenterOfTwoRectangle, getIntersectionPoint, getNormalVector, getParallelOfPolyline, getRectangleCenter, getWayLineIndex, getWaypointRangeIndex, isLineContainOther, isParallelLines, isPointOnLine, isZero, lineBox, lineLine, linePoint, linePolygon, movePointAlongNormal, newDrawApp, newGraphicApp, pointBox, pointPoint, pointPoint2, pointPolygon, polylineBox, polylinePoint, polylinePolygon, recursiveChildren, recursiveFindChild, recursiveFindParent, recursiveParents, removeBezierWayPoint, removeLineWayPoint, removeWayPoint, serializeTransform, splitLineEvenly, splitPolyline }; +export { AbsorbableCircle, AbsorbableLine, AbsorbablePoint, AbsorbablePointParam, AnimationManager, AppConsts, AppDragEvent, AppInteractionPlugin, AppWsMsgBroker, BezierCurveEditPlugin, BoundsGraphic, ChildTransform, ClientEngine, CombinationKey, CommonMouseTool, ContextMenu, ContextMenuPlugin, DOWN, DashedLine, DefaultWhiteMenuOptions, DefaultWhiteStyleOptions, DragPlugin, DraggablePoint, DraggablePointParam, GlobalKeyboardHelper, GraphicAnimation, GraphicCopyPlugin, GraphicDataUpdateOperation, GraphicDrawAssistant, GraphicEditPlugin, GraphicIdGenerator, GraphicInteractionPlugin, GraphicRelation, GraphicRelationParam, GraphicStore, GraphicTransform, GraphicTransformEvent, GraphicTransformPlugin, IdGenerator, InteractionPluginBase, InteractionPluginType, JlGraphic, JlGraphicAppKeyboardPlugin, JlGraphicTemplate, JlOperation, KeyListener, LEFT, LineEditPlugin, OperationRecord, OtherInteractionPlugin, OutOfBound, PolylineEditPlugin, RIGHT, RelationManage, ScaleData, ShiftData, TransformPoints, UP, VectorGraphicUtil, VectorText, ViewportMovePlugin, WsMsgCli, addBezierWayPoint, addLineWayPoint, addPolygonSegmentingPoint, addWayPoint, angleOfIncludedAngle, angleToAxisx, assertBezierPoints, calculateBezierPoints, calculateDistanceFromPointToLine, calculateFootPointFromPointToLine, calculateIntersectionPointOfCircleAndLine, calculateIntersectionPointOfCircleAndPoint, calculateLineMidpoint, calculateLineSegmentingPoint, calculateMirrorPoint, calculateMirrorPointBasedOnAxis, calculateOneBezierPoints, circlePoint, circlePoint2, clearWayPoint, convertLineToPolygonPoints, convertRectangleToPolygonPoints, convertToBezierParams, debounce, deserializeTransformInto, distance, distance2, epsilon, floatEquals, getCenterOfTwoRectangle, getIntersectionPoint, getNormalVector, getParallelOfPolyline, getRectangleCenter, getWayLineIndex, getWaypointRangeIndex, isLineContainOther, isParallelLines, isPointOnLine, isZero, lineBox, lineLine, linePoint, linePolygon, movePointAlongNormal, newDrawApp, newGraphicApp, pointBox, pointPoint, pointPoint2, pointPolygon, polylineBox, polylinePoint, polylinePolygon, recursiveChildren, recursiveFindChild, recursiveFindParent, recursiveParents, removeBezierWayPoint, removeLineWayPoint, removeWayPoint, serializeTransform, splitLineEvenly, splitPolyline }; diff --git a/src/graphic/AbsorbablePosition.ts b/src/graphic/AbsorbablePosition.ts index b3a7acf..1e99427 100644 --- a/src/graphic/AbsorbablePosition.ts +++ b/src/graphic/AbsorbablePosition.ts @@ -64,10 +64,9 @@ AbsorbablePointGraphic.endFill(); /** * 可吸附点 */ -export default class AbsorbablePoint +export class AbsorbablePoint extends Graphics - implements AbsorbablePosition, VectorGraphic -{ + implements AbsorbablePosition, VectorGraphic { _point: Point; absorbRange: number; scaledListenerOn = false;