Skip to content

Commit

Permalink
(#87) Location API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
s1hofmann committed Oct 7, 2019
1 parent 49bfa6d commit ddc676b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/location.function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Point } from "./point.class";
import { Region } from "./region.class";

/**
* {@link centerOf} returns the center {@link Point} for a given {@link Region}
* @param target {@link Region} to determine the center {@link Point} for
*/
export const centerOf = async (target: Region | Promise<Region>): Promise<Point> => {
const targetRegion = await target;
const x = Math.floor(targetRegion.left + targetRegion.width / 2);
Expand All @@ -9,6 +13,10 @@ export const centerOf = async (target: Region | Promise<Region>): Promise<Point>
return new Point(x, y);
};

/**
* {@link randomPointIn} returns a random {@link Point} within a given {@link Region}
* @param target {@link Region} the random {@link Point} has to be within
*/
export const randomPointIn = async (target: Region | Promise<Region>): Promise<Point> => {
const targetRegion = await target;
const x = Math.floor(targetRegion.left + Math.random() * targetRegion.width);
Expand Down

0 comments on commit ddc676b

Please sign in to comment.