Skip to content

Commit

Permalink
Add quadrac expression & small refactor to generate output from proje…
Browse files Browse the repository at this point in the history
…ct extent/zoom
  • Loading branch information
paulthatjazz committed Aug 23, 2024
1 parent 5c0ff00 commit 88663d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { numericDataSocket, numericNumberDataSocket } from "../socket_types"
import { exp, isSymbolNode, parse, parser } from 'mathjs'
import { PreviewControl } from "../controls/preview"
import { isEqual } from "lodash"
import { ProjectProperties } from "."
import { createXYZ } from "ol/tilegrid"


interface Expression {
Expand All @@ -15,14 +17,17 @@ interface Expression {
}

const ExpressionList: Array<Expression> = [
{ id: 1, name: `height * scale + error` }
{ id: 1, name: `height * scale + error` },
{ id: 2, name: `H^2 * scale + error` },
]

export class ExpressionComponent extends BaseComponent {
projectProps: ProjectProperties

constructor() {
constructor(ProjectProps: ProjectProperties) {
super("Expression")
this.category = "Arithmetic"
this.projectProps = ProjectProps
}

async builder(node: Node) {
Expand Down Expand Up @@ -128,22 +133,31 @@ export class ExpressionComponent extends BaseComponent {

const v = inputs[variables[0]][0] as NumericTileGrid

const out = editorNode.meta.output = outputs['out'] = new NumericTileGrid(v.zoom, v.x, v.y, v.width, v.height)

for (let x = v.x; x < v.x + v.width; ++x) {
for (let y = v.y; y < v.y + v.height; ++y) {
const tileGrid = createXYZ()
const outputTileRange = tileGrid.getTileRangeForExtentAndZ(this.projectProps.extent, this.projectProps.zoom)

variables.forEach((i) => {
const variableSource: any = inputs[i][0]
p.set(i, variableSource.get(x, y))
})
const out = editorNode.meta.output = outputs['out'] = new NumericTileGrid(
this.projectProps.zoom,
outputTileRange.minX,
outputTileRange.minY,
outputTileRange.getWidth(),
outputTileRange.getHeight()
)

let r = p.evaluate(expression)
out.iterate((x, y) => {

out.set(x, y, r);
p.clear();
}
}
variables.forEach((i) => {
const variableSource: any = inputs[i][0]
p.set(i, variableSource.get(x, y))
})

let r = p.evaluate(expression)

out.set(x, y, r);
p.clear();

})

editorNode.data.previousInputs = [inputs, expression]
editorNode.data.previewsOutput = out
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/projects/modelling/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function createDefaultComponents(saveMapLayer: SaveMapLayer, saveModel: S

// Arithmetic
new MaskNumericDataComponent(),
new ExpressionComponent(),
new ExpressionComponent(projectProps),
new BinaryOpComponent('Min', '', numericNumberDataSocket, numericNumberDataSocket, 'Arithmetic', projectProps),
new BinaryOpComponent('Max', '', numericNumberDataSocket, numericNumberDataSocket, 'Arithmetic', projectProps),
new VariadicOpComponent('Sum', '∑', numericDataSocket, numericDataSocket, 'Arithmetic', 'Sum all inputs'),
Expand Down

0 comments on commit 88663d0

Please sign in to comment.