({
face,
width,
height,
showLandmarks,
showContours,
showFrame,
}: FaceMapProps)
| 14 | } |
| 15 | |
| 16 | const FaceMap = ({ |
| 17 | face, |
| 18 | width, |
| 19 | height, |
| 20 | showLandmarks, |
| 21 | showContours, |
| 22 | showFrame, |
| 23 | }: FaceMapProps) => { |
| 24 | const screen = useWindowDimensions(); |
| 25 | const scaledFrame = scaleFrame(width, height, screen.width); |
| 26 | const scaledPoint = scalePoint(width, height, screen.width); |
| 27 | |
| 28 | const {landmarks, contours} = face; |
| 29 | const frame = scaledFrame(face.frame)!; |
| 30 | |
| 31 | function pointsToPath(points: Point[]) { |
| 32 | return points |
| 33 | .map(scaledPoint) |
| 34 | .map(({x, y}, i) => `${i === 0 ? 'M' : 'L'} ${x} ${y} `) |
| 35 | .join(' '); |
| 36 | } |
| 37 | |
| 38 | return ( |
| 39 | <Svg style={styles.container} width={width} height={height}> |
| 40 | {showFrame && ( |
| 41 | <Rect |
| 42 | stroke="white" |
| 43 | fill="transparent" |
| 44 | strokeWidth={2} |
| 45 | strokeOpacity={0.75} |
| 46 | width={frame.width} |
| 47 | height={frame.height} |
| 48 | x={frame.left} |
| 49 | y={frame.top} |
| 50 | /> |
| 51 | )} |
| 52 | |
| 53 | {showLandmarks && |
| 54 | landmarks && |
| 55 | Object.entries(landmarks).map(([key, landmark]) => { |
| 56 | const {x, y} = scaledPoint(landmark.position); |
| 57 | |
| 58 | return <Circle key={key} r={3} fill="yellow" x={x} y={y} />; |
| 59 | })} |
| 60 | |
| 61 | {showContours && |
| 62 | contours && |
| 63 | Object.entries(contours).map(([key, contour]) => { |
| 64 | const points = contour.points; |
| 65 | return ( |
| 66 | <React.Fragment key={key}> |
| 67 | {points.map((point, pointId) => { |
| 68 | const {x, y} = scaledPoint(point); |
| 69 | |
| 70 | return ( |
| 71 | <Circle |
| 72 | key={`${pointId}-${x}-${y}`} |
| 73 | x={x} |
nothing calls this directly
no test coverage detected