@annotorious/annotorious
Advanced tools
Comparing version
@@ -0,4 +1,4 @@ | ||
import { SvelteComponent } from 'svelte'; | ||
import { ShapeType, Shape } from '../../model'; | ||
import { SvelteComponent } from 'svelte'; | ||
export declare const getEditor: (shape: Shape) => typeof SvelteComponent | undefined; | ||
export declare const registerEditor: (shapeType: ShapeType, editor: typeof SvelteComponent) => Map<ShapeType, typeof SvelteComponent>; |
export { default as Ellipse } from './Ellipse.svelte'; | ||
export { default as MultiPolygon } from './MultiPolygon.svelte'; | ||
export { default as Polygon } from './Polygon.svelte'; | ||
export { default as Rectangle } from './Rectangle.svelte'; |
export * from './ellipse'; | ||
export * from './multipolygon'; | ||
export * from './polygon'; | ||
@@ -3,0 +4,0 @@ export * from './rectangle'; |
@@ -8,2 +8,3 @@ import { AbstractSelector } from '@annotorious/core'; | ||
ELLIPSE = "ELLIPSE", | ||
MULTIPOLYGLON = "MULTIPOLYGON", | ||
POLYGON = "POLYGON", | ||
@@ -10,0 +11,0 @@ RECTANGLE = "RECTANGLE" |
@@ -32,1 +32,4 @@ import { Bounds, Shape, ShapeType } from './Shape'; | ||
export declare const boundsFromPoints: (points: Array<[number, number]>) => Bounds; | ||
export declare const computePolygonArea: (points: [number, number][]) => number; | ||
export declare const isPointInPolygon: (points: [number, number][], x: number, y: number) => boolean; | ||
export declare const pointsToPath: (points: [number, number][], close?: boolean) => string; |
{ | ||
"name": "@annotorious/annotorious", | ||
"version": "3.1.7", | ||
"version": "3.2.0", | ||
"description": "Add image annotation functionality to any web page with a few lines of JavaScript", | ||
@@ -48,7 +48,7 @@ "author": "Rainer Simon", | ||
"vite": "^5.4.14", | ||
"vite-plugin-dts": "^4.5.0", | ||
"vite-plugin-dts": "^4.5.3", | ||
"vitest": "^3.0.8" | ||
}, | ||
"dependencies": { | ||
"@annotorious/core": "3.1.7", | ||
"@annotorious/core": "3.2.0", | ||
"rbush": "^4.0.1", | ||
@@ -55,0 +55,0 @@ "uuid": "^11.1.0" |
@@ -0,3 +1,4 @@ | ||
import type { SvelteComponent } from 'svelte'; | ||
import { ShapeType, type Shape } from '../../model'; | ||
import type { SvelteComponent } from 'svelte'; | ||
import { MultiPolygonEditor } from './multipolygon'; | ||
import { PolygonEditor } from './polygon'; | ||
@@ -8,3 +9,4 @@ import { RectangleEditor } from './rectangle'; | ||
[ShapeType.RECTANGLE, RectangleEditor as typeof SvelteComponent], | ||
[ShapeType.POLYGON, PolygonEditor as typeof SvelteComponent] | ||
[ShapeType.POLYGON, PolygonEditor as typeof SvelteComponent], | ||
[ShapeType.MULTIPOLYGLON, MultiPolygonEditor as typeof SvelteComponent] | ||
]); | ||
@@ -11,0 +13,0 @@ |
export { default as Ellipse } from './Ellipse.svelte'; | ||
export { default as MultiPolygon } from './MultiPolygon.svelte'; | ||
export { default as Polygon } from './Polygon.svelte'; | ||
export { default as Rectangle } from './Rectangle.svelte'; |
export * from './ellipse'; | ||
export * from './multipolygon'; | ||
export * from './polygon'; | ||
@@ -3,0 +4,0 @@ export * from './rectangle'; |
import { ShapeType } from '../Shape'; | ||
import { registerShapeUtil, type ShapeUtil } from '../shapeUtils'; | ||
import type { ShapeUtil } from '../shapeUtils'; | ||
import { computePolygonArea, isPointInPolygon, registerShapeUtil } from '../shapeUtils'; | ||
import type { Polygon } from './Polygon'; | ||
@@ -8,33 +9,9 @@ | ||
area: (polygon: Polygon): number => { | ||
const { points } = polygon.geometry; | ||
let area = 0; | ||
let j = points.length - 1; | ||
for (let i = 0; i < points.length; i++) { | ||
area += (points[j][0] + points[i][0]) * (points[j][1] - points[i][1]); | ||
j = i; | ||
} | ||
return Math.abs(0.5 * area); | ||
const points = polygon.geometry.points as [number, number][]; | ||
return computePolygonArea(points); | ||
}, | ||
intersects: (polygon: Polygon, x: number, y: number): boolean => { | ||
// Based on https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html | ||
const { points } = polygon.geometry; | ||
let inside = false; | ||
for (let i = 0, j = points.length - 1; i < points.length; j = i++) { | ||
const xi = points[i][0], | ||
yi = points[i][1]; | ||
const xj = points[j][0], | ||
yj = points[j][1]; | ||
const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi; | ||
if (intersect) inside = !inside; | ||
} | ||
return inside; | ||
const points = polygon.geometry.points as [number, number][]; | ||
return isPointInPolygon(points, x, y); | ||
} | ||
@@ -41,0 +18,0 @@ |
@@ -15,2 +15,4 @@ import type { AbstractSelector } from '@annotorious/core'; | ||
MULTIPOLYGLON = 'MULTIPOLYGON', | ||
POLYGON = 'POLYGON', | ||
@@ -17,0 +19,0 @@ |
@@ -57,2 +57,50 @@ import type { Bounds, Shape, ShapeType } from './Shape'; | ||
return { minX, minY, maxX, maxY }; | ||
}; | ||
} | ||
export const computePolygonArea = (points: [number, number][]) => { | ||
let area = 0; | ||
let j = points.length - 1; | ||
for (let i = 0; i < points.length; i++) { | ||
area += (points[j][0] + points[i][0]) * (points[j][1] - points[i][1]); | ||
j = i; | ||
} | ||
return Math.abs(0.5 * area); | ||
} | ||
export const isPointInPolygon = (points: [number, number][], x: number, y: number): boolean => { | ||
// Based on https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html | ||
let inside = false; | ||
for (let i = 0, j = points.length - 1; i < points.length; j = i++) { | ||
const xi = points[i][0], | ||
yi = points[i][1]; | ||
const xj = points[j][0], | ||
yj = points[j][1]; | ||
const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi; | ||
if (intersect) inside = !inside; | ||
} | ||
return inside; | ||
} | ||
export const pointsToPath = (points: [number, number][], close: boolean = true): string => { | ||
let d = 'M '; | ||
points.forEach(([x, y], idx) => { | ||
if (idx === 0) { | ||
// First point after the M command | ||
d += `${x},${y}`; | ||
} else { | ||
d += ` L ${x},${y}`; | ||
} | ||
}); | ||
if (close) | ||
d += ' Z'; | ||
return d; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
968070
6.31%149
8.76%7116
11.75%+ Added
- Removed
Updated