Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippath's bounds should be copied before intersection #1636 (#1… #1638

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
node-version: 16
cache: 'pnpm'

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Install dependencies
run: pnpm install

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Build
run: pnpm build

Expand Down
48 changes: 48 additions & 0 deletions __tests__/demos/bugfix/1636.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Image, Group, Rect } from '../../../packages/g';

export async function image(context) {
const { canvas } = context;
await canvas.ready;

const rect = new Rect({
style: {
x: 0,
y: 0,
width: 600,
height: 600,
},
});
const group = new Group({
style: {
clipPath: rect,
},
});
canvas.appendChild(group);

const img = new window.Image();
img.onload = () => {
const image = new Image({
style: {
x: 0,
y: 0,
width: 100,
height: 100,
img,
},
});
const image2 = new Image({
style: {
x: 50,
y: 0,
width: 100,
height: 100,
img,
},
});
group.appendChild(image);
group.appendChild(image2);
};
img.src =
'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*_aqoS73Se3sAAAAAAAAAAAAAARQnAQ';
img.crossOrigin = 'anonymous';
}
1 change: 1 addition & 0 deletions __tests__/demos/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { html } from './1610';
export { image } from './1636';
4 changes: 3 additions & 1 deletion __tests__/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as lil from 'lil-gui';
import { Canvas, CanvasEvent } from '../packages/g';
import { runtime, Canvas, CanvasEvent } from '../packages/g';
import { Renderer as CanvasRenderer } from '../packages/g-canvas';
import { Renderer as CanvaskitRenderer } from '../packages/g-canvaskit';
import { Renderer as SVGRenderer } from '../packages/g-svg';
Expand All @@ -16,6 +16,8 @@ import * as hammerjs from './demos/hammerjs';
import * as lottie from './demos/lottie';
import * as bugfix from './demos/bugfix';

runtime.enableCSSParsing = false;

const tests = {
...createSpecRender(namespace(basic2d, '2d')),
...createSpecRender(namespace(basic3d, '3d')),
Expand Down
2 changes: 2 additions & 0 deletions __tests__/unit/abstract-renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Abstract renderer', () => {
enableCulling: false,
enableDirtyRectangleRendering: true,
enableDirtyRectangleRenderingDebug: false,
enableSizeAttenuation: true,
});

renderer.setConfig({ enableAutoRendering: false });
Expand All @@ -19,6 +20,7 @@ describe('Abstract renderer', () => {
enableCulling: false,
enableDirtyRectangleRendering: true,
enableDirtyRectangleRenderingDebug: false,
enableSizeAttenuation: true,
});

expect(renderer.getPlugins().length).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
'<rootDir>/__tests__/unit/*.spec.+(ts|tsx|js)',
],
testPathIgnorePatterns: process.env.CI
? ['<rootDir>/__tests__/unit/g-gesture']
? ['<rootDir>/__tests__/unit/g-gesture', '<rootDir>/__tests__/main.ts']
: ['<rootDir>/__tests__/unit/g-gesture'],
preset: 'ts-jest',
transform: {
Expand Down
7 changes: 7 additions & 0 deletions packages/g-camera-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-camera-api

## 1.2.24

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 1.2.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-camera-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-camera-api",
"version": "1.2.23",
"version": "1.2.24",
"description": "A simple implementation of Camera API.",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvas

## 1.11.28

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]

## 1.11.27

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "1.11.27",
"version": "1.11.28",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvaskit

## 0.10.28

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]

## 0.10.27

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "0.10.27",
"version": "0.10.28",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-components

## 1.9.23

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 1.9.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-components",
"version": "1.9.22",
"version": "1.9.23",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-dom-mutation-observer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-dom-mutation-observer-api

## 1.2.23

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 1.2.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-dom-mutation-observer-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-dom-mutation-observer-api",
"version": "1.2.22",
"version": "1.2.23",
"description": "A simple implementation of DOM MutationObserver API.",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-gesture

## 2.2.26

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 2.2.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "2.2.25",
"version": "2.2.26",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-image-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-image-exporter

## 0.7.23

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 0.7.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-image-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-image-exporter",
"version": "0.7.22",
"version": "0.7.23",
"description": "A image exporter for G using DOM API",
"keywords": [
"antv",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-lite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-lite

## 1.2.23

### Patch Changes

- 1d25bf84: ClipPath should be copied first before calculate intersection bounds.

## 1.2.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lite",
"version": "1.2.22",
"version": "1.2.23",
"description": "A core module for rendering engine implements DOM API.",
"keywords": [
"antv",
Expand Down
20 changes: 7 additions & 13 deletions packages/g-lite/src/services/SceneGraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,35 +849,29 @@ export class DefaultSceneGraphService implements SceneGraphService {
}
});

if (!aabb) {
aabb = new AABB();
}

if (render) {
// FIXME: account for clip path
const clipped = findClosestClipPathTarget(element as DisplayObject);
if (clipped) {
// use bounds under world space
const clipPathBounds = clipped.parsedStyle.clipPath.getBounds(render);
if (!aabb) {
aabb = clipPathBounds;
aabb.update(clipPathBounds.center, clipPathBounds.halfExtents);
} else if (clipPathBounds) {
aabb = clipPathBounds.intersection(aabb);
}
}
}

if (!aabb) {
aabb = new AABB();
}

if (aabb) {
if (render) {
renderable.renderBounds = aabb;
} else {
renderable.bounds = aabb;
}
}

if (render) {
renderable.renderBounds = aabb;
renderable.renderBoundsDirty = false;
} else {
renderable.bounds = aabb;
renderable.boundsDirty = false;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/g-lite/src/services/aabb/RectUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { isString } from '@antv/util';
import type { Group, Image, ParsedImageStyleProps, Rect } from '../../display-objects';
import type {
Group,
Image,
ParsedImageStyleProps,
Rect,
} from '../../display-objects';
import type { GeometryAABBUpdater } from './interfaces';
export class RectUpdater implements GeometryAABBUpdater<ParsedImageStyleProps> {
update(parsedStyle: ParsedImageStyleProps, object: Image | Rect | Group) {
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lottie-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-lottie-player

## 0.2.23

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 0.2.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lottie-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lottie-player",
"version": "0.2.22",
"version": "0.2.23",
"description": "A lottie player for G",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-mobile-canvas-element/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-mobile-canvas-element

## 0.8.23

### Patch Changes

- Updated dependencies [1d25bf84]
- @antv/[email protected]

## 0.8.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-canvas-element/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-canvas-element",
"version": "0.8.22",
"version": "0.8.23",
"description": "Create a CanvasLike element from existed context in mobile environment",
"keywords": [
"antv",
Expand Down
Loading
Loading