figbertmath

[RADIOACTIVE] miscellaneous math programs in website form
git clone git://git.figbert.com/figbertmath.git
Log | Files | Refs | README

commit 9748ec8e62232c10342dba28f874b04ddafe8d77
parent 17dd376add5a6309d50ba9de176f600d13801105
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Fri, 29 Nov 2019 23:58:56 -0800

Add polygon angle calculator

Diffstat:
MREADME.md | 4++--
Msrc/components/App.js | 3+++
Asrc/components/highLevel/polygonAngle.js | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -1,12 +1,12 @@ # FIGBERT Math A calculator for miscellaneous formulas I encounter that can, and thus shall, be automated. -## Current +## Complete * Simple Calculator * Angular/Real Size Calculator * Consecutive Number Calculator +* Polygon Angle Calculator ## Planned -* Polygon Angle Calculator * Simultaneous Equation Calculator * Forces and Energy Calculator \ No newline at end of file diff --git a/src/components/App.js b/src/components/App.js @@ -3,6 +3,7 @@ import { ModeSelect } from "./highLevel/modeSelect"; import { SimpleCalc } from "./highLevel/simpleCalc"; import { AngSizeCalc } from "./highLevel/angSize"; import { ConsecNumCalc } from "./highLevel/consecNum"; +import { PolygonAngle } from "./highLevel/polygonAngle"; export class App extends React.Component { constructor(props) { @@ -27,6 +28,8 @@ export class App extends React.Component { return <AngSizeCalc mode={this.state.mode} onModeChange={this.changeMode}/>; } else if (this.state.mode === 'consecNum') { return <ConsecNumCalc mode={this.state.mode} onModeChange={this.changeMode}/>; + } else if (this.state.mode === 'polyAng') { + return <PolygonAngle mode={this.state.mode} onModeChange={this.changeMode} />; } else { return <ModeSelect mode={this.state.mode} onButtonPress={this.changeMode} />; } diff --git a/src/components/highLevel/polygonAngle.js b/src/components/highLevel/polygonAngle.js @@ -0,0 +1,96 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { CalcOut } from "../lowLevel/calcOut"; +import { Pad } from "../lowLevel/pad"; + +export class PolygonAngle extends React.Component { + constructor(props) { + super(props); + this.state = { + output: '', + sides: '', + type: 'Regular' + }; + this.onTypeClick = this.onTypeClick.bind(this); + this.onChange = this.onChange.bind(this); + this.calcAngles = this.calcAngles.bind(this); + } + + onChange(object) { + const value = object.target.value; + this.setState({ sides: value }, () => { + if (this.state.sides !== '') { + this.calcAngles() + } else { + this.setState({ + output: '' + }) + } + }); + } + + onTypeClick() { + if (this.state.type === 'Regular') { + this.setState({ type: 'Irregular Convex' }, () => { + if (this.state.sides !== '') { + this.calcAngles() + } + }); + } else { + this.setState({ type: 'Regular'}, () => { + if (this.state.sides !== '') { + this.calcAngles() + } + }); + } + } + + calcAngles() { + const sides = Math.round(Number(this.state.sides)); + if (sides < 3) { + this.setState({ + output: 'ERROR' + }); + } else { + const totalInterior = (sides - 2) * 180; + if (this.state.type === 'Regular') { + let eachInterior = totalInterior / sides, + eachExterior = 360 / sides; + if (eachInterior % 1 !== 0) { + eachInterior = '~' + Math.round(eachInterior); + } + if (eachExterior % 1 !== 0) { + eachExterior = '~' + Math.round(eachExterior); + } + this.setState({ + output: 'Total Interior: ' + totalInterior + '°\nEach Interior: ' + eachInterior + '°\nEach Exterior: ' + eachExterior + '°' + }) + } else { + this.setState({ + output: 'Total Interior: ' + totalInterior + '°' + }) + } + } + } + + render() { + return ( + <div> + <CalcOut mode={this.props.mode} output={this.state.output} /> + <Pad + type={'large'} + buttonValues={['type', 'sides', 'select']} + displayValues={[this.state.type, '# of sides', '…']} + textValues={[this.state.sides]} + onClick={this.onTypeClick} + onChange={this.onChange} + onModeClick={this.props.onModeChange} + /> + </div> + ); + } +} +PolygonAngle.propTypes = { + mode: PropTypes.string.isRequired, + onModeChange: PropTypes.func.isRequired +}; +\ No newline at end of file