useSectorCrescent
Hook used to create crescent sector of a circle.
Configuration
useSectorCrescent
will draw a sector counter-clockwise, starting from the right centre position, as useArc
.
If you wish to create a sector facing to other side, please use rotate
.
(SectorCrescentConfig | undefined) useSectorCrescent
accepts following configurations:
Property | Type | Default | Description |
---|---|---|---|
radius | number | 100 | Radius of outer arc of the sector. |
crescentRadius | number | 0.6 * radius | Radius of inner arc of the sector. (optional) |
angle | number | 60 | Angle of the sector, in degrees. |
extends
Primitive Configuration
(PrimitiveConfig) Base configurations for all primitives.
Property | Type | Default | Description |
---|---|---|---|
scale | number | Vertex | 1 | Scaling factor of the primitive. If Vertex is provided, it will scale x and y dimension accordingly (optional). |
rotate | number | 0 | Rotation of the primitive, in degrees, in clockwise manner (optional). |
position | Vertex | { x: 0, y: 0 } | Moving distance away from the primitive drawing centre. By default, primitive will start drawing in origin (0, 0) (optional). |
scale
, rotate
and position
can be considered as transformation of polygon after drawn, where position
can be considered as transform: translate
of css to the primitive.
The polygon will first be scaled, then rotated and lastly, translated.
If crescentRadius
is not given, it defaults to 0.6 * radius
.
However, when pass in crescentRadius
, please use the exact number but not the ratio to radius
.
Returns
(Primitive) All primitive return the following properties:
Property | Type | Description |
---|---|---|
vertices | Vertex[] | Vertices of the primitive. |
edges | Edge[] | Edges of the primitive. |
faces | Face[] | Faces of the primitive. |
centroid | Vertex | Centroid (geometric centre) of primitive. |
boundingBox | BoundingBox | Space constraint of the primitive, with properties x , y , width and height . |
svgPath | string | SVG path representing the shape of the primitive. |
drawToCanvas | (ctx: CanvasRenderingContext2D) => void | Callback that draws the primitive to a canvas context. |
modifyConfig | (newConfig: Partial<SectorCrescentConfig>) => void | Callback to update the configuration of the primitive. |
Example
import { useSectorCrescent } from "react-use-polygon";
const sectorCrescent = useSectorCrescent({
radius: 80,
crescentRadius: 50,
angle: 45,
rotate: 30,
});