Skip to content

Commit

Permalink
Draw different tensor field icons (circle/square) if radial or grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Patrick committed May 16, 2020
1 parent 54f9cde commit 22c74f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/ts/impl/basis_field.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Tensor from './tensor';
import Vector from '../vector';

export const enum FIELD_TYPE {
Radial,
Grid,
};

/**
* Grid or Radial field to be combined with others to create the tensor field
*/
export abstract class BasisField {
abstract readonly FOLDER_NAME: string;
abstract readonly FIELD_TYPE: number;
protected static folderNameIndex: number = 0;
protected parentFolder: dat.GUI;
protected folder: dat.GUI;
Expand Down Expand Up @@ -91,6 +97,7 @@ export abstract class BasisField {

export class Grid extends BasisField {
readonly FOLDER_NAME = `Grid ${Grid.folderNameIndex++}`;
readonly FIELD_TYPE = FIELD_TYPE.Grid;

constructor(centre: Vector, size: number, decay: number, private _theta: number) {
super(centre, size, decay);
Expand Down Expand Up @@ -118,6 +125,8 @@ export class Grid extends BasisField {

export class Radial extends BasisField {
readonly FOLDER_NAME = `Radial ${Radial.folderNameIndex++}`;
readonly FIELD_TYPE = FIELD_TYPE.Radial;

constructor(centre: Vector, size: number, decay: number) {
super(centre, size, decay);
}
Expand Down
4 changes: 4 additions & 0 deletions src/ts/impl/tensor_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class TensorField {
return this.basisFields.map(field => field.centre);
}

getBasisFields(): BasisField[] {
return this.basisFields;
}

samplePoint(point: Vector): Tensor {
if (!this.onLand(point)) {
// Degenerate point
Expand Down
7 changes: 7 additions & 0 deletions src/ts/ui/canvas_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ export class DefaultCanvasWrapper extends CanvasWrapper {
}
}

drawCircle(centre: Vector, radius: number): void {
const TAU = 2 * Math.PI;
this.ctx.beginPath();
this.ctx.arc(centre.x, centre.y, radius, 0, TAU);
this.ctx.fill();
}

drawSquare(centre: Vector, radius: number): void {
this.drawRectangle(centre.x - radius, centre.y - radius, 2 * radius, 2 * radius);
}
Expand Down
8 changes: 5 additions & 3 deletions src/ts/ui/tensor_field_gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DomainController from './domain_controller';
import DragController from './drag_controller';
import TensorField from '../impl/tensor_field';
import {NoiseParams} from '../impl/tensor_field';
import {BasisField} from '../impl/basis_field';
import {BasisField, FIELD_TYPE} from '../impl/basis_field';
import Util from '../util';
import Vector from '../vector';

Expand Down Expand Up @@ -125,8 +125,10 @@ export default class TensorFieldGUI extends TensorField {
// Draw centre points of fields
if (this.drawCentre) {
canvas.setFillStyle('red');
this.getCentrePoints().forEach(v =>
canvas.drawSquare(this.domainController.worldToScreen(v), 7));
this.getBasisFields().forEach(field =>
field.FIELD_TYPE === FIELD_TYPE.Grid ?
canvas.drawSquare(this.domainController.worldToScreen(field.centre), 7) :
canvas.drawCircle(this.domainController.worldToScreen(field.centre), 7))
}
}

Expand Down

0 comments on commit 22c74f4

Please sign in to comment.