Skip to content

Commit

Permalink
add fists support for angle and add method to point, smith examples #1
Browse files Browse the repository at this point in the history
  • Loading branch information
sytabaresa committed Aug 25, 2023
1 parent 0dc3293 commit fd5cf21
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 57 deletions.
30 changes: 30 additions & 0 deletions data/smith/examples/ex1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***
* Ejercice #1 (https://www.youtube.com/watch?v=pJsnWQLZHds)
* @author: Sebastian Tabares ([email protected])
* @version: 1.0
**/
Zo = 50;
text(1.2, 1.1, "Zo: " + Zo);
Zln = complex(60, 40) / Zo;
Zl = spoint(Zln);
k_a = circle(po, Zl);
text(1.2, 1, function() {
return "coef (1 method): " + Zl.nCoef();
});
text(1.2, .9, function() {
return "coef (2 method): " + k_a.radius();
});
A = intersection(ax_x, k_a, 0);
text(1.2, .8, function() {
return "SWR (1 method): " + A.SX();
});
text(1.2, .7, function() {
return "SWR (2 method): " + Zl.SWR();
});
C = angle(Zl, po, -240 * PI / 180);
text(1.2, .6, function() {
return "Zin: " + C.Z();
});
text(1.2, .5, function() {
return "Zi: " + C.Z() * Zo;
});
13 changes: 13 additions & 0 deletions data/smith/test-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/***
* Test Text
* @author: your name ([email protected])
* @version: 1.0
**/
Zo = 50;
Zln = complex(60, 40) / Zo;
Zl = spoint(Zln);
k_a = circle(po, Zl);
A = intersection(ax_x, k_a, 0);
text(1, 1, function() {
return "SWR: " + A.SX();
});
2 changes: 1 addition & 1 deletion src/common/components/atoms/infobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface InfoboxProps {
export function Infobox(props: InfoboxProps) {
const { x, y, el } = props

// console.log(el)
// console.log(el, x, y)

if (JXG.isPoint(el)) {
const sx = zRePart(x, y)
Expand Down
9 changes: 7 additions & 2 deletions src/common/components/atoms/projectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ const ProjectCard = (props: ProjectCard) => {
<h2 className="text-2xs md:text-md my-2 font-bold">{name}</h2>
<p>{description}</p>
<div className="absolute right-0 bottom-0 dropdown dropdown-end" onClick={e => e.stopPropagation()}>
<label tabIndex={0} className="btn btn-ghost"><DotsVerticalIcon className="w-6" /></label>
<label tabIndex={0} className="btn btn-ghost rounded-none"><DotsVerticalIcon className="w-6" /></label>
<ul tabIndex={0} className="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-52 z-10">
<li><a role="button" onClick={(e) => { e.stopPropagation(); removeProject(id) }}><TrashIcon className="w-6" />{t.saved.delete()}</a></li>
<li>
<a role="button" onClick={(e) => { e.stopPropagation(); removeProject(id) }}>
<TrashIcon className="w-6" />
{t.saved.delete()}
</a>
</li>
</ul>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/common/types/jsxgraphExtensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ declare namespace JXG {
export function createPoint(board: Board, parents: unknown[], attributes: PointAttributes): Point
export function createPointOld(board: Board, parents: unknown[], attributes: PointAttributes): Point
export function createComplex(board: Board, parents: unknown[], attributes: PointAttributes): Point
export function createAngle(board: Board, parents: unknown[], attributes: AngleAttributes): Angle
export function createAngleOld(board: Board, parents: unknown[], attributes: AngleAttributes): Angle


export interface JXGOptions {
recircle: CircleOptions | GeometryElementAttributes;
Expand Down
35 changes: 35 additions & 0 deletions src/modules/core/elements/angle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Angle } from "jsxgraph"
import JXG from "jsxgraph"

JXG.createAngleOld = JXG.createAngle
JXG.createAngle = function (board, parents: any[], attributes): Angle {
if (!JXG.exists(attributes))
attributes = {};
const attr = JXG.copyAttributes(attributes, board.options, 'angle');
// console.log(parents)
if (parents.length == 3 && JXG.isNumber(parents[2])) {
const { name, ...rest } = attr
const p1 = parents[0]
const p2 = parents[1]
const an = parents[2]

const auxp = board.create('point', [0, 0], { ...(name && { name }) })
const angle: Angle = board.create(Math.abs(an) > Math.PI ? 'reflexangle' : 'nonreflexangle', [p1, p2, auxp], rest)
angle.setAngle(an)
auxp.setAttribute({ fixed: true, })
return auxp

} else {
const angle: Angle = JXG.createAngleOld(board, parents, attr)

// console.log(sp)
return angle
}
};

JXG.registerElement('angle', JXG.createAngle);

// JXG.Options.angle = {
// strokeColor: 'blue',
// fillColor: 'blue',
// }
8 changes: 8 additions & 0 deletions src/modules/core/elements/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "@core/elements/common"
export * from "@core/elements/smithPoint"
export * from "@core/elements/point"
export * from "@core/elements/reCircle"
export * from "@core/elements/imCircle"
export * from "@core/elements/imCircleAd"
export * from "@core/elements/reCircleAd"
export * from "@core/elements/angle"
38 changes: 26 additions & 12 deletions src/modules/core/elements/point.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
import { Point } from "jsxgraph"
import JXG from "jsxgraph"
import { reflecImPart, reflecRePart } from "@core/utils/transforms";
import { zRePart, zImPart, abs } from "@core/utils/transforms";

JXG.createPointOld = JXG.createPoint
JXG.createPoint = function (board, parents: any[], attributes): Point {
if (!JXG.exists(attributes))
attributes = {};
const attr = JXG.copyAttributes(attributes, board.options, 'point');
// console.log(parents)
if (parents.length == 1 && JXG.isObject(parents[0]) && parents[0].isComplex) {
if (!JXG.exists(attributes))
attributes = {};

var c: JXG.Complex = parents[0]

var sp: any = board.create('point', [c.real, c.imaginary], attr)
sp.cX = () => reflecRePart(sp.X(), sp.Y())
sp.cY = () => reflecImPart(sp.X(), sp.Y())
return sp as Point
const c: JXG.Complex = parents[0]

const p: any = board.create('point', [c.real, c.imaginary], attr)
return p as Point
} else if (parents.length == 1 && JXG.isNumber(parents[0])) {
const re = parents[0]
var sp: any = board.create('point', [re, 0], attr)
return sp as Point
const p: any = board.create('point', [re, 0], attr)
return p as Point
} else {
return JXG.createPointOld(board, parents, attr)
const p: any = JXG.createPointOld(board, parents, attr)

p.SX = () => zRePart(p.X(), p.Y())
p.SY = () => zImPart(p.X(), p.Y())
p.Z = () => new JXG.Complex(p.SX(), p.SY())
p.coef = () => new JXG.Complex(p.X(), p.Y())
p.nCoef = () => abs(p.X(), p.Y())
p.SWR = () => (1 + p.nCoef()) / (1 - p.nCoef())

p.methodMap['SX'] = 'SX'
p.methodMap['SY'] = 'SY'
p.methodMap['Z'] = 'Z'
p.methodMap['coef'] = 'coef'
p.methodMap['nCoef'] = 'nCoef'
p.methodMap['SWR'] = 'SWR'

// console.log(sp)
return p as Point
}
};

Expand Down
6 changes: 1 addition & 5 deletions src/modules/core/elements/smithPoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SmithPoint } from "jsxgraph"
import JXG from "jsxgraph"
import { reflecImPart, reflecRePart, zImPart, zRePart } from "@core/utils/transforms";
import { reflecImPart, reflecRePart } from "@core/utils/transforms";

JXG.OBJECT_TYPE_SMITH_POINT = 99
JXG.createSmithPoint = function (board, parents: any[], attributes) {
Expand All @@ -18,8 +18,6 @@ JXG.createSmithPoint = function (board, parents: any[], attributes) {

sp.type = JXG.OBJECT_TYPE_SMITH_POINT
sp.elType = 'spoint'
sp.SX = () => zRePart(sp.X(), sp.Y())
sp.SY = () => zImPart(sp.X(), sp.Y())
return sp as SmithPoint
} else if (parents.length == 1 && JXG.isObject(parents[0]) && parents[0].isComplex) {
var c: JXG.Complex = parents[0]
Expand All @@ -30,8 +28,6 @@ JXG.createSmithPoint = function (board, parents: any[], attributes) {

sp.type = JXG.OBJECT_TYPE_SMITH_POINT
sp.elType = 'spoint'
sp.SX = () => zRePart(sp.X(), sp.Y())
sp.SY = () => zImPart(sp.X(), sp.Y())
return sp as SmithPoint
} else if (parents.length == 1 && JXG.isNumber(parents[0])) {
const re = parents[0]
Expand Down
26 changes: 13 additions & 13 deletions src/modules/core/jxg/initBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const initBoard = (options: BoardConfigOptions) => {
// taken for the original funtion, but modified
brd.updateInfobox = function (el: GeometryElement & { infoboxText: string }) {
var x, y, xc, yc,
vpinfoboxdigits,
// vpinfoboxdigits,
distX, distY,
vpsi = JXG.evaluate(el.visProp.showinfobox);
if ((!JXG.evaluate(this.attr.showinfobox) && vpsi === "inherit") || !vpsi) {
Expand All @@ -105,29 +105,29 @@ export const initBoard = (options: BoardConfigOptions) => {
yc = el.coords.usrCoords[2];
distX = JXG.evaluate(this.infobox.visProp.distancex);
distY = JXG.evaluate(this.infobox.visProp.distancey);
vpinfoboxdigits = JXG.evaluate(el.visProp.infoboxdigits);
// vpinfoboxdigits = JXG.evaluate(el.visProp.infoboxdigits);
this.infobox.setCoords(
xc + distX / this.unitX,
yc + distY / this.unitY
);

if (typeof el.infoboxText !== "string") {
if (vpinfoboxdigits === "auto") {
x = JXG.autoDigits(xc);
y = JXG.autoDigits(yc);
} else if (JXG.isNumber(vpinfoboxdigits)) {
x = JXG.toFixed(xc, vpinfoboxdigits);
y = JXG.toFixed(yc, vpinfoboxdigits);
} else {
x = xc;
y = yc;
}
// if (vpinfoboxdigits === "auto") {
// x = JXG.autoDigits(xc);
// y = JXG.autoDigits(yc);
// } else if (JXG.isNumber(vpinfoboxdigits)) {
// x = JXG.toFixed(xc, vpinfoboxdigits);
// y = JXG.toFixed(yc, vpinfoboxdigits);
// } else {
x = xc;
y = yc;
// }
this.highlightInfobox(x, y, el);
} else {
this.highlightCustomInfobox(el.infoboxText, el);
}
this.displayInfobox(true);
} else {
} else { // added to the original version
const coords = this.getUsrCoordsOfMouse()
xc = coords[0];
yc = coords[1];
Expand Down
16 changes: 8 additions & 8 deletions src/modules/core/utils/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export const darkTheme = {
// layer: 5
// }
// },

// text: {
// fontSize: 10,
// strokeColor: 'gray',
// useASCIIMathML: false,
// useMathJax: false,
// defaultDisplay: 'html'
// },
text: {
// fontSize: 10,
strokeColor: 'gray',
highlightStrokeColor: 'gray',
// useASCIIMathML: false,
// useMathJax: false,
// defaultDisplay: 'html'
},

// curve: {
// strokeWidth: '2px',
Expand Down
10 changes: 2 additions & 8 deletions src/pages/saved.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import { useTranslation } from "@modules/i18n"
import Layout from "@components/templates/default";
import { PlusIcon, RefreshIcon } from "@heroicons/react/outline"
import NewProjectForm from "@components/molecules/newProjectForm";
import { useDataProvider, useList } from "@hooks/useDataProvider";
import { useDataProvider } from "@hooks/useDataProvider";
import createModal from "@components/molecules/createModal";
import { ProjectList } from "@components/molecules/projectList";

// custom elements
import "@core/elements/common"
import "@core/elements/smithPoint"
import "@core/elements/point"
import "@core/elements/reCircle"
import "@core/elements/imCircle"
import "@core/elements/imCircleAd"
import "@core/elements/reCircleAd"
import "@core/elements"

import '@styles/jsxgraph.css';

Expand Down
9 changes: 1 addition & 8 deletions src/pages/smith.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ import { UserMenu } from "@components/organisms/userMenu";
import Footer from "@components/organisms/footer";

// custom elements
import "@core/elements/common"
import "@core/elements/smithPoint"
import "@core/elements/point"
import "@core/elements/reCircle"
import "@core/elements/imCircle"
import "@core/elements/imCircleAd"
import "@core/elements/reCircleAd"

import "@core/elements"
import '@styles/jsxgraph.css';

export { SmithProjectPage as Page }
Expand Down

0 comments on commit fd5cf21

Please sign in to comment.