Skip to content

Commit

Permalink
style: linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-85 committed Mar 6, 2024
1 parent 504c576 commit 30e8c2a
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 188 deletions.
208 changes: 104 additions & 104 deletions src/procgen/HeightProfiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ import { Vector2 } from 'three'
import { interpolatePoints } from '../common/utils'

export enum ProfileType {
Regular = 'regular',
Continentalness = 'continentalness',
Erosion = 'erosion',
PeaksValleys = 'peaksvalleys',
Regular = 'regular',
Continentalness = 'continentalness',
Erosion = 'erosion',
PeaksValleys = 'peaksvalleys',
}

/**
* Shape used to profile terrain height
* e.g. mapping value to real ground/terrain height
*/
class HeightProfiler {
static profiles = {}
curveParams
constructor(curveParams) {
this.curveParams = curveParams
}
static profiles = {}
curveParams
constructor(curveParams) {
this.curveParams = curveParams
}

static addProfile(curveProfile, profileType: ProfileType) {
HeightProfiler.profiles[profileType] =
HeightProfiler.profiles[profileType] || new HeightProfiler(curveProfile)
}
static addProfile(curveProfile, profileType: ProfileType) {
HeightProfiler.profiles[profileType] =
HeightProfiler.profiles[profileType] || new HeightProfiler(curveProfile)
}

getCurveSegment(inputVal) {
return getCurveSegment(inputVal, this.curveParams)
}
getCurveSegment(inputVal) {
return getCurveSegment(inputVal, this.curveParams)
}

static apply(profileType: ProfileType, inputVal) {
const profile = HeightProfiler.profiles[profileType]
return noiseToHeight(inputVal, profile.getCurveSegment(inputVal))
}
static apply(profileType: ProfileType, inputVal) {
const profile = HeightProfiler.profiles[profileType]
return noiseToHeight(inputVal, profile.getCurveSegment(inputVal))
}
}

/**
Expand All @@ -42,21 +42,21 @@ class HeightProfiler {
* @returns upper and lower points from curve profile closest to input val
*/
const getCurveSegment = (noise, curveProfile) => {
const lower = curveProfile
.filter(point => point.noise <= noise)
.reduce((last, curr) => {
const currDiff = Math.abs(noise - curr.noise)
const lastDiff = Math.abs(noise - last.noise)
return currDiff < lastDiff ? curr : last
})
const upper = curveProfile
.filter(point => point.noise >= noise)
.reduce((last, curr) => {
const currDiff = Math.abs(noise - curr.noise)
const lastDiff = Math.abs(noise - last.noise)
return currDiff < lastDiff ? curr : last
})
return { lower, upper }
const lower = curveProfile
.filter(point => point.noise <= noise)
.reduce((last, curr) => {
const currDiff = Math.abs(noise - curr.noise)
const lastDiff = Math.abs(noise - last.noise)
return currDiff < lastDiff ? curr : last
})
const upper = curveProfile
.filter(point => point.noise >= noise)
.reduce((last, curr) => {
const currDiff = Math.abs(noise - curr.noise)
const lastDiff = Math.abs(noise - last.noise)
return currDiff < lastDiff ? curr : last
})
return { lower, upper }
}

/**
Expand All @@ -66,81 +66,81 @@ const getCurveSegment = (noise, curveProfile) => {
* @returns height ranging from 0 to 255
*/
const noiseToHeight = (noiseVal: number, curveSegment) => {
const { lower, upper } = curveSegment
const lowerPoint = new Vector2(lower.noise, lower.height)
const upperPoint = new Vector2(upper.noise, upper.height)
const interpolatedHeight = interpolatePoints(lowerPoint, upperPoint, noiseVal)
return interpolatedHeight
const { lower, upper } = curveSegment
const lowerPoint = new Vector2(lower.noise, lower.height)
const upperPoint = new Vector2(upper.noise, upper.height)
const interpolatedHeight = interpolatePoints(lowerPoint, upperPoint, noiseVal)
return interpolatedHeight
}

/**
* Spline curve parameters
*/
const CurvePresets = {
regular: [
{
noise: 0,
height: 0,
},
{
noise: 1,
height: 255,
},
],
continentalness: [
{
noise: 0,
height: 0,
},
{
noise: 0.65,
height: 150,
},
{
noise: 0.75,
height: 255,
},
{
noise: 1,
height: 255,
},
],
erosion: [
{
noise: 0,
height: 50,
},
{
noise: 0.65,
height: 100,
},
{
noise: 0.75,
height: 150,
},
{
noise: 1,
height: 150,
},
],
peaksValleys: [
{
noise: 0,
height: 50,
},
{
noise: 0.65,
height: 100,
},
{
noise: 0.75,
height: 150,
},
{
noise: 1,
height: 150,
},
],
regular: [
{
noise: 0,
height: 0,
},
{
noise: 1,
height: 255,
},
],
continentalness: [
{
noise: 0,
height: 0,
},
{
noise: 0.65,
height: 150,
},
{
noise: 0.75,
height: 255,
},
{
noise: 1,
height: 255,
},
],
erosion: [
{
noise: 0,
height: 50,
},
{
noise: 0.65,
height: 100,
},
{
noise: 0.75,
height: 150,
},
{
noise: 1,
height: 150,
},
],
peaksValleys: [
{
noise: 0,
height: 50,
},
{
noise: 0.65,
height: 100,
},
{
noise: 0.75,
height: 150,
},
{
noise: 1,
height: 150,
},
],
}

export { HeightProfiler, CurvePresets }
42 changes: 21 additions & 21 deletions src/procgen/NoiseSampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import { Vector2 } from 'three'
import { sanitiseNoise } from '../common/utils'

export interface ISampler<InputType> {
// userScale: number; // scale applied to sampler user input when querying sample
density: number // intrinsic sample density
source
// querying sample value from input
query(input: InputType)
// userScale: number; // scale applied to sampler user input when querying sample
density: number // intrinsic sample density
source
// querying sample value from input
query(input: InputType)
}

/**
* Sampling points from noise source
*/
export class ProceduralNoise2DSampler implements ISampler<Vector2> {
source: any
density: any // TODO
constructor() {
this.source = new SimplexNoise()
}
source: any
density: any // TODO
constructor() {
this.source = new SimplexNoise()
}

query(input: Vector2) {
const { x, y } = input
const freq = [0.0125, 0.025, 0.05, 0.1, 0.2, 0.4, 0.8]
let noise = 0
freq.forEach((f: number, i: number) => {
noise +=
(this.source.noise3d(x * f, y * f, 0) + 0.5) /
Math.pow(2, i + 1)
});
query(input: Vector2) {
const { x, y } = input
const freq = [0.0125, 0.025, 0.05, 0.1, 0.2, 0.4, 0.8]
let noise = 0
freq.forEach((f: number, i: number) => {
noise +=
(this.source.noise3d(x * f, y * f, 0) + 0.5) /
Math.pow(2, i + 1)
});

return sanitiseNoise(noise)
}
return sanitiseNoise(noise)
}
}
Loading

0 comments on commit 30e8c2a

Please sign in to comment.