Skip to content

Commit

Permalink
Merge branch 'feature/0.3.4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 23, 2024
2 parents 30d9677 + e295952 commit 8076c9d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## 0.3.4
Handle Wall, Edge classes in Draw.segment.
Add an internal PIXI.Point.invert that returns object, for non-keys.
Fix for test if can convert polygon to rectangle.
Add `ClipperPaths#union` method that unions polygons without filling.

## 0.3.3
Switch to using TextureLoader.getTextureAlphaData.
Fix the `fromOverheadTileAlpha` method given changes to `TextureLoader.getTextureAlphaData`.
Use `wall.edge.a`.
Change Tile overhead test.

## 0.3.2
Use `token#getShape()` instead of `token#shape` in `token#tokenBorder` so it works even if the token shape is not yet defined.
Expand Down
22 changes: 20 additions & 2 deletions ClipperPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class ClipperPaths {
*/
static polygonToRectangle(polygon) {
const pts = polygon.points;
if ( !(polygon.isClosed && pts.length === 10)
|| !(!polygon.isClosed && pts.length === 8) ) return polygon;
if ( (polygon.isClosed && pts.length !== 10)
|| (!polygon.isClosed && pts.length !== 8) ) return polygon;

// Layout must be clockwise.
// Layout options:
Expand Down Expand Up @@ -318,6 +318,24 @@ export class ClipperPaths {
return this._clipperClip(polygon, ClipperLib.ClipType.ctDifference);
}

/**
* Union the paths.
* @returns {ClipperPaths}
*/
union() {
if ( this.paths.length === 1 ) return this;
const c = new ClipperLib.Clipper();
const union = new ClipperPaths();
union.scalingFactor = this.scalingFactor;
c.AddPaths(this.paths, ClipperLib.PolyType.ptSubject, true);
c.Execute(ClipperLib.ClipType.ctUnion,
union.paths,
ClipperLib.PolyFillType.pftNonZero,
ClipperLib.PolyFillType.pftNonZero
);
return union;
}

/**
* Union the paths, using a positive fill.
* This version uses a positive fill type so any overlap is filled.
Expand Down
7 changes: 5 additions & 2 deletions Draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ export class Draw {
* @param {Number} width Width of the line in pixels.
*/
segment(s, { color = Draw.COLORS.blue, alpha = 1, width = 1 } = {}) {
// Handle Wall, Edge, other
const A = s.edge?.a ?? s.a ?? s.A;
const B = s.edge?.b ?? s.b ?? s.B;
this.g.lineStyle(width, color, alpha)
.moveTo(s.A.x, s.A.y)
.lineTo(s.B.x, s.B.y);
.moveTo(A.x, A.y)
.lineTo(B.x, B.y);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions PIXI/Point.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ PIXI.Point._tmp3 = new PIXI.Point();
* @param {number} key Integer key
* @returns {PIXI.Point} coordinates
*/
function invertKey(key) {
function invertKey(key, outPoint) {
outPoint ??= new this();
return outPoint.copyFrom(this._invertKey(key));
}

function _invertKey(key) {
const x = Math.floor(key * MAX_TEXTURE_SIZE_INV);
const y = key - (MAX_TEXTURE_SIZE * x);
return new PIXI.Point(x, y);
return { x, y };
}

/**
Expand Down Expand Up @@ -431,7 +436,8 @@ PATCHES.PIXI.STATIC_METHODS = {
angleBetween,
flatMapPoints,
fromObject,
invertKey
invertKey,
_invertKey
};

PATCHES.PIXI.METHODS = {
Expand Down
2 changes: 1 addition & 1 deletion registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Hooks
*/
"use strict";

const VERSION = "0.3.3";
const VERSION = "0.3.4";

// Foundry utils
import { registerFoundryUtilsMethods } from "./util.js";
Expand Down

0 comments on commit 8076c9d

Please sign in to comment.