-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47f9107
commit 9118cf8
Showing
8 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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
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,88 @@ | ||
import { ShapeStruct, createBaseShape } from "../core"; | ||
import { SimplePath, SimplePolygonShape, getStructForSimplePolygon } from "../simplePolygon"; | ||
import { createFillStyle } from "../../utils/fillStyle"; | ||
import { createStrokeStyle } from "../../utils/strokeStyle"; | ||
|
||
export type CrossShape = SimplePolygonShape & { | ||
crossSize: number; | ||
}; | ||
|
||
export const struct: ShapeStruct<CrossShape> = { | ||
...getStructForSimplePolygon<CrossShape>(getPath), | ||
label: "Cross", | ||
create(arg = {}) { | ||
return { | ||
...createBaseShape(arg), | ||
type: "cross", | ||
fill: arg.fill ?? createFillStyle(), | ||
stroke: arg.stroke ?? createStrokeStyle(), | ||
width: arg.width ?? 100, | ||
height: arg.height ?? 100, | ||
crossSize: arg.crossSize ?? 20, | ||
}; | ||
}, | ||
getTextRangeRect: undefined, | ||
getTextPadding: undefined, | ||
patchTextPadding: undefined, | ||
}; | ||
|
||
function getPath(shape: CrossShape): SimplePath { | ||
const cx = shape.width / 2; | ||
const cy = shape.height / 2; | ||
|
||
const size = shape.crossSize; | ||
if (size >= shape.width || size >= shape.height || size <= 0) { | ||
// Fallback to rectangle when the cross size is too big. | ||
const tl = { x: 0, y: 0 }; | ||
const tr = { x: shape.width, y: 0 }; | ||
const br = { x: shape.width, y: shape.height }; | ||
const bl = { x: 0, y: shape.height }; | ||
return { | ||
path: [ | ||
tl, | ||
tl, | ||
{ x: cx, y: 0 }, | ||
tr, | ||
tr, | ||
{ x: shape.width, y: cy }, | ||
br, | ||
br, | ||
{ x: cx, y: shape.height }, | ||
bl, | ||
bl, | ||
{ x: 0, y: cy }, | ||
], | ||
}; | ||
} | ||
|
||
const d = size / 2; | ||
|
||
const x0 = 0; | ||
const y0 = 0; | ||
|
||
const x1 = cx - d; | ||
const y1 = cy - d; | ||
|
||
const x2 = cx + d; | ||
const y2 = cy + d; | ||
|
||
const x3 = shape.width; | ||
const y3 = shape.height; | ||
|
||
return { | ||
path: [ | ||
{ x: x0, y: y1 }, | ||
{ x: x1, y: y1 }, | ||
{ x: x1, y: y0 }, | ||
{ x: x2, y: y0 }, | ||
{ x: x2, y: y1 }, | ||
{ x: x3, y: y1 }, | ||
{ x: x3, y: y2 }, | ||
{ x: x2, y: y2 }, | ||
{ x: x2, y: y3 }, | ||
{ x: x1, y: y3 }, | ||
{ x: x1, y: y2 }, | ||
{ x: x0, y: y2 }, | ||
], | ||
}; | ||
} |
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