Skip to content

Commit

Permalink
chore: removing adding method on edgeless block (#8536)
Browse files Browse the repository at this point in the history
  • Loading branch information
doouding authored Oct 21, 2024
1 parent 00e4a25 commit 48c697c
Show file tree
Hide file tree
Showing 46 changed files with 729 additions and 942 deletions.
6 changes: 0 additions & 6 deletions packages/affine/block-surface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export type { Options } from './utils/rough/core.js';
import {
almostEqual,
clamp,
getBoundsWithRotation,
getPointFromBoundsWithRotation,
getPointsFromBoundsWithRotation,
getQuadBoundsWithRotation,
getStroke,
getSvgPathFromStroke,
intersects,
Expand Down Expand Up @@ -119,10 +116,7 @@ export const CommonUtils = {
clamp,
generateElementId,
generateKeyBetween,
getBoundsWithRotation,
getPointFromBoundsWithRotation,
getPointsFromBoundsWithRotation,
getQuadBoundsWithRotation,
getStroke,
getSvgPathFromStroke,
intersects,
Expand Down
10 changes: 4 additions & 6 deletions packages/affine/block-surface/src/managers/connector-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getBezierCurveBoundingBox,
getBezierParameters,
getBoundFromPoints,
getBoundsWithRotation,
getBoundWithRotation,
getPointFromBoundsWithRotation,
isOverlap,
isVecZero,
Expand Down Expand Up @@ -917,9 +917,7 @@ export class ConnectionOverlay extends Overlay {

// then check if in expanded bound
const bound = Bound.deserialize(connectable.xywh);
const rotateBound = Bound.from(
getBoundsWithRotation(rBound(connectable))
);
const rotateBound = Bound.from(getBoundWithRotation(rBound(connectable)));
// FIXME: the real path needs to be expanded: diamod, ellipse, trangle.
if (!rotateBound.expand(10).isPointInBound(point)) continue;

Expand Down Expand Up @@ -1103,10 +1101,10 @@ export class ConnectorPathGenerator {
const [startPoint, endPoint] = this._computeStartEndPoint(connector);

const startBound = start
? Bound.from(getBoundsWithRotation(rBound(start)))
? Bound.from(getBoundWithRotation(rBound(start)))
: null;
const endBound = end
? Bound.from(getBoundsWithRotation(rBound(end)))
? Bound.from(getBoundWithRotation(rBound(end)))
: null;
const path = this.generateOrthogonalConnectorPath({
startPoint,
Expand Down
4 changes: 2 additions & 2 deletions packages/affine/block-surface/src/renderer/canvas-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { type Color, ColorScheme } from '@blocksuite/affine-model';
import { requestConnectedFrame } from '@blocksuite/affine-shared/utils';
import {
DisposableGroup,
getBoundsWithRotation,
getBoundWithRotation,
intersects,
last,
Slot,
Expand Down Expand Up @@ -278,7 +278,7 @@ export class CanvasRenderer {
ctx.save();

const display = element.display ?? true;
if (display && intersects(getBoundsWithRotation(element), bound)) {
if (display && intersects(getBoundWithRotation(element), bound)) {
const renderFn =
this.elementRenderers[
element.type as keyof typeof this.elementRenderers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Bound } from '@blocksuite/global/utils';
import type { Y } from '@blocksuite/store';

import {
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
rotatePoints,
} from '@blocksuite/global/utils';
import { deltaInsertsToChunks } from '@blocksuite/inline';
Expand Down Expand Up @@ -235,7 +235,7 @@ export function getTextCursorPosition(
model: TextElementModel,
coord: { x: number; y: number }
) {
const leftTop = getPointsFromBoundsWithRotation(model)[0];
const leftTop = getPointsFromBoundWithRotation(model)[0];
const mousePos = rotatePoints(
[[coord.x, coord.y]],
leftTop,
Expand Down
10 changes: 5 additions & 5 deletions packages/affine/model/src/elements/brush/brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
import {
Bound,
getBoundFromPoints,
getPointsFromBoundsWithRotation,
getQuadBoundsWithRotation,
getPointsFromBoundWithRotation,
getQuadBoundWithRotation,
getSolidStrokePoints,
getSvgPathFromStroke,
inflateBound,
Expand Down Expand Up @@ -69,17 +69,17 @@ export class BrushElementModel extends GfxPrimitiveElementModel<BrushProps> {
}

override containsBound(bounds: Bound) {
const points = getPointsFromBoundsWithRotation(this);
const points = getPointsFromBoundWithRotation(this);
return points.some(point => bounds.containsPoint(point));
}

override getLineIntersections(start: IVec, end: IVec) {
const tl = [this.x, this.y];
const points = getPointsFromBoundsWithRotation(this, _ =>
const points = getPointsFromBoundWithRotation(this, _ =>
this.points.map(point => Vec.add(point, tl))
);

const box = Bound.fromDOMRect(getQuadBoundsWithRotation(this));
const box = Bound.fromDOMRect(getQuadBoundWithRotation(this));

if (box.w < 8 && box.h < 8) {
return Vec.distanceToLineSegment(start, end, box.center) < 5 ? [] : null;
Expand Down
14 changes: 7 additions & 7 deletions packages/affine/model/src/elements/shape/api/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IBound, IVec } from '@blocksuite/global/utils';
import {
Bound,
getCenterAreaBounds,
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
linePolygonIntersects,
pointInPolygon,
PointLocation,
Expand Down Expand Up @@ -53,7 +53,7 @@ export const diamond = {
options: PointTestOptions
) {
const point: IVec = [x, y];
const points = getPointsFromBoundsWithRotation(this, diamond.points);
const points = getPointsFromBoundWithRotation(this, diamond.points);

let hit = pointOnPolygonStoke(
point,
Expand All @@ -73,15 +73,15 @@ export const diamond = {
this,
DEFAULT_CENTRAL_AREA_RATIO
);
const centralPoints = getPointsFromBoundsWithRotation(
const centralPoints = getPointsFromBoundWithRotation(
centralBounds,
diamond.points
);
hit = pointInPolygon(point, centralPoints);
} else if (this.textBound) {
hit = pointInPolygon(
point,
getPointsFromBoundsWithRotation(
getPointsFromBoundWithRotation(
this,
() => Bound.from(this.textBound!).points
)
Expand All @@ -94,17 +94,17 @@ export const diamond = {
},

containsBound(bounds: Bound, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element, diamond.points);
const points = getPointsFromBoundWithRotation(element, diamond.points);
return points.some(point => bounds.containsPoint(point));
},

getNearestPoint(point: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element, diamond.points);
const points = getPointsFromBoundWithRotation(element, diamond.points);
return polygonNearestPoint(points, point);
},

getLineIntersections(start: IVec, end: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element, diamond.points);
const points = getPointsFromBoundWithRotation(element, diamond.points);
return linePolygonIntersects(start, end, points);
},

Expand Down
6 changes: 3 additions & 3 deletions packages/affine/model/src/elements/shape/api/ellipse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PointTestOptions } from '@blocksuite/block-std/gfx';

import {
clamp,
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
type IBound,
type IVec,
lineEllipseIntersects,
Expand Down Expand Up @@ -71,7 +71,7 @@ export const ellipse = {
} else if (this.textBound) {
hit = pointInPolygon(
point,
getPointsFromBoundsWithRotation(
getPointsFromBoundWithRotation(
this,
() => Bound.from(this.textBound!).points
)
Expand All @@ -83,7 +83,7 @@ export const ellipse = {
return hit;
},
containsBound(bounds: Bound, element: ShapeElementModel): boolean {
const points = getPointsFromBoundsWithRotation(element, ellipse.points);
const points = getPointsFromBoundWithRotation(element, ellipse.points);
return points.some(point => bounds.containsPoint(point));
},

Expand Down
14 changes: 7 additions & 7 deletions packages/affine/model/src/elements/shape/api/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IBound, IVec } from '@blocksuite/global/utils';
import {
Bound,
getCenterAreaBounds,
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
linePolygonIntersects,
pointInPolygon,
PointLocation,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const rect = {
options: PointTestOptions
) {
const point: IVec = [x, y];
const points = getPointsFromBoundsWithRotation(
const points = getPointsFromBoundWithRotation(
this,
undefined,
options.responsePadding
Expand All @@ -69,13 +69,13 @@ export const rect = {
this,
DEFAULT_CENTRAL_AREA_RATIO
);
const centralPoints = getPointsFromBoundsWithRotation(centralBounds);
const centralPoints = getPointsFromBoundWithRotation(centralBounds);
// Check if the point is in the center area
hit = pointInPolygon([x, y], centralPoints);
} else if (this.textBound) {
hit = pointInPolygon(
point,
getPointsFromBoundsWithRotation(
getPointsFromBoundWithRotation(
this,
() => Bound.from(this.textBound!).points
)
Expand All @@ -88,17 +88,17 @@ export const rect = {
},

containsBound(bounds: Bound, element: ShapeElementModel): boolean {
const points = getPointsFromBoundsWithRotation(element);
const points = getPointsFromBoundWithRotation(element);
return points.some(point => bounds.containsPoint(point));
},

getNearestPoint(point: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element);
const points = getPointsFromBoundWithRotation(element);
return polygonNearestPoint(points, point);
},

getLineIntersections(start: IVec, end: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element);
const points = getPointsFromBoundWithRotation(element);
return linePolygonIntersects(start, end, points);
},

Expand Down
14 changes: 7 additions & 7 deletions packages/affine/model/src/elements/shape/api/triangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IBound, IVec } from '@blocksuite/global/utils';
import {
Bound,
getCenterAreaBounds,
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
linePolygonIntersects,
pointInPolygon,
PointLocation,
Expand Down Expand Up @@ -50,7 +50,7 @@ export const triangle = {
options: PointTestOptions
) {
const point: IVec = [x, y];
const points = getPointsFromBoundsWithRotation(this, triangle.points);
const points = getPointsFromBoundWithRotation(this, triangle.points);

let hit = pointOnPolygonStoke(
point,
Expand All @@ -70,15 +70,15 @@ export const triangle = {
this,
DEFAULT_CENTRAL_AREA_RATIO
);
const centralPoints = getPointsFromBoundsWithRotation(
const centralPoints = getPointsFromBoundWithRotation(
centralBounds,
triangle.points
);
hit = pointInPolygon([x, y], centralPoints);
} else if (this.textBound) {
hit = pointInPolygon(
point,
getPointsFromBoundsWithRotation(
getPointsFromBoundWithRotation(
this,
() => Bound.from(this.textBound!).points
)
Expand All @@ -90,17 +90,17 @@ export const triangle = {
return hit;
},
containsBound(bounds: Bound, element: ShapeElementModel): boolean {
const points = getPointsFromBoundsWithRotation(element, triangle.points);
const points = getPointsFromBoundWithRotation(element, triangle.points);
return points.some(point => bounds.containsPoint(point));
},

getNearestPoint(point: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element, triangle.points);
const points = getPointsFromBoundWithRotation(element, triangle.points);
return polygonNearestPoint(points, point);
},

getLineIntersections(start: IVec, end: IVec, element: ShapeElementModel) {
const points = getPointsFromBoundsWithRotation(element, triangle.points);
const points = getPointsFromBoundWithRotation(element, triangle.points);
return linePolygonIntersects(start, end, points);
},

Expand Down
8 changes: 4 additions & 4 deletions packages/affine/model/src/elements/text/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IVec, SerializedXYWH } from '@blocksuite/global/utils';
import { field, GfxPrimitiveElementModel } from '@blocksuite/block-std/gfx';
import {
Bound,
getPointsFromBoundsWithRotation,
getPointsFromBoundWithRotation,
linePolygonIntersects,
pointInPolygon,
polygonNearestPoint,
Expand Down Expand Up @@ -40,12 +40,12 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
}

override containsBound(bounds: Bound): boolean {
const points = getPointsFromBoundsWithRotation(this);
const points = getPointsFromBoundWithRotation(this);
return points.some(point => bounds.containsPoint(point));
}

override getLineIntersections(start: IVec, end: IVec) {
const points = getPointsFromBoundsWithRotation(this);
const points = getPointsFromBoundWithRotation(this);
return linePolygonIntersects(start, end, points);
}

Expand All @@ -57,7 +57,7 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
}

override includesPoint(x: number, y: number): boolean {
const points = getPointsFromBoundsWithRotation(this);
const points = getPointsFromBoundWithRotation(this);
return pointInPolygon([x, y], points);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/blocks/src/_common/export-manager/export-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ export class ExportManager {
this.editorHost,
rootModel
) as EdgelessRootBlockComponent;
const bound = edgeless.getElementsBound();
if (!bound) return;
const bound = edgeless.gfx.elementsBound;
return this.edgelessToCanvas(edgeless.surface.renderer, bound, edgeless);
}
}
Expand Down
Loading

0 comments on commit 48c697c

Please sign in to comment.