Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Nov 11, 2024
1 parent 35b18aa commit e39753d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Vec2 } from "@lib/utils/vec2";

export class BoundingBox2D {
private _topLeft: Vec2;
private _bottomRight: Vec2;

constructor(topLeft: Vec2, bottomRight: Vec2) {
this._topLeft = topLeft;
this._bottomRight = bottomRight;
}

getTopLeft(): Vec2 {
return this._topLeft;
}

getBottomRight(): Vec2 {
return this._bottomRight;
}

contains(point: Vec2): boolean {
return (
point.x >= this._topLeft.x &&
point.x <= this._bottomRight.x &&
point.y >= this._topLeft.y &&
point.y <= this._bottomRight.y
);
}

intersects(other: BoundingBox2D): boolean {
return (
this._topLeft.x <= other._bottomRight.x &&
this._bottomRight.x >= other._topLeft.x &&
this._topLeft.y <= other._bottomRight.y &&
this._bottomRight.y >= other._topLeft.y
);
}

getCenter(): Vec2 {
return {
x: (this._topLeft.x + this._bottomRight.x) / 2,
y: (this._topLeft.y + this._bottomRight.y) / 2,
};
}

getWidth(): number {
return this._bottomRight.x - this._topLeft.x;
}

getHeight(): number {
return this._bottomRight.y - this._topLeft.y;
}

getIntersectionArea(other: BoundingBox2D): number {
if (!this.intersects(other)) {
return 0;
}

const xOverlap =
Math.min(this._bottomRight.x, other._bottomRight.x) - Math.max(this._topLeft.x, other._topLeft.x);
const yOverlap =
Math.min(this._bottomRight.y, other._bottomRight.y) - Math.max(this._topLeft.y, other._topLeft.y);

return xOverlap * yOverlap;
}

getIntersectionVector(other: BoundingBox2D): Vec2 {
if (!this.intersects(other)) {
return { x: 0, y: 0 };
}

const xOverlap =
Math.min(this._bottomRight.x, other._bottomRight.x) - Math.max(this._topLeft.x, other._topLeft.x);
const yOverlap =
Math.min(this._bottomRight.y, other._bottomRight.y) - Math.max(this._topLeft.y, other._topLeft.y);

return { x: xOverlap, y: yOverlap };
}
}

export class QuadTree {
static makeQuadtree(): QuadTree {}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CompositeLayer, CompositeLayerProps, FilterContext, Layer, UpdateParameters } from "@deck.gl/core";
import { GeoJsonLayer, TextLayer } from "@deck.gl/layers";
import { GeoJsonLayer, TextLayer, _TextBackgroundLayer } from "@deck.gl/layers";

import type { Feature, FeatureCollection } from "geojson";

import { BoundingBox2D } from "./BoundingBox";

export type WellBorePickLayerData = {
easting: number;
northing: number;
Expand All @@ -17,6 +19,8 @@ type TextLayerData = {
name: string;
};

function makeBoundingBoxFromLabel(label: TextLayerData): BoundingBox2D {}

export type WellBorePicksLayerProps = {
id: string;
data: WellBorePickLayerData[];
Expand Down Expand Up @@ -69,7 +73,21 @@ export class WellborePicksLayer extends CompositeLayer<WellBorePicksLayerProps>
shouldUpdateState(
params: UpdateParameters<Layer<WellBorePicksLayerProps & Required<CompositeLayerProps>>>
): boolean {
// console.debug(params.context.viewport.zoom);
const textLayer = params.context.layerManager.getLayers({ layerIds: [`${this.id}-text`] })[0] as TextLayer;
if (!textLayer) {
return false;
}
const backgroundLayer = textLayer.context.layerManager.getLayers({
layerIds: [`${textLayer.id}-background`],
})[0] as _TextBackgroundLayer;
if (!backgroundLayer) {
return false;
}
const getBoundingRect = backgroundLayer.props.getBoundingRect;

if (typeof getBoundingRect !== "function") {
return false;
}
return false;
}

Expand Down Expand Up @@ -113,14 +131,17 @@ export class WellborePicksLayer extends CompositeLayer<WellBorePicksLayerProps>
fontSize: fontSize * 2,
sdf: true,
},
lineHeight: 1,
outlineColor: [0, 0, 0],
background: true,
getBackgroundColor: [0, 0, 0, 255],
outlineWidth: 2,
getSize: 12,
sdf: true,
sizeScale: fontSize,
sizeUnits: "meters",
sizeMinPixels: sizeMinPixels,
sizeMaxPixels: sizeMaxPixels,
// sizeMinPixels: sizeMinPixels,
// sizeMaxPixels: sizeMaxPixels,
getAlignmentBaseline: "top",
getTextAnchor: "middle",
getPosition: (d: TextLayerData) => d.coordinates,
Expand Down

0 comments on commit e39753d

Please sign in to comment.