-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(draw): add assembly requiredInterface and providedInterface shap… (
#906)
- Loading branch information
Showing
8 changed files
with
305 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@plait/draw': minor | ||
--- | ||
|
||
add assembly requiredInterface and providedInterface shape for uml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
PlaitBoard, | ||
Point, | ||
PointOfRectangle, | ||
RectangleClient, | ||
getNearestPointBetweenPointAndEllipse, | ||
getNearestPointBetweenPointAndSegments, | ||
setStrokeLinecap | ||
} from '@plait/core'; | ||
import { ShapeEngine } from '../../interfaces'; | ||
import { Options } from 'roughjs/bin/core'; | ||
import { RectangleEngine } from '../basic-shapes/rectangle'; | ||
import { getUnitVectorByPointAndPoint, rotateVector } from '@plait/common'; | ||
|
||
export const AssemblyEngine: ShapeEngine = { | ||
draw(board: PlaitBoard, rectangle: RectangleClient, options: Options) { | ||
const rs = PlaitBoard.getRoughSVG(board); | ||
const shape = rs.path( | ||
` | ||
M${rectangle.x} ${rectangle.y + rectangle.height / 2} | ||
H${rectangle.x + rectangle.width * 0.3} | ||
A${rectangle.width * 0.13} ${rectangle.height * 0.285}, 0, 1, 1 ${rectangle.x + | ||
rectangle.width * 0.3 + | ||
rectangle.width * 0.26} ${rectangle.y + rectangle.height / 2} | ||
A${rectangle.width * 0.13} ${rectangle.height * 0.285}, 0, 1, 1 ${rectangle.x + rectangle.width * 0.3} ${rectangle.y + | ||
rectangle.height / 2} | ||
M${rectangle.x + rectangle.width * 0.3 + rectangle.width * 0.13} ${rectangle.y} | ||
A${rectangle.width * 0.233} ${rectangle.height / 2}, 0, 0, 1 ${rectangle.x + | ||
rectangle.width * 0.3 + | ||
rectangle.width * 0.13} ${rectangle.y + rectangle.height} | ||
M${rectangle.x + rectangle.width * 0.3 + rectangle.width * 0.13 + rectangle.width * 0.233} ${rectangle.y + | ||
rectangle.height / 2} H${rectangle.x + rectangle.width} | ||
`, | ||
{ | ||
...options, | ||
fillStyle: 'solid' | ||
} | ||
); | ||
setStrokeLinecap(shape, 'round'); | ||
|
||
return shape; | ||
}, | ||
isInsidePoint(rectangle: RectangleClient, point: Point) { | ||
const rangeRectangle = RectangleClient.getRectangleByPoints([point, point]); | ||
return RectangleClient.isHit(rectangle, rangeRectangle); | ||
}, | ||
getCornerPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getCornerPoints(rectangle); | ||
}, | ||
getConnectorPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getEdgeCenterPoints(rectangle); | ||
}, | ||
getNearestPoint(rectangle: RectangleClient, point: Point) { | ||
const nearestPoint = getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle)); | ||
if (nearestPoint[0] === rectangle.x + rectangle.width / 2) { | ||
return getNearestPointBetweenPointAndEllipse( | ||
point, | ||
[rectangle.x + rectangle.width * 0.43, rectangle.y + rectangle.height / 2], | ||
rectangle.width * 0.223, | ||
rectangle.height / 2 | ||
); | ||
} | ||
return nearestPoint; | ||
}, | ||
getTangentVectorByConnectionPoint(rectangle: RectangleClient, pointOfRectangle: PointOfRectangle) { | ||
const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle); | ||
if (connectionPoint[0] > rectangle.x + rectangle.width * 0.43 && connectionPoint[1] < rectangle.y + rectangle.height / 2) { | ||
return rotateVector(getUnitVectorByPointAndPoint(connectionPoint, [rectangle.x, rectangle.y + rectangle.height / 2]), -Math.PI); | ||
} | ||
if (connectionPoint[0] > rectangle.x + rectangle.width * 0.43 && connectionPoint[1] > rectangle.y + rectangle.height / 2) { | ||
return getUnitVectorByPointAndPoint(connectionPoint, [rectangle.x, rectangle.y + rectangle.height / 2]); | ||
} | ||
return getUnitVectorByPointAndPoint(connectionPoint, [rectangle.x, rectangle.y + rectangle.height / 2]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
PlaitBoard, | ||
Point, | ||
PointOfRectangle, | ||
RectangleClient, | ||
getEllipseTangentSlope, | ||
getNearestPointBetweenPointAndSegments, | ||
getVectorFromPointAndSlope, | ||
setStrokeLinecap | ||
} from '@plait/core'; | ||
import { ShapeEngine } from '../../interfaces'; | ||
import { Options } from 'roughjs/bin/core'; | ||
import { RectangleEngine } from '../basic-shapes/rectangle'; | ||
import { getUnitVectorByPointAndPoint } from '@plait/common'; | ||
|
||
export const ProvidedInterfaceEngine: ShapeEngine = { | ||
draw(board: PlaitBoard, rectangle: RectangleClient, options: Options) { | ||
const rs = PlaitBoard.getRoughSVG(board); | ||
const shape = rs.path( | ||
` M${rectangle.x} ${rectangle.y + rectangle.height / 2} | ||
H${rectangle.x + rectangle.width * 0.54} | ||
A${(rectangle.width * 0.46) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width} ${rectangle.y + | ||
rectangle.height / 2} | ||
A${(rectangle.width * 0.46) / 2} ${rectangle.height / 2}, 0, 1, 1 ${rectangle.x + rectangle.width * 0.54} ${rectangle.y + | ||
rectangle.height / 2} | ||
`, | ||
{ | ||
...options, | ||
fillStyle: 'solid' | ||
} | ||
); | ||
setStrokeLinecap(shape, 'round'); | ||
|
||
return shape; | ||
}, | ||
isInsidePoint(rectangle: RectangleClient, point: Point) { | ||
const rangeRectangle = RectangleClient.getRectangleByPoints([point, point]); | ||
return RectangleClient.isHit(rectangle, rangeRectangle); | ||
}, | ||
getCornerPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getCornerPoints(rectangle); | ||
}, | ||
getConnectorPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getEdgeCenterPoints(rectangle); | ||
}, | ||
getNearestPoint(rectangle: RectangleClient, point: Point) { | ||
const nearestPoint = getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle)); | ||
return nearestPoint; | ||
}, | ||
getTangentVectorByConnectionPoint(rectangle: RectangleClient, pointOfRectangle: PointOfRectangle) { | ||
const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle); | ||
const centerPoint: Point = [rectangle.x + (rectangle.width * 3) / 4, rectangle.y + rectangle.height / 2]; | ||
if (connectionPoint[0] > rectangle.x + rectangle.width * 0.54) { | ||
const point = [connectionPoint[0] - centerPoint[0], -(connectionPoint[1] - centerPoint[1])]; | ||
const rx = (rectangle.width * 0.46) / 2; | ||
const ry = rectangle.height / 2; | ||
const slope = getEllipseTangentSlope(point[0], point[1], rx, ry) as any; | ||
return getVectorFromPointAndSlope(point[0], point[1], slope); | ||
} | ||
return getUnitVectorByPointAndPoint(connectionPoint, [rectangle.x, rectangle.y + rectangle.height / 2]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
PlaitBoard, | ||
Point, | ||
PointOfRectangle, | ||
RectangleClient, | ||
getNearestPointBetweenPointAndSegments, | ||
setStrokeLinecap | ||
} from '@plait/core'; | ||
import { ShapeEngine } from '../../interfaces'; | ||
import { Options } from 'roughjs/bin/core'; | ||
import { RectangleEngine } from '../basic-shapes/rectangle'; | ||
import { getPolygonEdgeByConnectionPoint } from '../../utils/polygon'; | ||
|
||
export const RequiredInterfaceEngine: ShapeEngine = { | ||
draw(board: PlaitBoard, rectangle: RectangleClient, options: Options) { | ||
const rs = PlaitBoard.getRoughSVG(board); | ||
const shape = rs.path( | ||
`M${rectangle.x} ${rectangle.y} | ||
A${rectangle.width * 0.39} ${rectangle.height / 2}, 0, 0, 1 ${rectangle.x} ${rectangle.y + rectangle.height} | ||
M${rectangle.x + rectangle.width * 0.41} ${rectangle.y + rectangle.height / 2} H${rectangle.x + rectangle.width} | ||
`, | ||
{ | ||
...options, | ||
fillStyle: 'solid' | ||
} | ||
); | ||
setStrokeLinecap(shape, 'round'); | ||
|
||
return shape; | ||
}, | ||
isInsidePoint(rectangle: RectangleClient, point: Point) { | ||
const rangeRectangle = RectangleClient.getRectangleByPoints([point, point]); | ||
return RectangleClient.isHit(rectangle, rangeRectangle); | ||
}, | ||
getCornerPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getCornerPoints(rectangle); | ||
}, | ||
getNearestPoint(rectangle: RectangleClient, point: Point) { | ||
return getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle)); | ||
}, | ||
getEdgeByConnectionPoint(rectangle: RectangleClient, pointOfRectangle: PointOfRectangle): [Point, Point] | null { | ||
const corners = RectangleEngine.getCornerPoints(rectangle); | ||
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle); | ||
return getPolygonEdgeByConnectionPoint(corners, point); | ||
}, | ||
getConnectorPoints(rectangle: RectangleClient) { | ||
return RectangleClient.getEdgeCenterPoints(rectangle); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters