Skip to content

Commit 74ff956

Browse files
author
shuzarevich
committed
feat: prevent SVG rendering artifacts by introducing a rendering offset in path calculations
1 parent 6013ee7 commit 74ff956

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

projects/f-flow/src/f-connection/common/domain/adaptive-curve-builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
IFConnectionBuilderResponse,
1111
} from '../../f-connection-builder';
1212

13+
const RENDERING_OFFSET = 0.0002; // Prevents SVG rendering artifacts at path endpoints;
14+
1315
/**
1416
* AdaptiveCurveBuilder
1517
*
@@ -184,7 +186,7 @@ export class AdaptiveCurveBuilder implements IFConnectionBuilder {
184186
const c1 = AdaptiveCurveBuilder._softControl(sourceSide, p0, p3, h0);
185187
const c2 = AdaptiveCurveBuilder._softControl(targetSide, p3, p0, h3);
186188

187-
const path = `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${p3.x + 0.0002} ${p3.y + 0.0002}`;
189+
const path = `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${p3.x + RENDERING_OFFSET} ${p3.y + RENDERING_OFFSET}`;
188190

189191
const connectionCenter = new CalculateConnectionCenterHandler().handle(
190192
new CalculateConnectionCenterRequest([p0, c1, c2, p3]),

projects/f-flow/src/f-connection/common/domain/f-bezier.path-builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
IFConnectionBuilderResponse,
1111
} from '../../f-connection-builder';
1212

13+
const RENDERING_OFFSET = 0.0002; // Prevents SVG rendering artifacts at path endpoints;
14+
1315
export class FBezierPathBuilder implements IFConnectionBuilder {
1416
private static _getConnectorOffset(distance: number, offset: number): number {
1517
if (distance >= offset) {
@@ -52,7 +54,7 @@ export class FBezierPathBuilder implements IFConnectionBuilder {
5254

5355
const targetAnglePoint = FBezierPathBuilder._getAnglePoint(targetSide, target, source, offset);
5456

55-
const path = `M ${source.x} ${source.y} C ${sourceAnglePoint.x} ${sourceAnglePoint.y}, ${targetAnglePoint.x} ${targetAnglePoint.y}, ${target.x + 0.0002} ${target.y + 0.0002}`;
57+
const path = `M ${source.x} ${source.y} C ${sourceAnglePoint.x} ${sourceAnglePoint.y}, ${targetAnglePoint.x} ${targetAnglePoint.y}, ${target.x + RENDERING_OFFSET} ${target.y + RENDERING_OFFSET}`;
5658

5759
const connectionCenter = new CalculateConnectionCenterHandler().handle(
5860
new CalculateConnectionCenterRequest([source, sourceAnglePoint, targetAnglePoint, target]),

projects/f-flow/src/f-connection/common/domain/f-segment.path-builder.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
} from '../../f-connection-builder';
1616
import { IMap } from '../../../domain';
1717

18+
const RENDERING_OFFSET = 0.0002; // Prevents SVG rendering artifacts at path endpoints;
19+
1820
const CONNECTOR_SIDE_POINT: IMap<IPoint> = {
1921
[EFConnectableSide.LEFT]: PointExtensions.initialize(-1, 0),
2022

@@ -76,7 +78,7 @@ export class FSegmentPathBuilder implements IFConnectionBuilder {
7678
const directionAccessor = direction.x !== 0 ? 'x' : 'y';
7779
const currentDirection = direction[directionAccessor];
7880

79-
let points: IPoint[] = [];
81+
let points: IPoint[];
8082
const sourceGapOffset = PointExtensions.initialize();
8183
const targetGapOffset = PointExtensions.initialize();
8284

@@ -182,7 +184,7 @@ export class FSegmentPathBuilder implements IFConnectionBuilder {
182184
if (i > 0 && i < points.length - 1) {
183185
segment = this._getBend(points[i - 1], p, points[i + 1], borderRadius);
184186
} else if (i === points.length - 1) {
185-
segment = this._buildLastLineSegment(i, p);
187+
segment = this._buildLastLineSegment(p);
186188
} else {
187189
segment = this._buildMoveOrLineSegment(i, p);
188190
}
@@ -217,7 +219,7 @@ export class FSegmentPathBuilder implements IFConnectionBuilder {
217219
return `${index === 0 ? 'M' : 'L'}${point.x} ${point.y}`;
218220
}
219221

220-
private _buildLastLineSegment(index: number, point: IPoint): string {
221-
return `L${point.x + 0.0002} ${point.y + 0.0002}`;
222+
private _buildLastLineSegment(point: IPoint): string {
223+
return `L${point.x + RENDERING_OFFSET} ${point.y + RENDERING_OFFSET}`;
222224
}
223225
}

projects/f-flow/src/f-connection/common/domain/f-straight.path-builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {
88
IFConnectionBuilderResponse,
99
} from '../../f-connection-builder';
1010

11+
const RENDERING_OFFSET = 0.0002; // Prevents SVG rendering artifacts at path endpoints;
12+
1113
export class FStraightPathBuilder implements IFConnectionBuilder {
1214
public handle(request: IFConnectionBuilderRequest): IFConnectionBuilderResponse {
1315
const { source, target } = request;
14-
const path = `M ${source.x} ${source.y} L ${target.x + 0.0002} ${target.y + 0.0002}`;
16+
const path = `M ${source.x} ${source.y} L ${target.x + RENDERING_OFFSET} ${target.y + RENDERING_OFFSET}`;
1517

1618
const connectionCenter = new CalculateConnectionCenterHandler().handle(
1719
new CalculateConnectionCenterRequest([source, target]),

0 commit comments

Comments
 (0)