How to use the @bentley/geometry-core.Point2d function in @bentley/geometry-core

To help you get started, we’ve selected a few @bentley/geometry-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / display-test-app / src / frontend / Viewer.ts View on Github external
function saveImage(vp: Viewport) {
  const buffer = vp.readImage(undefined, new Point2d(768, 768), true); // flip vertically...
  if (undefined === buffer) {
    alert("Failed to read image");
    return;
  }

  const url = imageBufferToPngDataUrl(buffer, false);
  if (undefined === url) {
    alert("Failed to produce PNG");
    return;
  }

  openImageDataUrlInNewWindow(url, "Saved View");
}
github imodeljs / imodeljs / test-apps / display-test-app / src / frontend / IncidentMarkerDemo.ts View on Github external
const sorted: IncidentMarker[] = [];
    const maxLen = 10;
    cluster.markers.forEach((marker) => {
      if (maxLen > sorted.length || marker.severity > sorted[sorted.length - 1].severity) {
        const index = sorted.findIndex((val) => val.severity < marker.severity);
        if (index === -1)
          sorted.push(marker);
        else
          sorted.splice(index, 0, marker);
        if (sorted.length > maxLen)
          sorted.length = maxLen;
      }
    });

    this.imageOffset = new Point3d(0, 28);
    this.imageSize = new Point2d(30, 30);
    this.label = cluster.markers.length.toLocaleString();
    this.labelColor = "black";
    this.labelFont = "bold 14px san-serif";

    let title = "";
    sorted.forEach((marker) => {
      if (title !== "")
        title += "<br>";
      title += "Severity: " + marker.severity + " Id: " + marker.id;
    });
    if (cluster.markers.length &gt; maxLen)
      title += "<br>...";

    const div = document.createElement("div"); // Use HTML as markup isn't supported for string.
    div.innerHTML = title;
    this.title = div;
github imodeljs / imodeljs / core / frontend / src / ElementLocateManager.ts View on Github external
public doPick(vp: ScreenViewport, pickPointWorld: Point3d, pickRadiusView: number, options: LocateOptions): number {
    if (this.hitList &amp;&amp; this.hitList.length &gt; 0 &amp;&amp; vp === this.viewport &amp;&amp; pickPointWorld.isAlmostEqual(this.pickPointWorld)) {
      this.hitList.resetCurrentHit();
      return this.hitList.length;
    }

    this.empty(); // empty the hit list
    this.viewport = vp;
    this.pickPointWorld.setFrom(pickPointWorld);

    const pickPointView = vp.worldToView(pickPointWorld);
    const testPointView = new Point2d(Math.floor(pickPointView.x + 0.5), Math.floor(pickPointView.y + 0.5));
    let pixelRadius = Math.floor(pickRadiusView + 0.5);
    const rect = new ViewRect(testPointView.x - pixelRadius, testPointView.y - pixelRadius, testPointView.x + pixelRadius, testPointView.y + pixelRadius);
    let result: number = 0;
    vp.readPixels(rect, Pixel.Selector.All, (pixels) =&gt; {
      if (undefined === pixels)
        return;

      testPointView.x = cssPixelsToDevicePixels(testPointView.x);
      testPointView.y = cssPixelsToDevicePixels(testPointView.y);
      pixelRadius = cssPixelsToDevicePixels(pixelRadius);

      const elmHits = new Map();
      const testPoint = Point2d.createZero();
      for (testPoint.x = testPointView.x - pixelRadius; testPoint.x &lt;= testPointView.x + pixelRadius; ++testPoint.x) {
        for (testPoint.y = testPointView.y - pixelRadius; testPoint.y &lt;= testPointView.y + pixelRadius; ++testPoint.y) {
          const pixel = pixels.getPixel(testPoint.x, testPoint.y);
github imodeljs / imodeljs / test-apps / ui-test-app / src / frontend / plugins / MeasurePoints.ts View on Github external
constructor(worldLocation: XYAndZ, distanceLabel: string) {
    this.worldLocation = Point3d.createFrom(worldLocation);
    this.size = Point2d.createFrom(DistanceMarker._size);
    this.position = new Point3d();
    this.label = distanceLabel;
    const offset: Point2d = new Point2d(0, 20);
    this.labelOffset = offset;
  }
github imodeljs / imodeljs / test-apps / ui-test-app / src / frontend / tools / MeasurePoints.ts View on Github external
constructor(worldLocation: XYAndZ, distanceLabel: string) {
    this.worldLocation = Point3d.createFrom(worldLocation);
    this.size = Point2d.createFrom(DistanceMarker._size);
    this.position = new Point3d();
    this.label = distanceLabel;
    const offset: Point2d = new Point2d(0, 20);
    this.labelOffset = offset;
  }
github imodeljs / imodeljs / core / common / src / QPoint.ts View on Github external
public unquantize(index: number, out?: Point2d): Point2d {
    assert(index &lt; this.length);
    if (index &lt; this.length) {
      return this._list[index].unquantize(this.params, out);
    } else {
      return undefined !== out ? out : new Point2d();
    }
  }
github imodeljs / imodeljs / core / frontend / src / ImageUtil.ts View on Github external
export function canvasToResizedCanvasWithBars(canvasIn: HTMLCanvasElement, targetSize: Point2d, barSize = new Point2d(0, 0), barStyle = "#C0C0C0"): HTMLCanvasElement {
  const canvasOut = document.createElement("canvas");
  canvasOut.width = targetSize.x + barSize.x;
  canvasOut.height = targetSize.y + barSize.y;

  let adjustImageX = barSize.x / 2;
  let adjustImageY = barSize.y / 2;

  if (1 === barSize.x % 2) {
    adjustImageX += 0.5;
  }
  if (1 === barSize.y % 2) {
    adjustImageY += 0.5;
  }

  const context = canvasOut.getContext("2d")!;
  context.fillStyle = barStyle;
github imodeljs / imodeljs / core / frontend / src / tools / SelectTool.ts View on Github external
protected selectByPointsProcess(origin: Point3d, corner: Point3d, ev: BeButtonEvent, method: SelectionMethod, overlap: boolean) {
    const vp = ev.viewport;
    if (!vp)
      return;
    const pts: Point2d[] = [];
    pts[0] = new Point2d(Math.floor(origin.x + 0.5), Math.floor(origin.y + 0.5));
    pts[1] = new Point2d(Math.floor(corner.x + 0.5), Math.floor(corner.y + 0.5));
    const range = Range2d.createArray(pts);

    const rect = new ViewRect();
    rect.initFromRange(range);
    vp.readPixels(rect, Pixel.Selector.Feature, (pixels) =&gt; {
      if (undefined === pixels)
        return;

      const sRange = Range2d.createNull();
      sRange.extendPoint(Point2d.create(cssPixelsToDevicePixels(range.low.x), cssPixelsToDevicePixels(range.low.y)));
      sRange.extendPoint(Point2d.create(cssPixelsToDevicePixels(range.high.x), cssPixelsToDevicePixels(range.high.y)));

      let contents = new Set();
      const testPoint = Point2d.createZero();
github imodeljs / imodeljs / core / frontend / src / ImageUtil.ts View on Github external
  return imageElementFromImageSource(source).then((image) => new Point2d(image.naturalWidth, image.naturalHeight));
}