npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

permissive-fov

v2.0.0

Published

An implementation of Permissive Field Of View algorithm in JavaScript.

Downloads

3

Readme

Precise Permissive Field Of View

A Precise Permissive FOV algorithm, based on the Python implementation.

Installation

npm install permissive-fov

Usage

Instantiation

In order to instantiate a PermissiveFov object, one needs to pass it the map dimensions and an isTransparent function that will determine whether a pair of coordinates points to a transparent (non-blocking) cell on the map.

const PermissiveFov = require("permissive-fov").PermissiveFov;

const width = 80;
const height = 50;
const isTransparent = (x, y) => map[x][y].transparent;

const fov = new PermissiveFov(width, height, isTransparent);

Since Permissive FOV contains TypeScript typings, it can also be used within TypeScript applications, the only difference being, obviously, the import statement:

import { PermissiveFov } from "permissive-fov";

FOV computation

A FOV computation requires four parametres: the source coordinates x and y, maximum sight radius (use Infinity for unlimited sight radius) and a function that will mark a given pair of coordinates as seen.

const startX = 40;
const startY = 25;
const radius = 10;
const setVisible = (x, y) => map[x][y].visible = true;

fov.compute(40, 25, 10, setVisible);

Changing map dimensions

const newWidth = 100;
const newHeight = 60;

fov.setMapDimensions(newWidth, newHeight);

Changing the transparency check function

const newIsTransparent = (x, y) => {
    return map[x][y].transparent ||
        map[x][y].xRayTransparent;
};

fov.setIsTransparent(newIsTransparent);

About Permissive FOV

Precise Permissive Field Of View is a field of view (FOV) computation algorithm. Given a 2D grid with a source point S and n points marked as obstacles, it will determine all points visible from S.

Here's an example of a field of view calculated using the Permissive FOV algorithm:

indoor

Real life uses

As with most field of view algorithms, Precise Permissive Field Of View can be used in any game with a two dimensional grid layout, e.g. a roguelike.

Due to the permissive nature of this algorithm, it is well suited for situations where symmetry and permissiveness are the desired features, e.g. for reasons of gameplay balance.

Restrictiveness vs. permissiveness

As the name itself implies, this algorithm is permissive (as opposed to restrictive). It means that it will typically consider many more points to be in field of view than other algorithms would.

This also means that in some cases, the field of view will take an unnatural looking shape, including points that are considered to be visible despite being right behind an obstacle. Here are two examples that demonstrate this:

pillar

outdoor

Symmetry

A FOV algorithm is considered symmetric given that the following is true:

Given any set of points A and B, when B is in FOV of A, then A is in FOV of B.

In other words, a field of view is symmetric when all of the points seen from source can also see the source, while all the points not seen by the source, cannot see the source either.

Permissive Precise FOV is perfectly symmetric.

Performance

Compared to other available FOV algorithms, Precise Permissive FOV is on the slower side of the spectrum, with an average time required to compute a single field of view several times longer than that of the best performing alternatives.

This means that this algorithm may not be well suited for uses where the field of view computation is performed very frequently. That being said, the symmetric nature of Precise Permissive FOV allows for smart optimisations. For instance, if the FOV has already been calculated for origin point A, determining whether A is visible from B doesn't require another FOV computation: if A sees B, then B sees A.

Images

FOV images have been generated by FOV Torture Chamber.

Credits

Python implementation's authorship and copyright notice:

Author:         Aaron MacDonald
Date:           June 14, 2007

Description:    An implementation of the precise permissive field
                of view algorithm for use in tile-based games.
                Based on the algorithm presented at
                http://roguebasin.roguelikedevelopment.org/
                  index.php?title=
                  Precise_Permissive_Field_of_View.

You are free to use or modify this code as long as this notice is
included.
This code is released without warranty.