Skip to content

Commit

Permalink
feat(Texture): allow comparing with equals() using a string
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Nov 1, 2023
1 parent cebe6f8 commit e33a955
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Polygons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class Polygons extends Array<Polygon> {
return this.selectBy((polygon) => polygon.isWithin(box))
}

selectByTextures(textures: Texture[]) {
selectByTextures(textures: (Texture | string)[]) {
return this.selectBy((polygon) => polygon.texture?.equalsAny(textures) ?? false)
}

Expand Down
15 changes: 12 additions & 3 deletions src/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,22 @@ export class Texture extends ThreeJsTextue {
}
}

equals(texture: Texture) {
/**
* compares filenames of textures without the extensions
*
* For example:
* - texture.jpg == TEXTURE.JPG
* - texture.bmp == texture.jpg
*/
equals(texture: Texture | string) {
const { name: aFilename } = path.parse(this.filename.toLowerCase())
const { name: bFilename } = path.parse(texture.filename.toLowerCase())
const { name: bFilename } = path.parse(
typeof texture === 'string' ? texture.toLowerCase() : texture.filename.toLowerCase(),
)
return aFilename === bFilename
}

equalsAny(textures: Texture[]) {
equalsAny(textures: (Texture | string)[]) {
if (textures.length === 0) {
return false
}
Expand Down

0 comments on commit e33a955

Please sign in to comment.