From 54188a07cef8cb2ac55c778250d62b62be3dc538 Mon Sep 17 00:00:00 2001 From: Philip Hallwirth <37780428+Traumlos@users.noreply.github.com> Date: Sun, 23 Mar 2025 00:15:03 +0100 Subject: [PATCH 01/10] superficial refactor and added java doc to math folder --- src/main/java/maths/BigFraction.java | 297 ++-- src/main/java/maths/BigSquareRoot.java | 144 +- src/main/java/maths/CharSet.java | 79 +- src/main/java/maths/GMono.java | 39 - src/main/java/maths/Param.java | 144 +- src/main/java/maths/PolyBasic.java | 1976 ++++++++++-------------- src/main/java/maths/TDono.java | 16 +- src/main/java/maths/TMono.java | 34 +- src/main/java/maths/TPoly.java | 61 +- 9 files changed, 1243 insertions(+), 1547 deletions(-) delete mode 100644 src/main/java/maths/GMono.java diff --git a/src/main/java/maths/BigFraction.java b/src/main/java/maths/BigFraction.java index 440ef0fb..aa7f34be 100644 --- a/src/main/java/maths/BigFraction.java +++ b/src/main/java/maths/BigFraction.java @@ -2,9 +2,10 @@ import java.io.Serializable; import java.math.BigInteger; -import java.math.BigDecimal; - +/** + * Represents a fraction with arbitrary precision using BigInteger. + */ public class BigFraction implements Cloneable, Comparable, Serializable { protected final BigInteger numerator_; protected final BigInteger denominator_; @@ -12,23 +13,30 @@ public class BigFraction implements Cloneable, Comparable, Serializable { final public static BigFraction ZERO = new BigFraction("0/1"); final public static BigFraction ONE = new BigFraction("1/1"); - - public long intNumerator() { - return numerator_.intValue(); - } - - public long intDenominator() { - return denominator_.intValue(); - } - + /** + * Returns the numerator as a BigInteger. + * + * @return the numerator as a BigInteger + */ public BigInteger numerator() { return numerator_; } + /** + * Returns the denominator as a BigInteger. + * + * @return the denominator as a BigInteger + */ public BigInteger denominator() { return denominator_; } + /** + * Constructs a BigFraction with the specified numerator and denominator. + * + * @param num the numerator + * @param den the denominator + */ public BigFraction(BigInteger num, BigInteger den) { boolean numNonnegative = gteq(num, BigInteger.ZERO); @@ -44,34 +52,52 @@ public BigFraction(BigInteger num, BigInteger den) { denominator_ = b.divide(g); } - - public BigFraction(long n) { - this(BigInteger.valueOf(n), BigInteger.valueOf(1)); - } - + /** + * Constructs a BigFraction with the specified BigInteger numerator. + * + * @param b the numerator + */ public BigFraction(BigInteger b) { this(b, BigInteger.valueOf(1)); } + /** + * Copy constructor for BigFraction. + * + * @param f the BigFraction to copy + */ public BigFraction(BigFraction f) { numerator_ = f.numerator(); denominator_ = f.denominator(); } + /** + * Constructs a BigFraction from a string representation. + * + * @param s the string representation of the fraction + */ public BigFraction(String s) { this(new BigInteger(s.substring(0, s.indexOf('/'))), new BigInteger(s.substring(s.indexOf('/') + 1))); } + /** + * Constructs a BigFraction with the specified long numerator and denominator. + * + * @param num the numerator + * @param den the denominator + */ public BigFraction(long num, long den) { this(new BigInteger(Long.toString(num)), new BigInteger(Long.toString(den))); } - //------------------ - // Override toString - //------------------ - + /** + * Returns a string representation of the fraction. + * + * @return the string representation of the fraction + */ + @Override public String toString() { BigInteger b2 = denominator(); @@ -81,42 +107,54 @@ public String toString() { return numerator().toString(); } - //-------------------------------- - // Required to implement Cloneable - //-------------------------------- - + /** + * Creates and returns a copy of this BigFraction. + * + * @return a clone of this BigFraction + */ public Object clone() { return new BigFraction(this); } - //---------------------------- - // Utility comparison routines - //---------------------------- - - private boolean gt(BigInteger x, BigInteger y) { - return x.compareTo(y) > 0; - } - + /** + * Checks if this fraction is greater than or equal to the specified BigInteger. + * + * @param x the first BigInteger + * @param y the second BigInteger + * @return true if x is greater than or equal to y; false otherwise + */ private boolean gteq(BigInteger x, BigInteger y) { return x.compareTo(y) >= 0; } + /** + * Checks if the numerator is greater than or equal to the specified BigInteger. + * + * @param y the BigInteger to compare with + * @return true if the numerator is greater than or equal to y; false otherwise + */ private boolean gteq(BigInteger y) { return numerator_.compareTo(y) >= 0; } + /** + * Checks if this fraction is less than the specified BigInteger. + * + * @param x the first BigInteger + * @param y the second BigInteger + * @return true if x is less than y; false otherwise + */ private boolean lt(BigInteger x, BigInteger y) { return x.compareTo(y) < 0; } - private boolean lteq(BigInteger x, BigInteger y) { - return x.compareTo(y) <= 0; - } - - //------------ - // Get minimum - //------------ + /** + * Returns the minimum of this fraction and the specified fraction. + * + * @param val the fraction to compare with + * @return the minimum fraction + */ public BigFraction min(BigFraction val) { if (compareTo(val) <= 0) { return this; @@ -125,10 +163,12 @@ public BigFraction min(BigFraction val) { } } - //------------ - // Get maximum - //------------ - + /** + * Returns the maximum of this fraction and the specified fraction. + * + * @param val the fraction to compare with + * @return the maximum fraction + */ public BigFraction max(BigFraction val) { if (compareTo(val) > 0) { return this; @@ -137,43 +177,24 @@ public BigFraction max(BigFraction val) { } } - //------------------------------------------------------- - // Convert to BigDecimal - // Rounding mode is any of BigDecimal.ROUND_xxx constants - //------------------------------------------------------- - - public BigDecimal asBigDecimal(int scale, int roundingMode) { - BigDecimal num = new BigDecimal(numerator()); - BigDecimal den = new BigDecimal(denominator()); - return num.divide(den, scale, roundingMode); - } - - //------------------ - // Get negated value - //------------------ - - public BigFraction negate() { - return new BigFraction(numerator().negate(), denominator()); - } - - //--------------------------- - // Get multiplicative inverse - //--------------------------- - - public BigFraction inverse() { - return new BigFraction(denominator(), numerator()); - } - - //---- - // Add - //---- - + /** + * Raises this fraction to the power of the specified integer. + * + * @param d the exponent + * @return the resulting fraction + */ public BigFraction pow(int d) { BigInteger an = numerator(); BigInteger ad = denominator(); return new BigFraction(an.pow(d), (ad.pow(d))); } + /** + * Adds the specified fraction to this fraction. + * + * @param b the fraction to add + * @return the resulting fraction + */ public BigFraction add(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -182,38 +203,32 @@ public BigFraction add(BigFraction b) { return new BigFraction(an.multiply(bd).add(bn.multiply(ad)), ad.multiply(bd)); } + /** + * Adds the specified BigInteger to this fraction. + * + * @param n the BigInteger to add + * @return the resulting fraction + */ public BigFraction add(BigInteger n) { return add(new BigFraction(n, BigInteger.ONE)); } + /** + * Adds the specified long value to this fraction. + * + * @param n the long value to add + * @return the resulting fraction + */ public BigFraction add(long n) { return add(new BigInteger(Long.toString(n))); } - //--------- - // Subtract - //--------- - - public BigFraction subtract(BigFraction b) { - BigInteger an = numerator(); - BigInteger ad = denominator(); - BigInteger bn = b.numerator(); - BigInteger bd = b.denominator(); - return new BigFraction(an.multiply(bd).subtract(bn.multiply(ad)), ad.multiply(bd)); - } - - public BigFraction subtract(BigInteger n) { - return subtract(new BigFraction(n, BigInteger.ONE)); - } - - public BigFraction subtract(long n) { - return subtract(new BigInteger(Long.toString(n))); - } - - //--------- - // Multiply - //--------- - + /** + * Multiplies this fraction by the specified fraction. + * + * @param b the fraction to multiply by + * @return the resulting fraction + */ public BigFraction multiply(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -222,18 +237,22 @@ public BigFraction multiply(BigFraction b) { return new BigFraction(an.multiply(bn), ad.multiply(bd)); } + /** + * Multiplies this fraction by the specified BigInteger. + * + * @param n the BigInteger to multiply by + * @return the resulting fraction + */ public BigFraction multiply(BigInteger n) { return multiply(new BigFraction(n, BigInteger.ONE)); } - public BigFraction multiply(long n) { - return multiply(new BigInteger(Long.toString(n))); - } - - //------- - // Divide - //------- - + /** + * Divides this fraction by the specified fraction. + * + * @param b the fraction to divide by + * @return the resulting fraction + */ public BigFraction divide(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -242,14 +261,21 @@ public BigFraction divide(BigFraction b) { return new BigFraction(an.multiply(bd), ad.multiply(bn)); } + /** + * Divides this fraction by the specified BigInteger. + * + * @param n the BigInteger to divide by + * @return the resulting fraction + */ public BigFraction divide(BigInteger n) { return divide(new BigFraction(n, BigInteger.ONE)); } - public BigFraction divide(long n) { - return divide(new BigInteger(Long.toString(n))); - } - + /** + * Calculates the square root of this fraction if it is non-negative. + * + * @return the square root as a BigFraction, or null if not a perfect square + */ public BigFraction sqrt() { if (!gteq(BigInteger.ZERO)) return null; @@ -263,14 +289,22 @@ public BigFraction sqrt() { return null; } - //--------------------------------- - // Required to implement Comparable - //--------------------------------- + /** + * Checks if the numerator is zero. + * + * @return true if the numerator is zero; false otherwise + */ public boolean isZero() { return numerator().compareTo(BigInteger.ZERO) == 0; } + /** + * Compares this fraction with another object. + * + * @param other the object to compare with + * @return -1, 0, or 1 as this fraction is less than, equal to, or greater than the given object + */ public int compareTo(Object other) { BigFraction b = (BigFraction) (other); BigInteger an = numerator(); @@ -289,31 +323,52 @@ public int compareTo(Object other) { } } + /** + * Compares this fraction with a BigInteger. + * + * @param n the BigInteger to compare with + * @return -1, 0, or 1 as this fraction is less than, equal to, or greater than the given BigInteger + */ public int compareTo(BigInteger n) { Object obj = new BigFraction(n, BigInteger.ONE); return compareTo(obj); } - //---------------- - // Override equals - //---------------- - + /** + * Checks if this fraction is equal to another object. + * + * @param other the object to compare with + * @return true if the fractions are equal; false otherwise + */ public boolean equals(Object other) { return compareTo((BigFraction) other) == 0; } + /** + * Checks if this fraction is equal to a BigInteger. + * + * @param n the BigInteger to compare with + * @return true if equal; false otherwise + */ public boolean equals(BigInteger n) { return compareTo(n) == 0; } + /** + * Checks if this fraction is equal to a long value. + * + * @param n the long value to compare with + * @return true if equal; false otherwise + */ public boolean equals(long n) { return equals(new BigInteger(Long.toString(n))); } - //------------------ - // Override hashCode - //------------------ - + /** + * Returns a hash code for this fraction. + * + * @return the hash code computed from numerator and denominator + */ public int hashCode() { int num = numerator().intValue(); int den = denominator().intValue(); diff --git a/src/main/java/maths/BigSquareRoot.java b/src/main/java/maths/BigSquareRoot.java index 181d7aef..d6795385 100644 --- a/src/main/java/maths/BigSquareRoot.java +++ b/src/main/java/maths/BigSquareRoot.java @@ -3,39 +3,25 @@ import java.math.BigDecimal; import java.math.BigInteger; +/** + * Provides methods to calculate square roots and cube roots with arbitrary precision. + */ public class BigSquareRoot { - private static BigDecimal ZERO = BigDecimal.ZERO; - private static BigDecimal ONE = BigDecimal.ONE; - private static BigDecimal TWO = new BigDecimal("2"); - private static BigDecimal THREE = new BigDecimal("3"); + private static final BigDecimal ZERO = BigDecimal.ZERO; + private static final BigDecimal ONE = BigDecimal.ONE; + private static final BigDecimal TWO = new BigDecimal("2"); public static final int DEFAULT_MAX_ITERATIONS = 50; public static final int DEFAULT_SCALE = 10; private static int maxIterations = DEFAULT_MAX_ITERATIONS; - //--------------------------------------- - // The error is the original number minus - // (sqrt * sqrt). If the original number - // was a perfect square, the error is 0. - //--------------------------------------- - - //------------------- - // Maximum iterations - //------------------- - - private static int getMaxIterations() { - return maxIterations; - } - - private static void setMaxIterations(int maxIterations) { - maxIterations = maxIterations; - } - - //-------------------------- - // Get initial approximation - //-------------------------- - + /** + * Gets an initial approximation for the square root computation. + * + * @param n the BigDecimal for which to compute the initial approximation + * @return the initial guess as a BigDecimal + */ private static BigDecimal getInitialApproximation(BigDecimal n) { BigInteger integerPart = n.toBigInteger(); int length = integerPart.toString().length(); @@ -47,18 +33,25 @@ private static BigDecimal getInitialApproximation(BigDecimal n) { return guess; } - //---------------- - // Get square root - //---------------- - + /** + * Calculates the square root of a BigInteger. + * + * @param n the BigInteger for which to calculate the square root + * @return the square root as a BigDecimal + * @throws IllegalArgumentException if n is non-positive + */ public static BigDecimal get(BigInteger n) { return get(new BigDecimal(n)); } + /** + * Calculates the square root of a BigDecimal. + * + * @param n the BigDecimal for which to calculate the square root + * @return the square root as a BigDecimal + * @throws IllegalArgumentException if n is non-positive + */ private static BigDecimal get(BigDecimal n) { - - // Make sure n is a positive number - if (n.compareTo(ZERO) <= 0) { throw new IllegalArgumentException(); } @@ -73,9 +66,6 @@ private static BigDecimal get(BigDecimal n) { if (length > 20) scale = (length / 2); - // Iterate - - iterations = 0; boolean more = true; BigDecimal error; while (more) { @@ -91,66 +81,24 @@ private static BigDecimal get(BigDecimal n) { } } return guess; - } - //---------------------- - // Get random BigInteger - //---------------------- - - private static BigInteger getRandomBigInteger(int nDigits) { - StringBuffer sb = new StringBuffer(); - java.util.Random r = new java.util.Random(); - for (int i = 0; i < nDigits; i++) { - sb.append(r.nextInt(10)); - } - return new BigInteger(sb.toString()); - } - - //----- - // Test - //----- - -// public static void main(String[] args) { -// -// BigInteger n; -// BigDecimal sqrt; -// BigSquareRoot app = new BigSquareRoot(); -// // Generate a random big integer with a hundred digits -// -// n = BigSquareRoot.getRandomBigInteger(100); -// -// // Build an array of test numbers -// -// String testNums[] = {"9", "30", "720", "1024", n.multiply(n).toString()}; -// -// for (int i = 0; i < testNums.length; i++) { -// n = new BigInteger(testNums[i]); -// if (i > 0) { -// System.out.println("----------------------------"); -// } -// System.out.println("Computing the square root of"); -// System.out.println(n.toString()); -// int length = n.toString().length(); -// if (length > 20) { -// app.setScale(length / 2); -// } -// sqrt = app.get(n); -// BigInteger dd = sqrt.multiply(sqrt).toBigInteger().subtract(n); -// System.out.println("Iterations " + app.getIterations()); -// System.out.println("Sqrt " + sqrt.toString()); -// System.out.println(sqrt.multiply(sqrt).toString()); -// System.out.println(n.toString()); -// System.out.println("Error " + app.getError().toString()); -// } -// -// } - + /** + * Calculates the square root of a BigInteger. + * + * @param b the BigInteger for which to calculate the square root + * @return the square root as a BigDecimal + */ public static BigDecimal sqrt(BigInteger b) { - return get(b); } + /** + * Calculates the integer square root of a BigInteger if it is a perfect square. + * + * @param b the BigInteger for which to calculate the integer square root + * @return the integer square root if perfect; null otherwise + */ public static BigInteger sqrtI(BigInteger b) { BigDecimal b1 = sqrt(b); BigInteger b2 = b1.toBigInteger(); @@ -158,18 +106,4 @@ public static BigInteger sqrtI(BigInteger b) { return b2; return null; } - -// Newton Method to get the cube root on BigIntegers : - - public static BigDecimal CubeRoot(BigDecimal B, int iter) { //????????????? - BigDecimal[] cubique = new BigDecimal[2]; - cubique[0] = B.divide(THREE); - for (int i = 0; i < iter; i++) { - cubique[1] = ((cubique[0].multiply(TWO)).add(B.divide(cubique[0].pow(2)))).divide(THREE); - cubique[0] = cubique[1]; - } - return cubique[0]; - } - - -} +} \ No newline at end of file diff --git a/src/main/java/maths/CharSet.java b/src/main/java/maths/CharSet.java index 990069fb..46d7a4fa 100644 --- a/src/main/java/maths/CharSet.java +++ b/src/main/java/maths/CharSet.java @@ -1,25 +1,38 @@ package maths; -//import wprover.CMisc; - +/** + * Represents a character set for polynomial operations. + */ public class CharSet { final private static boolean DEBUG = false; - private PolyBasic basic = PolyBasic.getInstance(); - private static CharSet charset = new CharSet(); + private final PolyBasic basic = PolyBasic.getInstance(); + private static final CharSet charset = new CharSet(); private static int REDUCE_LEN = 2; + /** + * Returns the debug status. + * + * @return true if debug is enabled; false otherwise + */ public static boolean debug() { return DEBUG; } + /** + * Returns the singleton instance of CharSet. + * + * @return the singleton instance + */ public static CharSet getinstance() { return charset; } - public long freemonos() { - return 0; - } - + /** + * Processes the given polynomial and returns the resulting polynomial. + * + * @param pp the input polynomial + * @return the resulting polynomial + */ public TPoly charset(TPoly pp) { TPoly rm, ch, chend, p, output; output = null; @@ -51,7 +64,6 @@ public TPoly charset(TPoly pp) { chend.setNext(null); rm = tp; - if (ch == chend) { output = basic.ppush(ch.getPoly(), output); } else { @@ -86,11 +98,9 @@ public TPoly charset(TPoly pp) { poly = null; } } - } } -// this.printpoly(output); reduce(output); TPoly tp = reverse(output); if (!cfinished(tp)) @@ -106,15 +116,25 @@ public TPoly charset(TPoly pp) { return tp; } - public TPoly reduce1(TPoly poly) // 1, 2, 3, 4, 5 - { + /** + * Reduces the given polynomial. + * + * @param poly the input polynomial + * @return the reduced polynomial + */ + public TPoly reduce1(TPoly poly) { poly = reverse(poly); reduce(poly); poly = reverse(poly); return poly; } - public void reduce(TPoly poly) { // n ,n-1,,,,,,, 1. + /** + * Reduces the given polynomial in place. + * + * @param poly the input polynomial + */ + public void reduce(TPoly poly) { TPoly p1 = poly; while (p1 != null) { TMono m = p1.poly; @@ -130,7 +150,12 @@ public void reduce(TPoly poly) { // n ,n-1,,,,,,, 1. } } - + /** + * Checks if the given polynomial is finished. + * + * @param pp the input polynomial + * @return true if the polynomial is finished; false otherwise + */ public boolean cfinished(TPoly pp) { if (pp == null) return true; int a = basic.lv(pp.getPoly()); @@ -147,6 +172,11 @@ public boolean cfinished(TPoly pp) { return true; } + /** + * Prints the given polynomial. + * + * @param pp the input polynomial + */ public void printpoly(TPoly pp) { int i = 0; while (pp != null) { @@ -160,6 +190,12 @@ public void printpoly(TPoly pp) { } } + /** + * Reverses the given polynomial. + * + * @param pp the input polynomial + * @return the reversed polynomial + */ public static TPoly reverse(TPoly pp) { if (pp == null) return pp; TPoly out = null; @@ -177,16 +213,5 @@ public static TPoly reverse(TPoly pp) { } } return out; - } - - public TPoly pushpoly(TMono p, TPoly pp) { - TPoly pt; - - pt = new TPoly(); - pt.setNext(pp); - pt.setPoly(p); - return pt; - } - -} +} \ No newline at end of file diff --git a/src/main/java/maths/GMono.java b/src/main/java/maths/GMono.java deleted file mode 100644 index 5982616b..00000000 --- a/src/main/java/maths/GMono.java +++ /dev/null @@ -1,39 +0,0 @@ -package maths; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-5-28 - * Time: 22:11:39 - * To change this template use File | Settings | File Templates. - */ -public class GMono { - public int x = 0; - public int deg = 0; - public BigFraction val = null; - public TMono coef = null; - public TMono next = null; - - public GMono() { - - } - - public GMono(int x, int val, int deg) { - this.x = x; - this.deg = deg; - if (x == 0 || deg == 0) { - this.x = 0; - this.deg = 0; - this.val = new BigFraction(val,1); - } else { - this.coef = new TMono(0, val, 0); - } - - } - - public GMono(int x, TMono coef, int deg) { - this.x = x; - this.deg = deg; - this.coef = coef; - } -} diff --git a/src/main/java/maths/Param.java b/src/main/java/maths/Param.java index b6282295..a6c15c1b 100644 --- a/src/main/java/maths/Param.java +++ b/src/main/java/maths/Param.java @@ -1,57 +1,91 @@ package maths; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.DataInputStream; - -public class Param { - public static int VARIABLE = 0; - public static int STATIC = 1; - - public int type = 0; - public int xindex; - public double value; - - public boolean Solved = false; - public TMono m = null; - - - public Param() { - } - - public Param(int index, double val) { - xindex = index; - value = val; - } - - public void setParameterStatic() { - type = STATIC; - } - - public String toString() { - String s = "x" + xindex; - if (m != null && m.deg != 1) - s += "^" + m.deg; - return s; - } - - public String getString() { - String s = "x" + xindex; - return s; - } - - public void Save(DataOutputStream out) throws IOException { - out.writeInt(type); - out.writeInt(xindex); - out.writeDouble(value); - out.writeBoolean(Solved); - } - - public void Load(DataInputStream in) throws IOException { - type = in.readInt(); - xindex = in.readInt(); - value = in.readDouble(); - Solved = in.readBoolean(); - } - -} + import java.io.DataOutputStream; + import java.io.IOException; + import java.io.DataInputStream; + + /** + * Represents a parameter with a type, index, value, and optional monomial. + */ + public class Param { + public static int STATIC = 1; + + public int type = 0; + public int xindex; + public double value; + + public boolean Solved = false; + public TMono m = null; + + /** + * Default constructor for Param. + */ + public Param() { + } + + /** + * Constructs a Param with the specified index and value. + * + * @param index the index of the parameter + * @param val the value of the parameter + */ + public Param(int index, double val) { + xindex = index; + value = val; + } + + /** + * Sets the parameter type to static. + */ + public void setParameterStatic() { + type = STATIC; + } + + /** + * Returns a string representation of the parameter. + * + * @return the string representation of the parameter + */ + public String toString() { + String s = "x" + xindex; + if (m != null && m.deg != 1) + s += "^" + m.deg; + return s; + } + + /** + * Returns a string representation of the parameter index. + * + * @return the string representation of the parameter index + */ + public String getString() { + String s = "x" + xindex; + return s; + } + + /** + * Saves the parameter to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ + public void Save(DataOutputStream out) throws IOException { + out.writeInt(type); + out.writeInt(xindex); + out.writeDouble(value); + out.writeBoolean(Solved); + } + + /** + * Loads the parameter from a DataInputStream. + * + * @param in the DataInputStream to read from + * @throws IOException if an I/O error occurs + */ + public void Load(DataInputStream in) throws IOException { + type = in.readInt(); + xindex = in.readInt(); + value = in.readDouble(); + Solved = in.readBoolean(); + } + } \ No newline at end of file diff --git a/src/main/java/maths/PolyBasic.java b/src/main/java/maths/PolyBasic.java index 892d5ae5..26ec1ec4 100644 --- a/src/main/java/maths/PolyBasic.java +++ b/src/main/java/maths/PolyBasic.java @@ -2,13 +2,11 @@ import java.util.Vector; -//import java.util.regex.Pattern; -//import java.math.BigDecimal; -//import java.math.MathContext; import java.math.BigInteger; -//import java.math.RoundingMode; - +/** + * This class provides basic polynomial operations. + */ public class PolyBasic { private static int MAXSTR = 100; final private static double ZERO = 10E-6; @@ -16,19 +14,41 @@ public class PolyBasic { private static boolean BB_STOP = false; private static boolean RM_SCOEF = true; + /** + * Returns the singleton instance of the PolyBasic class. + * + * @return the singleton instance of PolyBasic + */ public static PolyBasic getInstance() { return basic; } + /** + * Sets the BB\_STOP flag. + * + * @param t the new value for the BB\_STOP flag + */ public static void setbbStop(boolean t) { BB_STOP = t; } + /** + * Sets the RM\_SCOEF flag. + * + * @param s the new value for the RM\_SCOEF flag + */ public static void setRMCOEF(boolean s) { RM_SCOEF = s; } - +/** + * Adds two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param es a flag indicating whether to perform exact simplification + * @return the resulting polynomial after addition + */ private TMono pp_plus(TMono p1, TMono p2, boolean es) { if (p1 == null) return p2; @@ -100,16 +120,36 @@ private TMono pp_plus(TMono p1, TMono p2, boolean es) { return (poly); } - + /** + * Subtracts one polynomial from another. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the resulting polynomial after subtraction + */ private TMono pp_minus(TMono p1, TMono p2) { TMono m = pp_plus(p1, cp_times(-1, p2), true); return m; } + /** + * Multiplies a polynomial by a constant. + * + * @param c the constant to multiply by + * @param p1 the polynomial to be multiplied + * @return the resulting polynomial after multiplication + */ public TMono cp_times(long c, TMono p1) { return cp_times(BigInteger.valueOf(c), p1); } + /** + * Multiplies a polynomial by a constant. + * + * @param c the constant to multiply by + * @param p1 the polynomial to be multiplied + * @return the resulting polynomial after multiplication + */ private TMono cp_times(BigInteger c, TMono p1) { if (p1 == null || c.compareTo(BigInteger.ZERO) == 0) return null; if (c.compareTo(BigInteger.ONE) == 0) return p1; @@ -126,6 +166,13 @@ private TMono cp_times(BigInteger c, TMono p1) { return p1; } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the resulting polynomial after multiplication + */ private TMono pp_times(TMono p1, TMono p2) //(m X n) { if (p1 == null || p2 == null) return null; @@ -168,6 +215,13 @@ private TMono pp_times(TMono p1, TMono p2) //(m X n) return (poly); } + /** + * Multiplies two monomials. + * + * @param p1 the first monomial + * @param p2 the second monomial + * @return the resulting monomial after multiplication + */ private TMono mp_times(TMono p1, TMono p2) // p1.x <= p2.x { TMono poly = p2; @@ -199,6 +253,12 @@ private TMono mp_times(TMono p1, TMono p2) // p1.x <= p2.x return (poly); } + /** + * Checks if the given polynomial is zero. + * + * @param m the polynomial to check + * @return true if the polynomial is zero, false otherwise + */ public boolean check_zero(TMono m) { if (m == null) return false; if (m.x == 0 && m.value() == 0) return true; @@ -211,16 +271,30 @@ public boolean check_zero(TMono m) { return false; } + /** + * Returns the degree of the given polynomial `p` with respect to the variable `x`. + * + * @param p the polynomial to check + * @param x the variable to check the degree against + * @return the degree of the polynomial with respect to `x` + */ public int deg(TMono p, int x) { if (p.x == x) return p.deg; if (p.x > x) { int d1 = deg(p.coef, x); int d2 = deg(p.next, x); - return d1 > d2 ? d1 : d2; + return Math.max(d1, d2); } return 0; } + /** + * Reduces the given polynomial `m` using the provided parameters `p`. + * + * @param m the polynomial to be reduced + * @param p the array of parameters used for reduction + * @return the reduced polynomial + */ public TMono reduce(TMono m, Param[] p) { if (m == null) return null; @@ -249,7 +323,13 @@ else if (pm.xindex == x) { return m; } - // simplify an tmono to low degree. Note here we don't remove coef. + /** + * Simplifies a polynomial to a lower degree without removing coefficients. + * + * @param m the polynomial to simplify + * @param p the array of parameters used for simplification + * @return the simplified polynomial + */ public TMono simplify(TMono m, Param[] p) { if (m == null) return null; @@ -277,6 +357,13 @@ else if (pm.xindex == x) { return m; } + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ public TMono prem(TMono p1, TMono p2) { if (p1 == null) return p1; @@ -301,6 +388,13 @@ public TMono prem(TMono p1, TMono p2) { return result; } + /** + * Returns the degree of the polynomial `m` with respect to the variable `x`. + * + * @param m the polynomial + * @param x the variable + * @return the degree of the polynomial with respect to `x` + */ private int degree(TMono m, int x) { if (m == null || m.x < x) return 0; @@ -311,59 +405,61 @@ private int degree(TMono m, int x) { return 0; } + /** + * Checks if the pseudo-remainder of two polynomials can be computed. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return true if the pseudo-remainder can be computed, false otherwise + */ private boolean can_prem3(TMono p1, TMono p2) { if (p1 == null || p2 == null) return false; return prem3(p1, p2, false) == null; } + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ private TMono prem3(TMono p1, TMono p2) { return prem3(p1, p2, true); } - private TMono prem3(TMono p1, TMono p2, boolean r /*do all*/) { // p1.x > p2.x. + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param r a flag indicating whether to perform all steps + * @return the pseudo-remainder of the two polynomials + */ + private TMono prem3(TMono p1, TMono p2, boolean r) { if (p2 == null) return p1; int x = p2.x; if (x == 0) return p1; TMono[] mm = new TMono[2]; - getm2(p1, p2, mm);//, x, p2.deg, mm); + getm2(p1, p2, mm); boolean rx = false; while (mm[0] != null && mm[1] != null) { -// int d1 = degree(mm[0], x); -// int d2 = degree(p2, x); if (p1 != null) { -// if (d1 >= d2) { -// int dd = d1 - d2; { -// TMono l1 = ptimes(p_copy(mm[0].coef), mm[1]); -// if (rx) { -// print(p1); -// print(p2); -// print(mm[0]); -// print(mm[1]); -// } TMono t1 = pp_times(p1, mm[0]); TMono t2 = pp_times(p_copy(p2), mm[1]); -// if(rx) -// { -// print(t1); -// print(t2); -// } p1 = pp_minus(t1, t2); coefgcd(p1); -// if (rx) { -// print(p1); -// System.out.println("\n"); -// } if (p1 == null) break; } } if (p1 == null) break; mm[0] = mm[1] = null; - getm2(p1, p2, mm);// x, p2.deg, mm); // mm[0]: coef , mm[1]. p.x + getm2(p1, p2, mm); if (!r && mm[1] != null && mm[1].x < p1.x) return p1; @@ -371,7 +467,15 @@ private TMono prem3(TMono p1, TMono p2, boolean r /*do all*/) { // p1.x > p2.x return p1; } - private void getm2(TMono p1, TMono p2, TMono[] mm) {// int x, int deg, TMono[] mm) { + + /** + * Computes the monomials `mm` required for the pseudo-remainder calculation. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param mm an array to store the resulting monomials + */ + private void getm2(TMono p1, TMono p2, TMono[] mm) { if (p1 == null || p2 == null || p1.x < p2.x || p1.x == p2.x && p1.deg < p2.deg) return; @@ -400,24 +504,16 @@ private void getm2(TMono p1, TMono p2, TMono[] mm) {// int x, int deg, TMono[] m if (p1 != null && p1.deg == 0) p1 = p1.coef; } - -// if (p.x > x) { -// while (p != null) { -// getm2(p.coef, x, deg, mm); -// if (mm[0] != null) { -// TMono m = pth(p.x, 1, p.deg); -// mm[1] = ptimes(mm[1], m); -// return; -// } -// p = p.next; -// } -// } else if (p.deg >= deg) { -// mm[0] = p; -// mm[1] = pth(0, 1, 0); -// return; -// } } + + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ private TMono prem1(TMono p1, TMono p2) { if (p1 == null) @@ -448,12 +544,6 @@ else if (p1.x > p2.x) { int d1 = deg(p1); int d2 = deg(p2); if (d1 < d2) { - /*TMono m = p1; //comment by ye. 5.31. - p1 = p2; - p2 = m; - int t = d1; - d1 = d2; - d2 = t;*/ break; } if (d1 >= d2) { @@ -477,12 +567,17 @@ else if (p1.x > p2.x) { while (result != null && result.deg == 0 && result.x != 0) result = result.coef; - -// print(result); return result; } + /** + * Divides the degree of the polynomial `m` by `n` for the variable `x`. + * + * @param m the polynomial to be modified + * @param x the variable whose degree is to be divided + * @param n the divisor for the degree + */ public void div_factor1(TMono m, int x, int n) { if (x > m.x) return; @@ -510,39 +605,11 @@ public void div_factor1(TMono m, int x, int n) { } - public void factor2(TMono m1) { - TMono m = this.get_factor2(m1); - if (m == null) - return; - while (m != null) { - if (m.x != 0) { - this.div_factor1(m1, m.x, m.deg); - } - m = m.coef; - } - } - - public TMono get_factor2(TMono m) { - if (m == null) - return null; - - TMono mx = null; - TMono m1 = m; - long n = 0; - while (m != null) { - if (m.x != 0) - n = factor_contain(m.x, m.deg, m1); - if (n != 0) { - if (mx == null) - mx = new TMono(m.x, 1, (int) n); - else - mx = this.pp_times(mx, new TMono(m.x, 1, (int) n)); - } - m = m.coef; - } - return mx; - } - + /** + * Factors the polynomial `m1` by dividing it by its common factors. + * + * @param m1 the polynomial to be factored + */ public void factor1(TMono m1) { if (!RM_SCOEF) return; @@ -558,6 +625,12 @@ public void factor1(TMono m1) { } } + /** + * Gets the common factors of the polynomial `m`. + * + * @param m the polynomial to get factors from + * @return the common factors of the polynomial + */ public TMono get_factor1(TMono m) { if (m == null) return null; @@ -580,6 +653,14 @@ public TMono get_factor1(TMono m) { return mx; } + /** + * Checks if the polynomial `m` contains the factor `(x, d)`. + * + * @param x the variable of the factor + * @param d the degree of the factor + * @param m the polynomial to check + * @return true if the polynomial contains the factor, false otherwise + */ private boolean m_contain(long x, long d, TMono m) { if (m == null || x > m.x || x == m.x && d > m.deg) return false; @@ -594,6 +675,14 @@ private boolean m_contain(long x, long d, TMono m) { return false; } + /** + * Determines the minimum degree of the factor `(x, n)` contained in the polynomial `m`. + * + * @param x the variable of the factor + * @param n the degree of the factor + * @param m the polynomial to check + * @return the minimum degree of the factor contained in the polynomial + */ private long factor_contain(long x, long n, TMono m) { if (m == null) return n; @@ -622,6 +711,13 @@ else if (t < n) return n; } + /** + * Removes the common factors of the polynomial `p1` using the polynomial `p2`. + * + * @param p1 the polynomial to be factored + * @param p2 the polynomial used for factoring + * @return the factored polynomial + */ public TMono factor_remove(TMono p1, TMono p2) { // p1 ,p2 be destryoed. if (p1 == null || p2 == null || plength(p1) > 1000) return p1; @@ -671,7 +767,13 @@ public TMono factor_remove(TMono p1, TMono p2) { // p1 ,p2 be destryoed. return p1; } - + /** + * Divides the polynomial `m` by the polynomial `d`. + * + * @param m the dividend polynomial + * @param d the divisor polynomial + * @return the quotient polynomial + */ TMono div(TMono m, TMono d) { if (m == null || d == null) return m; @@ -726,6 +828,12 @@ TMono div(TMono m, TMono d) { return result; } + /** + * Creates a copy of the polynomial `p`. + * + * @param p the polynomial to copy + * @return the copied polynomial + */ public TMono p_copy(TMono p) { if (p == null) return null; @@ -739,7 +847,13 @@ public TMono p_copy(TMono p) { } - + /** + * Compares two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return -1 if p1 is less than p2, 1 if p1 is greater than p2, 0 if they are equal + */ private int pp_compare(TMono p1, TMono p2) { if (p1 == null && p2 == null) return 0; @@ -758,6 +872,12 @@ private int pp_compare(TMono p1, TMono p2) { return pp_compare(p1.next, p2.next); } + /** + * Pushes a polynomial into a sorted vector. + * + * @param m the polynomial to push + * @param v the vector to push into + */ public void ppush(TMono m, Vector v) { if (m == null) return; @@ -772,6 +892,13 @@ public void ppush(TMono m, Vector v) { v.add(m); } + /** + * Compares two polynomials for sorting. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return -1 if p1 is less than p2, 1 if p1 is greater than p2, 0 if they are equal + */ private int pp_compare2(TMono p1, TMono p2) { if (p1 == null && p2 == null) return 0; @@ -801,84 +928,12 @@ private int pp_compare2(TMono p1, TMono p2) { return n; } - private int pp_compare1(TMono p1, TMono p2) { - if (p1 == null && p2 == null) - return 0; - if (p1 == null && p2 != null) - return -1; - if (p1 != null && p2 == null) - return 1; - int x = Math.max(p1.x, p2.x) + 1; - while (x != 0) { - int x1 = getNextX(x, -1, p1); - int x2 = getNextX(x, -1, p2); - if (x1 > x2) - return 1; - else if (x1 < x2) - return -1; - else { - int d1 = this.getMaxDeg(x1, 1000, -1, p1); - int d2 = this.getMaxDeg(x2, 1000, -1, p2); - if (d1 > d2) - return 1; - else if (d1 < d2) - return -1; - else { - int d = d1; - while (d != 0) { - d1 = this.getMaxDeg(x1, d, -1, p1); - d2 = this.getMaxDeg(x2, d, -1, p2); - if (d1 > d2) - return 1; - else if (d1 < d2) - return -1; - d--; - } - } - x = x1; - } - } - return 1; - } - - private int getNextX(int x, int x1, TMono m) { // x1 < x . - if (m == null) return x1; - if (m.x <= x1) return x1; - while (m != null) { - if (m.x <= x1) return x1; - - if (m.x < x && m.x > x1) - x1 = m.x; - x1 = getNextX(x, x1, m.coef); - m = m.next; - if (m == null) - break; - if (m.deg == 0) - m = m.coef; - } - return x1; - } - - private int getMaxDeg(int x, int dmax, int d, TMono m) { // dd < d , dd > d1; return dd; - if (m == null) return d; - if (m.x < x) return d; - - while (m != null) { - if (m.x < x) return d; - - if (m.x == x && m.deg > d && m.deg < dmax) - d = m.deg; - d = getMaxDeg(x, dmax, d, m.coef); - m = m.next; - if (m == null) - break; - - if (m.deg == 0) - m = m.coef; - } - return d; - } - + /** + * Checks if the given polynomial is an integer. + * + * @param p the polynomial to check + * @return true if the polynomial is an integer, false otherwise + */ private boolean Int(TMono p) { if (p == null) return false; @@ -890,14 +945,11 @@ private boolean Int(TMono p) { return false; } - public void dprint(TMono p, int dx) { - upValueTM(p, -dx); - String s = getExpandedPrint(p); - System.out.println(s); -// print(p); - upValueTM(p, dx); - } - + /** + * Prints the given polynomial. + * + * @param p the polynomial to print + */ public void print(TMono p) { if (p == null) return; @@ -907,15 +959,27 @@ public void print(TMono p) { System.out.print(String_p_print(p, false, true, true)); -// p_print(p, false, true); System.out.print("\n"); } + /** + * Prints the polynomial in a simplified format. + * + * @param p the polynomial to print + */ public void sprint(TMono p) { p_print(p, false, true); } - private void p_print(TMono p, boolean ce, boolean first) { // coefficent ? print "+" of first ? + + /** + * Prints the polynomial in a specified format. + * + * @param p the polynomial to print + * @param ce a flag indicating whether to enclose the polynomial in parentheses + * @param first a flag indicating whether this is the first polynomial in a sequence + */ + private void p_print(TMono p, boolean ce, boolean first) { if (p == null) return; if (p.next == null) ce = false; @@ -946,6 +1010,12 @@ private void p_print(TMono p, boolean ce, boolean first) { // coefficent ? } } + /** + * Prints a monomial in a polynomial. + * + * @param p the monomial to print + * @param first a flag indicating whether this is the first monomial in the polynomial + */ private void m_print(TMono p, boolean first) { if (p.x == 0) { if (first != true) { @@ -981,14 +1051,37 @@ private void m_print(TMono p, boolean first) { } } + + /** + * Creates a new monomial with the specified variable, coefficient, and degree. + * + * @param x the variable of the monomial + * @param c the coefficient of the monomial + * @param d the degree of the monomial + * @return the created monomial + */ public TMono pth(int x, int c, int d) { return new TMono(x, c, d); } + /** + * Creates a new monomial with the specified variable, BigInteger coefficient, and degree. + * + * @param x the variable of the monomial + * @param c the BigInteger coefficient of the monomial + * @param d the degree of the monomial + * @return the created monomial + */ public TMono pth(int x, BigInteger c, int d) { return new TMono(x, c, d); } + /** + * Returns the degree of the given polynomial. + * + * @param p the polynomial + * @return the degree of the polynomial + */ public int deg(TMono p) { if (p == null) { int k = 0; @@ -996,15 +1089,32 @@ public int deg(TMono p) { return p.deg; } + /** + * Returns the leading variable of the given polynomial. + * + * @param p the polynomial + * @return the leading variable of the polynomial + */ public int lv(TMono p) { if (p == null) return 0; return p.x; } + /** + * Returns a zero polynomial. + * + * @return a zero polynomial + */ public TMono pzero() { return null; } + /** + * Returns the length of the given polynomial. + * + * @param m the polynomial + * @return the length of the polynomial + */ public int plength(TMono m) { if (m == null) return 0; @@ -1015,12 +1125,12 @@ public int plength(TMono m) { } } - boolean pzerom(TMono m) { - if (m == null) - return true; - return (!pzerop(m.coef) && m.next == null); - } - + /** + * Checks if the given polynomial is zero. + * + * @param m the polynomial to check + * @return true if the polynomial is zero, false otherwise + */ public boolean pzerop(TMono m) { if (m == null) return true; @@ -1029,7 +1139,13 @@ public boolean pzerop(TMono m) { return pzerop(m.coef) && pzerop(m.next); } - + /** + * Adds a monomial to a polynomial. + * + * @param t the monomial to add + * @param p the polynomial to add to + * @return the resulting polynomial after addition + */ TPoly addpoly(TMono t, TPoly p) { TPoly poly = new TPoly(); poly.setNext(p); @@ -1038,17 +1154,14 @@ TPoly addpoly(TMono t, TPoly p) { return poly; } - TPoly addPolytoList(TPoly pl, TPoly pp) { - if (pl == null) return pp; - - while (pl != null) { - pp = ppush(pl.getPoly(), pp); - pl = pl.getNext(); - } - return pp; - } - - public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. + /** + * Pushes a polynomial into a sorted linked list. + * + * @param t the polynomial to push + * @param pp the linked list to push into + * @return the updated linked list with the polynomial added + */ + public TPoly ppush(TMono t, TPoly pp) { if (t == null) return pp; @@ -1104,6 +1217,13 @@ public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. return pp; } + /** + * Calculates the value of a polynomial given the polynomial and parameters. + * + * @param m the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return the calculated value of the polynomial + */ double calpoly(TMono m, Param[] p) { if (m == null || p == null) return 0.0; @@ -1123,6 +1243,13 @@ public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. } + /** + * Calculates the values of the polynomial `mm` given the parameters `p`. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomial + */ public double[] calculv(TMono mm, Param[] p) { int x, d; double[] result = null; @@ -1210,6 +1337,13 @@ else if (d == 4 && ee != 0) return null; } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomial + */ public double[] calculv_2v(TMono mm, Param[] p) { if (mm.next != null) return this.calculv(mm.next.coef, p); @@ -1217,11 +1351,16 @@ public double[] calculv_2v(TMono mm, Param[] p) { return null; } -// public double[] calculate_onlinex(TMono mm, param[] p, int dx, int dy) { -// CLine ln = this. - -// } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @param dx the first variable index + * @param dy the second variable index + * @return an array of calculated values of the polynomial + */ public double[] calculate_online(TMono mm, Param[] p, int dx, int dy) { if (mm.deg != 1 && mm.x != dy) return null; @@ -1258,6 +1397,15 @@ public double[] calculate_online(TMono mm, Param[] p, int dx, int dy) { return result; } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @param dx the first variable index + * @param dy the second variable index + * @return an array of calculated values of the polynomial + */ public double[] calculate_oncr(TMono mm, Param[] p, int dx, int dy) { if (mm.deg != 2 && mm.x != dy) return null; @@ -1304,7 +1452,15 @@ public double[] calculate_oncr(TMono mm, Param[] p, int dx, int dy) { return result; } - public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two poly + /** + * Calculates the values of two polynomials `mm1` and `mm2` given the parameters `p`. + * + * @param mm1 the first polynomial to calculate + * @param mm2 the second polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomials + */ + public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) { int x, d; double[] result; @@ -1362,7 +1518,6 @@ public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two pol if (result == null || result.length == 0) result = calculv(mm2, p); if (result == null || result.length == 0) { -// System.out.println("parell two line"); return null; } return result; @@ -1370,62 +1525,91 @@ public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two pol } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the product of the two polynomials + */ public TMono pRtimes(TMono p1, TMono p2) { return pp_times(p1, p2); } - public TMono pQtimer(TMono t1, TMono t2, TMono t3, TMono t4) { - return this.pp_times(p_copy(t1), pp_times(p_copy(t2), pp_times(p_copy(t3), p_copy(t4)))); - } - + /** + * Adds two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the sum of the two polynomials + */ public TMono padd(TMono p1, TMono p2) { //add TMono m = (pp_plus(p1, p2, true)); return m; } + /** + * Subtracts the second polynomial from the first polynomial. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the difference of the two polynomials + */ public TMono pdif(TMono p1, TMono p2) {//minus TMono m = (pp_minus(p1, p2)); return m; } - TMono redundancy(TMono m) { - return m; - } - - boolean isZero(TMono m) { - if (m == null) return true; - if (Int(m)) { - if (m.value() == 0) - return true; - else - return false; - } - - if (m.x != 0 && m.coef == null) return isZero(m.next); - return false; - } - + /** + * Creates a copy of the given polynomial. + * + * @param p the polynomial to copy + * @return the copied polynomial + */ public TMono pcopy(TMono p) { return p_copy(p); } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the product of the two polynomials + */ public TMono ptimes(TMono p1, TMono p2) { return pp_times(p1, p2); } + /** + * Multiplies a polynomial by a constant. + * + * @param p the polynomial + * @param c the constant + * @return the product of the polynomial and the constant + */ public TMono pctimes(TMono p, long c) { return cp_times(BigInteger.valueOf(c), p); } - void pr(TMono m) { - print(m); - } - + /** + * Prints the given polynomial. + * + * @param m the polynomial to print + */ public void printpoly(TMono m) { print(m); } + + /** + * Gets the monomial with the minimum degree for the given variable in the polynomial. + * + * @param x the variable + * @param p the polynomial + * @return the monomial with the minimum degree for the given variable + */ TMono getMinV(int x, TPoly p) { TMono poly = null; int exp = 0; @@ -1447,36 +1631,12 @@ TMono getMinV(int x, TPoly p) { } - - public TPoly OptimizePoly(TPoly poly) { - TPoly t = poly; - while (poly != null) { - TMono m = poly.getPoly(); - m = opt(m); - poly.setPoly(m); - poly = poly.getNext(); - } - return t; - } - - TMono opt(TMono m) { - if (m == null) return null; - - if (Int(m)) return m; - - if (m.x <= 3 && m.x > 0) - return null; - - m.coef = opt(m.coef); - m.next = opt(m.next); - - if (m.coef == null && m.deg != 0) m = m.next; - if (isZero(m)) return null; - - return m; - } - - + /** + * Returns the head of the polynomial as a string. + * + * @param m the polynomial + * @return the head of the polynomial as a string + */ public String printHead(TMono m) { if (m == null) return "0"; @@ -1488,11 +1648,22 @@ public String printHead(TMono m) { return "x" + v; } + /** + * Returns a simplified string representation of the polynomial. + * + * @param m the polynomial + * @return the simplified string representation of the polynomial + */ public String printSPoly(TMono m) { return printSPoly(m, MAXSTR); } - + /** + * Returns a string representation of the polynomial with a maximum length. + * + * @param m the polynomial + * @return the string representation of the polynomial with a maximum length + */ public String printNPoly(TMono m) { if (m == null) return ""; @@ -1504,6 +1675,13 @@ public String printNPoly(TMono m) { return s; } + /** + * Returns a string representation of two polynomials with a maximum length. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the string representation of the two polynomials with a maximum length + */ public String printNPoly(TMono m1, TMono m2) { int n1 = plength(m1); int n2 = plength(m2); @@ -1516,6 +1694,13 @@ public String printNPoly(TMono m1, TMono m2) { return s1 + s2 + " != 0"; } + /** + * Returns a simplified string representation of the polynomial with a specified maximum length. + * + * @param m the polynomial + * @param n the maximum length of the string representation + * @return the simplified string representation of the polynomial with a specified maximum length + */ public String printSPoly(TMono m, int n) { if (m == null) return "0"; @@ -1527,6 +1712,12 @@ public String printSPoly(TMono m, int n) { return s; } + /** + * Returns a string representation of the polynomial with a maximum length. + * + * @param m the polynomial + * @return the string representation of the polynomial with a maximum length + */ public String printMaxstrPoly(TMono m) { int n = MAXSTR; if (m == null) @@ -1538,35 +1729,15 @@ public String printMaxstrPoly(TMono m) { return s; } - public String printSPoly1(TMono m, int n) { - if (m == null) - return ""; - - String s = StringPrint(m); - if (s.length() > n) - return s.substring(0, n) + "...."; - - return s; - } - - public String StringPrint(TMono p) { - StringBuffer buffer = new StringBuffer(); - String_p_print(p, true, buffer); - return buffer.toString(); - } - - public void String_p_print(TMono p, boolean nn, StringBuffer buffer) { - if (p == null) return; - while (p != null) { - if (String_mprint(p.coef, buffer)) - buffer.insert(0, '+'); - buffer.append("x" + p.x + "" + p.deg); - if (p.deg == 0) - p = p.coef; - else p = p.next; - } - } - + /** + * Returns a string representation of the polynomial. + * + * @param p the polynomial + * @param ce a flag indicating whether to enclose the polynomial in parentheses + * @param first a flag indicating whether this is the first polynomial in a sequence + * @param nn a flag indicating whether to include the leading coefficient + * @return the string representation of the polynomial + */ public String String_p_print(TMono p, boolean ce, boolean first, boolean nn) { if (p == null) return ""; if (p.next == null) ce = false; @@ -1606,29 +1777,12 @@ public String String_p_print(TMono p, boolean ce, boolean first, boolean nn) { return s; } - - public boolean String_mprint(TMono m, StringBuffer buffer) { - boolean br = false; - if (m == null) return br; - - if (m.next != null) - br = true; - if (br) - buffer.append("("); - while (m != null) { - String_mprint(m.coef, buffer); - if (String_mprint(m.coef, buffer)) - buffer.insert(0, '+'); - buffer.append(m.x + "" + m.deg); - if (m.deg == 0) - m = m.coef; - else m = m.next; - } - if (br) - buffer.append(")"); - return br; - } - + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @return the string representation of the polynomial with expanded format + */ public String getExpandedPrint(TMono p) { String r = ep_print(p, "", true); if (r != null && (r.endsWith("-") || r.endsWith("+"))) @@ -1636,6 +1790,14 @@ public String getExpandedPrint(TMono p) { return r; } + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @param s the string to append to + * @param f a flag indicating whether this is the first polynomial in a sequence + * @return the string representation of the polynomial with expanded format + */ private String ep_print(TMono p, String s, boolean f) { String st = ""; while (p != null) { @@ -1654,6 +1816,14 @@ private String ep_print(TMono p, String s, boolean f) { return st; } + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @param s the string to append to + * @param f a flag indicating whether this is the first polynomial in a sequence + * @return the string representation of the polynomial with expanded format + */ private String eprint(TMono p, String s, boolean f) { if (p == null) return ""; @@ -1694,6 +1864,13 @@ private String eprint(TMono p, String s, boolean f) { } } + /** + * Returns a string representation of all printed monomials in the polynomial. + * + * @param p the polynomial + * @param b a flag indicating whether to include the leading coefficient + * @return the string representation of all printed monomials in the polynomial + */ public String getAllPrinted(TMono p, boolean b) { int n = MAXSTR; MAXSTR = 1000000; @@ -1724,11 +1901,25 @@ public String getAllPrinted(TMono p, boolean b) { else return s; } + /** + * Returns a string representation of all printed monomials in the polynomial. + * + * @param p the polynomial + * @return the string representation of all printed monomials in the polynomial + */ public String getAllPrinted(TMono p) { return getAllPrinted(p, true); } + /** + * Returns a string representation of the monomial. + * + * @param p the monomial + * @param first a flag indicating whether this is the first monomial in the polynomial + * @param nn a flag indicating whether to include the leading coefficient + * @return the string representation of the monomial + */ private String String_m_print(TMono p, boolean first, boolean nn) { @@ -1774,6 +1965,12 @@ else if (t != 1) return s; } + /** + * Returns the greatest common divisor of the coefficients of the polynomial. + * + * @param p the polynomial + * @return the greatest common divisor of the coefficients of the polynomial + */ public BigInteger coefgcd(TMono p) { if (p == null) return BigInteger.ONE; @@ -1793,6 +1990,13 @@ public BigInteger coefgcd(TMono p) { return c; } + /** + * Divides the coefficients of the polynomial by the given constant. + * + * @param m the polynomial + * @param c the constant to divide by + * @return true if successful, false otherwise + */ private boolean coef_div(TMono m, BigInteger c) { if (m == null) return true; if (m.x == 0) { @@ -1806,23 +2010,24 @@ private boolean coef_div(TMono m, BigInteger c) { } + /** + * Returns the greatest common divisor of two BigInteger values. + * + * @param a the first BigInteger + * @param b the second BigInteger + * @return the greatest common divisor of the two BigInteger values + */ BigInteger gcd(BigInteger a, BigInteger b) { return a.gcd(b); } - private long gcd(long a, long b) { - long t; - - a = Math.abs(a); - b = Math.abs(b); - while (b != 0) { - t = b; - b = a % b; - a = t; - } - return a; - } - + /** + * Returns the greatest common divisor of the coefficients of the polynomial. + * + * @param p the polynomial + * @param c the constant to divide by + * @return the greatest common divisor of the coefficients of the polynomial + */ private BigInteger coefgcd(TMono p, BigInteger c) { if (p == null) return c; @@ -1847,10 +2052,24 @@ private BigInteger coefgcd(TMono p, BigInteger c) { return c; } + /** + * Checks if the given value is close to zero. + * + * @param r the value to check + * @return true if the value is close to zero, false otherwise + */ private boolean ZERO(double r) { return Math.abs(r) < ZERO; } + /** + * Solves a quadratic polynomial equation. + * + * @param aa the coefficient of x^2 + * @param bb1 the coefficient of x + * @param bb2 the constant term + * @return an array of solutions to the equation + */ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { double[] result; @@ -1884,6 +2103,15 @@ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { return result; } + /** + * Solves a cubic polynomial equation. + * + * @param a the coefficient of x^3 + * @param b the coefficient of x^2 + * @param c the coefficient of x + * @param d the constant term + * @return an array of solutions to the equation + */ double[] poly_solve_cubic(double a, double b, double c, double d) { double p = (3 * c / a - (b * b / (a * a))) / 3; double q = (2 * Math.pow(b / a, 3) - 9 * b * c / a / a + 27 * d / a) / 27; @@ -1918,6 +2146,12 @@ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { return null; } + /** + * Calculates the cubic root of a given value. + * + * @param r the value to calculate the cubic root of + * @return the cubic root of the value + */ private double cubic_root(double r) { double r1 = Math.pow(Math.abs(r), 1.0 / 3.0); if (r < 0) @@ -1925,50 +2159,15 @@ private double cubic_root(double r) { return r1; } -// double[] cal_e4(double A, double B, double C, double D, double E, double rt) { -// double a = -3 * B * B / (8 * A * A) + C / A; -// double b = B * B * B / (8 * A * A * A) - B * C / (2 * A * A) + D / A; -// double c = -3 * B * B * B * B / (256 * A * A * A * A) + C * B * B / (16 * A * A * A) - B * D / (4 * A * A) + E / A; -// double p = -a * a / 12 - c; -// double q = -a * a * a / 108 + a * c / 3 - b * b / 8; -// double r = q / 2 + Math.sqrt(q * q / 4 + p * p * p / 27); -// double u = Math.pow(r, 1 / 3.0); -// double y = -5 / 6 * a - u; -// if (Math.abs(u) > ZERO) -// y += p / (3 * u); -// -// double w = Math.sqrt(a + 2 * y); -// double t1 = -(3 * a + 2 * y + 2 * b / w); -// double t2 = -(3 * a + 2 * y - 2 * b / w); -// int n = 0; -// double v1, v2, v3, v4; -// if (t1 < 0 && t2 < 0) -// return null; -// else if (t1 > 0 && t2 > 0) -// n = 4; -// else -// n = 2; -// -// int i = 0; -// double d[] = new double[n]; -// -// if (t1 > 0) { -// v1 = -b / (4 * a) + (w + Math.sqrt(t1)) / 2; -// v2 = -b / (4 * a) + (w - Math.sqrt(t1)) / 2; -// d[i++] = v1 / rt; -// d[i++] = v2 / rt; -// -// } -// -// if (t2 > 0) { -// v3 = -b / (4 * a) + (-w + Math.sqrt(t2)) / 2; -// v4 = -b / (4 * a) + (-w - Math.sqrt(t2)) / 2; -// d[i++] = v3 / rt; -// d[i++] = v4 / rt; -// } -// return d; -// } - + /** + * Solves a quartic polynomial equation. + * + * @param a the coefficient of x^4 + * @param b the coefficient of x^3 + * @param c the coefficient of x^2 + * @param d the coefficient of x + * @return an array of solutions to the equation + */ double[] poly_solve_quartic(double a, double b, double c, double d) { /* * This code is based on a simplification of @@ -2061,16 +2260,6 @@ private double cubic_root(double r) { u[0] = A + B - rc / 3; u[1] = -0.5 * (A + B) - rc / 3; u[2] = -(Math.sqrt(3.0) / 2.0) * mod_diffAB; -// double sgnR = (R >= 0 ? 1 : -1); -// double modR = Math.abs(R); -// double sqrt_disc = Math.sqrt(R2 - Q3); -// double A = -sgnR * Math.pow(modR + sqrt_disc, 1.0 / 3.0); -// double B = Q / A; -// double mod_diffAB = Math.abs(A - B); -// -// u[0] = A + B - rc / 3; -// u[1] = -0.5 * (A + B) - rc / 3; -// u[2] = -(Math.sqrt(3.0) / 2.0) * mod_diffAB; } } @@ -2193,6 +2382,13 @@ private double cubic_root(double r) { ///////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Calculates the polynomial value for the given monomial and coefficients. + * + * @param m the monomial + * @param p the coefficients + * @return the polynomial value + */ BigFraction calpoly(TMono m, BigFraction[] p) { if (m == null || p == null) return BigFraction.ZERO; @@ -2216,192 +2412,26 @@ BigFraction calpoly(TMono m, BigFraction[] p) { return r; } - public int check_ndg(TMono m, Param[] pm) // 0. TRUE 1. FALSE 2.CAN NOT Verify, should be checked by floating point calculation. - { - if (m == null) - return 1; - - int x = m.x; - int n = 0; - for (n = 0; n < pm.length; n++) { - Param p = pm[n]; - if (p == null || p.xindex >= x) - break; - } - BigFraction[] bp = new BigFraction[n + 1]; - - int r = ndg_valid(m, pm, bp, 0); - if (r == -1) { - long k = 1; - for (int i = 0; i <= n; i++) { - if (pm[i].m == null) { - bp[i] = bp[i].add(BigInteger.valueOf(2 * k + 1)); - r = ndg_valid(m, pm, bp, 0); - if (r != -1) - return r; - k++; - } - } - } - - for (int i = 0; i < bp.length; i++) - if (bp[i] != null) - System.out.println(bp[i]); - return -1; - } - - public int ndg_valid(TMono m, Param[] pm, BigFraction[] bp, int n) { - for (int i = n; i < bp.length && pm[i] != null; i++) { - Param p = pm[i]; - if (p.m == null) { - if (bp[i] == null) - bp[i] = new BigFraction((long) p.value); - } else { - BigFraction[] bb = calcu_pm(p.m, bp, p); - if (bb == null) // no solution. - return -1; - else if (bb.length == 0) - return 1; // not equal.. - else if (bb.length == 1) - bp[i] = bb[0]; - else { - for (int j = 0; j < bb.length; j++) { - bp[i] = bb[j]; - int b1 = ndg_valid(m, pm, bp, i + 1); - if (b1 != 1) - return b1; - } - } - } - } - boolean r = calpoly(m, bp).compareTo(BigInteger.ZERO) == 0; - if (r) - return 0; - else return 1; - } - - public BigFraction[] calcu_pm(TMono m, BigFraction[] bp, Param pm) { // return null if m.coef == 0 - if (m.deg == 1) { - BigFraction a = calpoly(m.coef, bp); - if (a.isZero()) return null; - - BigFraction b = calpoly(m.next, bp); - BigFraction[] bb = new BigFraction[1]; - bb[0] = b.divide(a).negate(); - return bb; - } else if (m.deg == 2) { - BigFraction a, b, c; - a = calpoly(m.coef, bp); - if (a.isZero()) return null; - m = m.next; - if (m.deg == 1) { - b = calpoly(m.coef, bp); - m = m.next; - } else b = BigFraction.ZERO; - c = calpoly(m.coef, bp); - BigFraction dl = b.multiply(b).subtract(a.multiply(4).multiply(c)); - dl = dl.sqrt(); - if (dl != null) { - BigFraction[] bb = new BigFraction[2]; - bb[0] = (b.negate().add(dl).divide(a.multiply(2))); - bb[1] = (b.negate().subtract(dl).divide(a.multiply(2))); - return bb; - } else return null; - } else if (m.deg == 3) { - BigFraction a, b, c, d; - a = b = c = d = BigFraction.ZERO; - while (m != null) { - BigFraction f = calpoly(m.coef, bp); - switch (m.x) { - case 3: - a = f; - break; - case 2: - b = f; - break; - case 1: - c = f; - break; - case 0: - d = f; - break; - } - m = m.next; - } - if (a.isZero()) return null; - } - return new BigFraction[0]; - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - private boolean n2dv(TMono m) { - if (plength(m) != 2) return false; - m = m.next; - if (m == null) return false; - return Int(m.coef); - } - - public TPoly gb_reduce(TPoly poly) { -// return bb_reduce(poly); - return null; - } - - public void nn_reduce(TPoly poly) { - while (poly != null) { - TMono m = poly.poly; - if (n2dv(m)) { - while (m != null && m.x != 0) { - nn_div1(m.x, poly.next); - m = m.coef; - } - } - poly = poly.next; - } - } - - public void nn_div1(int x, TPoly poly) { - - while (poly != null) { - TMono m = poly.poly; - while (true) { - long n = factor_contain(x, 1, m); - if (n > 0) - div_factor1(m, x, (int) n); - else break; - } - poly = poly.next; - } - } - - public TMono g_prem(TMono p1, TMono p2) { -// if (p1 == null) -// return p1; -// if (p2 == null) -// return p1; -// if (p1.x < p2.x) -// return p1; -// -// TMono result = null; -// if (p1.x == p2.x) -// result = prem1(p1, p2); -// else -// result = prem3(p1, p2); -// -// coefgcd(result); -// -// return result; - return null; - } - - + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param vlist the list of polynomials to reduce + * @param t the time limit for reduction + * @return the reduced polynomial + */ public Vector bb_reduce(Vector vlist, long t) { bb_reduce(vlist, t, false); -// bb_reduce(vlist, t, false); -// bb_reduce(vlist, t, true); - return vlist; } + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param vlist the list of polynomials to reduce + * @param t the time limit for reduction + * @param s a flag indicating whether to use a special reduction method + * @return the reduced polynomial + */ public Vector bb_reduce(Vector vlist, long t, boolean s) { @@ -2439,7 +2469,6 @@ public Vector bb_reduce(Vector vlist, long t, boolean s) { ppush(m2, vlist); } size = vlist.size(); - // i = size -2; } } if (r) break; @@ -2447,68 +2476,13 @@ public Vector bb_reduce(Vector vlist, long t, boolean s) { return vlist; } - - public void divm(TMono m1, TMono m) { - if (m1 == null || m == null || m1.x <= m.x) return; - - while (m != null && m.x != 0) { - while (true) { - long n = factor_contain(m.x, 1, m1); - if (n > 0) - div_factor1(m1, m.x, (int) n); - else break; - } - m = m.coef; - } - } - - public int get_n_paraent(TMono m) { - if (m == null) - return 0; - int n = 0; - while (m != null) - m = m.coef; - return n; - } - - public TMono sp_reduce(TMono m1, TMono m2) { //m1.x == m2.x - - - while (true) { - - if (m1 == null) return m1; - if (m2 == null) return m1; - if (m1.x != m2.x) - break; - if (m2.coef == null || m2.coef.coef != null) - break; - if (m2.deg != 1) - break; - - // basic.print(m1); - - BigInteger b1 = getLN(m1); - BigInteger b2 = getLN(m2); - - int n = m1.deg; - - BigInteger bc1 = BigInteger.ONE; - BigInteger coefm2 = m2.coef.val; - TMono e = p_copy(m2.next.coef); - e = this.pctimes(e, -1); - - TMono cpm2 = pth(0, 1, 1); - for (int i = 0; i < n; i++) { - bc1 = bc1.multiply(coefm2); - cpm2 = ptimes(cpm2, p_copy(e)); - } - m1 = padd(ptimes(m1.coef, cpm2), this.pctimes(m1.next, bc1.intValue())); -// basic.print(m1); - } - coefgcd(m1); - return m1; - } - + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param vlist the list of polynomials to reduce + * @return the reduced polynomial + */ public TMono b_reduce(TMono m1, Vector vlist) { if (m1 == null) return null; @@ -2541,103 +2515,13 @@ public TMono b_reduce(TMono m1, Vector vlist) { return m1; } - private void ppmove(TPoly pp) { - if (pp == null) return; - TMono m = pp.poly; - TPoly tp = pp.next; - while (tp != null) { - TMono mx = tp.poly; - if (pp_compare(m, mx) < 0) { - tp.poly = m; - pp.poly = mx; - pp = tp; - } else break; - - tp = pp.next; - } - } - - private TPoly shink_poly(TPoly poly) { - if (poly == null) return null; - TPoly tp = poly; - while (tp.next != null) { - if (tp.next.poly == null) - tp.next = tp.next.next; - else - tp = tp.next; - } - if (poly.poly != null) - return poly; - return poly.next; - } - - - private int compare(TMono m1, TMono m2) { - if (m1 == null && m2 == null) return 0; - if (m1 == null && m2 != null) return -1; - if (m1 != null && m2 == null) return 1; - - if (m1.x == 0 && m2.x == 0) return 0; - if (m1.x == 0 && m2.x != 0) return -1; - if (m1.x != 0 && m2.x == 0) return 1; - - if (m1.x > m2.x || m1.x == m2.x && m1.deg > m2.deg) - return 1; - if (m1.x == m2.x && m1.deg == m2.deg) - return 0; - - return -1; - } - - private TMono m_head(TMono m) { - if (m == null) - return null; - while (!Int(m)) - m = m.coef; - return pth(0, m.val, 0); - } - -// private TMono bb_divnh(TMono m1, TMono m2) { -// if (m1 == null || m2 == null) return null; -// int n = compare(m1, m2); -// -// if (n < 0) return null; -// -// if (Int(m1) && Int(m2)) -// return new TMono(0, m1.val, 0); -// -// if (n == 0) { -// TMono mx = bb_divn(m1.coef, m2.coef); -// if (mx == null) -// mx = this.m_head(m1); -// return mx; -// } -// -// if (n > 0) { -// if (m1.x == m2.x) { -// TMono mx = bb_divn(m1.coef, m2.coef); -// if (mx == null) -// mx = this.m_head(m1); -// int dd = m1.deg - m2.deg; -// if (dd > 0) -// mx = pp_times(pth(m1.x, 1, dd), mx); -// -// return mx; -// } else { -// TMono mx = bb_divn(m1.coef, m2); -// if (mx != null) { -// int dd = m1.deg; -// if (dd > 0) -// mx = pp_times(pth(m1.x, 1, dd), mx); -// } -// return mx; -// -// } -// -// } -// return null; -// } - + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the result of the division + */ private TMono bb_divnh(TMono m1, TMono m2) { if (m1 == null || m2 == null) return null; @@ -2667,6 +2551,13 @@ else if (dd > 0) return pp_times(pth(m1.x, 1, m1.deg), mx); } + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the result of the division + */ private TMono bb_divn(TMono m1, TMono m2) { // get a term of m1 which diviid leading variable of m2. if (m1 == null || m2 == null) return null; @@ -2715,12 +2606,24 @@ else if (dd > 0) return null; } + + /** + * Prints the given vector of polynomials. + * + * @param v the vector of polynomials to print + */ public void printVpoly(Vector v) { for (int i = 0; i < v.size(); i++) this.print((TMono) v.get(i)); System.out.println("\n"); } + /** + * Computes the Groebner basis for the given vector of polynomials. + * + * @param v the vector of polynomials + * @return the Groebner basis as a vector of polynomials + */ public Vector g_basis(Vector v) { while (true) { bb_reduce(v, System.currentTimeMillis()); @@ -2741,6 +2644,12 @@ public Vector g_basis(Vector v) { return v; } + /** + * Computes the S-polynomials for the given vector of polynomials. + * + * @param vlist the vector of polynomials + * @return the S-polynomials as a vector of polynomials + */ public Vector s_polys(Vector vlist) { Vector v = new Vector(); @@ -2761,27 +2670,24 @@ public Vector s_polys(Vector vlist) { return v; } - private TMono s_poly(TMono m1, TMono m2) { - if (m1.x == m2.x && m1.deg >= m2.deg) { - - } else if (m_contain(m2.x, m2.deg, m1.coef)) { - - } else return null; - - TMono result; - m1 = p_copy(m1); - m2 = p_copy(m2); - if (m1.x == m2.x) { - result = prem1(m1, m2); - } else - result = prem3(m1, m2); - return result; - } - + /** + * Computes the S-polynomial for two given polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the S-polynomial of the two polynomials + */ private TMono s_poly1(TMono m1, TMono m2) { return prem4(m1, m2); } + /** + * Computes the S-polynomial for two given polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the S-polynomial of the two polynomials + */ private TMono prem4(TMono m1, TMono m2) { if (m1 == null || m2 == null) return null; if (m1.x < m2.x) return m1; @@ -2804,6 +2710,13 @@ private TMono prem4(TMono m1, TMono m2) { return null; } + /** + * Computes the greatest common divisor of two polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the greatest common divisor of the two polynomials + */ private TMono gcd_h(TMono m1, TMono m2) { // gcd of m1, m2. (HEAD); if (m1 == null || m2 == null) return null; TMono mx = null; @@ -2832,6 +2745,13 @@ else if (m1.x < m2.x) return mx; } + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m the second polynomial + * @return the result of the division + */ private TMono div_gcd(TMono m1, TMono m) { TMono mx = pth(0, 1, 0); @@ -2854,36 +2774,14 @@ private TMono div_gcd(TMono m1, TMono m) { return mx; } - private TMono[] mgcd(TMono m1, TMono m2) { - if (m1 == null || m2 == null) return null; - TMono[] mm = new TMono[2]; - bb_div2n(m1, m2, mm); - return mm; - } - - private void bb_div2n(TMono m1, TMono m2, TMono[] mm) { - if (m1 == null || m2 == null) return; - - while (m1 != null) { - if (m1.x > m2.x) { - bb_div2n(m1.coef, m2, mm); - if (mm[0] != null) { - mm[1] = ptimes(pth(m1.x, 1, m1.deg), mm[1]); - return; - } - } else if (m1.x == m2.x && m1.deg >= m2.deg) { - mm[0] = pth(0, 1, 0); - mm[1] = pth(0, 1, 0); - get_mm(m1, m2, mm); - return; - } else break; - - m1 = m1.next; - if (m1 != null && m1.deg == 0) - m1 = m1.coef; - } - } + /** + * Computes the greatest common divisor of two polynomials and stores the result in the provided array. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @param mm the array to store the result + */ private void get_mm(TMono m1, TMono m2, TMono[] mm) { if (m1 == null || m2 == null) return; @@ -2912,6 +2810,12 @@ else if (m1.deg < m2.deg) get_mm(m1, m2, mm); } + /** + * Gets the leading coefficient of a polynomial. + * + * @param m the polynomial + * @return the leading coefficient + */ private BigInteger getLN(TMono m) { if (m == null) return null; while (!Int(m)) @@ -2919,70 +2823,14 @@ private BigInteger getLN(TMono m) { return m.val; } -// public void n_reduce(Vector v1, Vector nlist) { -// for (int i = 0; i < v1.size(); i++) { -// TMono m1 = (TMono) v1.get(i); -// boolean r = false; -// while (true) { -// boolean b = true; -// for (int j = 0; j < nlist.size(); j++) { -// TMono m2 = (TMono) nlist.get(j); -// TMono mm = gcd_h(m1, m2); -// if (mm != null && mm.x != 0) { -// TMono t1 = div_gcd(m1, mm); -// TMono t2 = div_gcd(m2, mm); -// print(m1); -// print(m2); -// m1 = pdif(ptimes(t2, p_copy(m1)), ptimes(t1, p_copy(m2))); -// -// if (CharSet.debug()) { -// print(m1); -// System.out.println("\n"); -// } -// -// r = true; -// b = false; -// } -// } -// if (b) break; -// } -// if (r) { -// v1.remove(i); -// if (m1 == null) -// i--; -// else -// v1.add(i, m1); -// } -// } -// } - - - public TMono ll_gbasis(TMono m1, TMono md, int x, int para) { - if (m1 == null) - return null; - - if (m1.deg == 1) { - TMono m11 = getxm1(x, 1, m1); // u1 - TMono m12 = getxm1(x - 1, 1, m1); // u2 - TMono c11 = pp_times(pth(para, 1, 1), p_copy(m11)); // zu1, - TMono c12 = pp_times(pth(para, 1, 1), p_copy(m12)); // zu2. - - TMono c2 = pth(x, 1, 1); // x1 - TMono t11 = ptimes(c11, p_copy(m1)); // zu1*x1 - TMono t12 = ptimes(c12, p_copy(m12)); // zu2^2 - - TMono t2 = pp_times(c2, p_copy(md)); // x1*md. - - t2 = pdif(t2, t11); - t2 = pp_times(p_copy(m11), t2); - TMono t13 = pp_times(p_copy(m12), pp_times(pth(para, 1, 1), p_copy(m12))); - - - return pdif(t2, pp_times(t13, p_copy(m1))); - } - return null; - } - + /** + * Computes the delta of two polynomials. + * + * @param x the variable + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the delta of the two polynomials + */ public TMono ll_delta(int x, TMono m1, TMono m2) { if (m1 == null) return null; if (m1.deg == 1) { @@ -3021,23 +2869,14 @@ public TMono ll_delta(int x, TMono m1, TMono m2) { return null; } - public TMono getxm1(int x, TMono m) { - if (m == null) - return null; - - if (m.x == x) - return m.coef; - - while (m.next != null) - m = m.next; - if (m.deg != 0) - return null; - m = m.coef; - if (m.deg == 1 && m.x == x) - return m.coef; - return null; - } - + /** + * Gets the leading coefficient of a polynomial. + * + * @param x the variable + * @param d the degree + * @param m the polynomial + * @return the leading coefficient + */ public TMono getxm1(int x, int d, TMono m) { if (m == null) return null; @@ -3058,6 +2897,12 @@ public TMono getxm1(int x, int d, TMono m) { return null; } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param v the polynomial + * @param dx the value to add + */ public void upValueTM(Vector v, int dx) { if (dx == 0) return; @@ -3067,6 +2912,12 @@ public void upValueTM(Vector v, int dx) { } } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param v the polynomial + * @param dx the value to add + */ public void upValueDM(Vector v, int dx) { for (int i = 0; i < v.size(); i++) { TDono d = (TDono) v.get(i); @@ -3076,6 +2927,12 @@ public void upValueDM(Vector v, int dx) { } } + /** + * Gets the maximum value of x in a vector of polynomials. + * + * @param v the vector of polynomials + * @return the maximum value of x + */ public int getMaxX(Vector v) { int x = 0; @@ -3087,6 +2944,12 @@ public int getMaxX(Vector v) { return x; } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param m the polynomial + * @param dx the value to add + */ public void upValueTM(TMono m, int dx) { if (dx == 0) return; @@ -3107,8 +2970,13 @@ public void upValueTM(TMono m, int dx) { m = m.next; } } - - + + /** + * Checks if the polynomial is finished. + * + * @param v the vector of polynomials + * @return true if the polynomial is finished, false otherwise + */ public boolean gb_finished(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -3118,6 +2986,11 @@ public boolean gb_finished(Vector v) { return false; } + /** + * Reduces the polynomial by removing terms with degree 0. + * + * @param v the vector of polynomials + */ public void ndg_reduce(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -3128,7 +3001,13 @@ public void ndg_reduce(Vector v) { } } - + /** + * Gets the conditions for the given vector of polynomials. + * + * @param v the vector of polynomials + * @param dx the value to add + * @return the conditions as a vector of polynomials + */ public Vector getcnds(Vector v, int dx) { Vector v1 = new Vector(); for (int i = 0; i < v.size(); i++) { @@ -3142,93 +3021,14 @@ public Vector getcnds(Vector v, int dx) { return v1; } - public Vector specialTreatment(TMono m1, TMono m2, int dd) { - Vector v = new Vector(); - if (m1 == null) return v; - int x = m1.x; - - if (m1.deg == 1) { - TMono m11 = getxm1(x, 1, m1); - TMono m12 = getxm1(x - 1, 1, m1); - if (m2 == null) { - return v; - } - TMono m21 = getxm1(x, 1, m2); - TMono m22 = getxm1(x - 1, 1, m2); - - - TMono dmm = pdif(ptimes(p_copy(m1), p_copy(m21)), ptimes(p_copy(m11), p_copy(m2))); - dmm = ptimes(pth(dd, 1, 1), dmm); - - TMono dmm1 = pdif(ptimes(p_copy(m1), p_copy(m22)), ptimes(p_copy(m12), p_copy(m2))); - dmm1 = ptimes(pth(dd, 1, 1), dmm1); - v.add(dmm); - v.add(dmm1); - } - return v; - } - - public Vector updateTMM(Vector v, int s, int e, int dx, boolean up) { - Vector v3 = new Vector(); - - for (int i = 0; i < v.size(); i++) { - TMono m = (TMono) v.get(i); - TMono m2 = updateTMM(m, s, e, dx, up); - ppush(m2, v3); - } - return v3; - } - - private TMono updateTMM(TMono m, int s, int e, int dx, boolean up) { - - TMono mx = null; - - if (up) { - while (m != null) { - if (m.x < s && m.x != 0) { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - m1 = ptimes(m1, pth(dx + m.x, 1, m.deg)); - mx = padd(mx, m1); - } else { - if (m.x == 0) { - TMono m1 = pth(0, m.val, m.deg); - mx = padd(mx, m1); - } else { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - if (m.deg != 0) - m1 = ptimes(m1, pth(m.x, 1, m.deg)); - mx = padd(mx, m1); - } - - } - m = m.next; - } - } else { - while (m != null) { - if (m.x > e) { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - m1 = ptimes(m1, pth(m.x - dx, 1, m.deg)); - mx = padd(mx, m1); - } else { - if (m.x == 0) { - TMono m1 = pth(0, m.val, m.deg); - mx = padd(mx, m1); - } else { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - if (m.deg != 0) - m1 = ptimes(m1, pth(m.x, 1, m.deg)); - mx = padd(mx, m1); - } - } - m = m.next; - } - } - return mx; - } - - ////////////////////////////////////////////////////////////////// - //TDono; + /** + * Parses common Dono objects from the given vector of polynomials. + * + * @param v the vector of polynomials + * @param dx the value to add + * @return a vector of parsed Dono objects + */ public Vector parseCommonDono(Vector v, int dx) { Vector v1 = new Vector(); for (int i = 0; i < v.size(); i++) { @@ -3251,6 +3051,11 @@ public Vector parseCommonDono(Vector v, int dx) { return v1; } + /** + * Erases common Dono objects from the given vector of polynomials. + * + * @param v the vector of polynomials + */ public void eraseCommonDono(Vector v) { for (int i = 0; i < v.size(); i++) { TDono d = (TDono) v.get(i); @@ -3266,6 +3071,13 @@ public void eraseCommonDono(Vector v) { } } + /** + * Checks if two monomials are equal. + * + * @param m1 the first monomial + * @param m2 the second monomial + * @return true if the monomials are equal, false otherwise + */ public boolean ck_eq(TMono m1, TMono m2) { while (m1 != null && m2 != null) { if (m1.x != m2.x || m1.deg != m2.deg) @@ -3276,62 +3088,18 @@ public boolean ck_eq(TMono m1, TMono m2) { m2 = m2.next; } - return m1 == m2; // null - } - - public Vector parseDono(Vector v, int dx) { - Vector v1 = new Vector(); - Vector v2 = new Vector(); - - int ldx = 0; - for (int i = 0; i < v.size(); i++) { - TDono d = (TDono) v.get(i); - TMono m = d.p2; - - ldx = getLdx(m, dx); - if (ldx == 0) { - v1.add(d); - } else - v2.add(d); - } - - if (v2.size() == 0) return v1; - - boolean r = true; - - while (true) { - r = true; - - for (int i = 0; i < v2.size(); i++) { - TDono d = (TDono) v2.get(i); - reduceDono(d, v1, dx); - if (getLdx(d.p2, dx) == 0) { - v1.add(d); - v2.remove(d); - i--; - r = false; - } - } - if (r) break; - } - - return v1; - } - - private int getLdx(TMono m, int dx) { - while (m != null) { - - if (m.x > 0 && m.x < dx) - return m.x; - - int n = getLdx(m.coef, dx); - if (n > 0) - return n; - m = m.next; - } - return 0; + return m1 == m2; } + /** + * Checks if the polynomial is less than a given value. + * + * This method only traverses the `coef` chain of the polynomial. + * + * @param m the polynomial + * @param dx the value to compare with + * @return true if the polynomial is less than the given value, false otherwise + */ public boolean ctLessdx1(TMono m, int dx) { while (m != null) { if (m.x > 0 && m.deg > 0 && m.x < dx) @@ -3341,6 +3109,16 @@ public boolean ctLessdx1(TMono m, int dx) { return false; } + + /** + * Checks if the polynomial is less than a given value. + * + * This method traverses both the `coef` and `next` chains of the polynomial and uses recursion. + * + * @param m the polynomial + * @param dx the value to compare with + * @return true if the polynomial is less than the given value, false otherwise + */ public boolean ctLessdx(TMono m, int dx) { int r = 0; @@ -3357,21 +3135,13 @@ public boolean ctLessdx(TMono m, int dx) { return false; } - - private boolean ctLdx(TMono m, int i) { - while (m != null) { - - if (m.x > 0 && m.x == i) - return true; - - boolean n = ctLdx(m.coef, i); - if (n) - return n; - m = m.next; - } - return false; - } - + /** + * Gets the minimum leading degree of a polynomial. + * + * @param m the polynomial + * @param dx the value to compare with + * @return the minimum leading degree, or -1 if not found + */ private int MinLdx(TMono m, int dx) { int r = MinLdx(m); if (r >= dx) @@ -3379,6 +3149,12 @@ private int MinLdx(TMono m, int dx) { return r; } + /** + * Gets the minimum leading degree of a polynomial. + * + * @param m the polynomial + * @return the minimum leading degree + */ private int MinLdx(TMono m) { int r = Integer.MAX_VALUE; @@ -3396,26 +3172,14 @@ private int MinLdx(TMono m) { } - private int MaxLdx(TMono m, int dx) { - int r = 0; - - while (m != null) { - if (m.x == 0) - return -1; - if (m.x < dx) { - if (r < m.x) - r = m.x; - } - - int k = MaxLdx(m.coef, dx); - if (k > 0 && r < k) - r = k; - m = m.next; - } - return r; - } - + /** + * Gets the maximum leading degree of a polynomial. + * + * @param m the polynomial + * @param i the value to compare with + * @return the maximum leading degree + */ private int ctMLdx(TMono m, int i) { // MAX int r = 0; @@ -3439,6 +3203,14 @@ private int ctMLdx(TMono m, int i) { // MAX } + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param mm the polynomial to reduce + * @param v the vector of polynomials + * @param dx the value to add + * @return the reduced polynomial + */ public TMono reduceMDono(TMono mm, Vector v, int dx) { TMono m = mm; @@ -3461,8 +3233,6 @@ public TMono reduceMDono(TMono mm, Vector v, int dx) { for (int k = 0; k < rd; k++) { m = pp_times(m, p_copy(d1.p2)); } -// dprint(m, 9); -// dprint(m2, 9); TMono dp = basic.p_copy(d1.p1); div_factor1(dp, max, 1); @@ -3485,41 +3255,19 @@ public TMono reduceMDono(TMono mm, Vector v, int dx) { if (BB_STOP) return null; } -// this.print(m); coefgcd(m); } } return m; } - public void reduceDono(TDono d, Vector v, int dx) { - for (int i = 1; i < dx; i++) { - if (!ctLdx(d.p2, i)) - continue; - - int n = i; - - TDono d1 = getDo(v, n); - if (d1 != null) { - TMono m = d.p2; - TMono m2 = this.padd(pp_times(p_copy(d1.p1), p_copy(d1.p2)), p_copy(d1.c)); - TMono mx = bb_divn(m, m2); - if (mx == null) { - m = pp_times(m, p_copy(d1.p2)); - mx = bb_divn(m, m2); - } - - - while (mx != null && mx.x != 0) { - BigInteger b2 = getLN(m2); - m = pdif(cp_times(b2, m), pp_times(mx, p_copy(m2))); - mx = bb_divn(m, m2); - } - d.p2 = m; - } - } - } - + /** + * Gets the Dono object from the given vector of polynomials. + * + * @param v the vector of polynomials + * @param n the value to compare with + * @return the Dono object, or null if not found + */ public TDono getDo(Vector v, int n) { TDono xd = null; int nn = -1; @@ -3544,87 +3292,13 @@ public TDono getDo(Vector v, int n) { return xd; } - - public void d_reduce(TDono d1, Vector vlist) { - if (d1 == null) return; - - TMono m1 = d1.p2; - BigInteger bb = BigInteger.ONE; - - - while (true) { - boolean r = true; - for (int i = 0; i < vlist.size(); i++) { - TMono m2 = (TMono) vlist.get(i); - TMono m = bb_divnh(m1, m2); - while (m != null) { - BigInteger b2 = getLN(m2); - bb.multiply(b2); - m1 = pdif(cp_times(b2, m1), pp_times(m, p_copy(m2))); - if (m1 == null) break; - r = false; - m = bb_divn(m1, m2); - } - } - if (r) break; - } -// d1.p1 = cp_times(bb, d1.p1); - d1.c = cp_times(bb, d1.c); - d1.p2 = m1; - } - - - public void splitDonos(Vector vnn, Vector vnds, int dx) { - Vector vtemp = new Vector(); - - while (true) { - while (vnds.size() != 0) { - TMono tx = getMaxDMono(vnds, dx); -// this.dprint(tx, 9); - - int max = MaxLdx(tx, dx); - int min = MinLdx(tx, dx); - vnds.remove(tx); - - - if (max != min) { - tx = reduceMDono(tx, vnn, dx); - max = MaxLdx(tx, dx); - } - - if (max == min) { - TDono d = splitDono(tx, dx); - if (d != null) - vnn.add(d); - } else { - vtemp.add(tx); - } - } - if (vtemp.size() == 0) - break; - else { - vnds.addAll(vtemp); - vtemp.clear(); - } - } - - } - - public TMono getMaxDMono(Vector vnds, int dx) { - int k = 0; - TMono tx = null; - - for (int i = 0; i < vnds.size(); i++) { - TMono m = (TMono) vnds.get(i); - int x = this.MaxLdx(m, dx); - if (x > k) { - k = x; - tx = m; - } - } - return tx; - } - + /** + * Splits the given monomial into a Dono object. + * + * @param m the monomial + * @param dx the value to add + * @return the Dono object + */ public TDono splitDono(TMono m, int dx) { TMono m1 = m; TMono c = null; @@ -3643,8 +3317,6 @@ public TDono splitDono(TMono m, int dx) { TMono mx = this.pp_minus(p_copy(m), p_copy(c)); - int minX = this.MinLdx(mx, dx); - TMono mo = pth(0, 1, 0); TMono mf = get_factor1(mx); while (mf != null && mf.x != 0) { @@ -3662,33 +3334,5 @@ public TDono splitDono(TMono m, int dx) { return new TDono(mo, mx, c); } - - public void reduceMdo(Vector vrs, int dx) { - for (int i = 0; i < vrs.size(); i++) { - TMono m = (TMono) vrs.get(i); - int max = this.MaxLdx(m, dx); - int min = this.MinLdx(m, dx); - if (max == min) - continue; - - - } - - } - - - public TMono getMono(TDono d) { - TMono m = padd(pp_times(p_copy(d.p1), p_copy(d.p2)), p_copy(d.c)); - coefgcd(m); - if (m == null) - return m; - - if (this.getLN(m).intValue() < 0) { - m = cp_times(-1, m); - return m; - } - return m; - } - } diff --git a/src/main/java/maths/TDono.java b/src/main/java/maths/TDono.java index a5187d16..236265f9 100644 --- a/src/main/java/maths/TDono.java +++ b/src/main/java/maths/TDono.java @@ -1,17 +1,23 @@ package maths; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-7 - * Time: 9:59:11 - * To change this template use File | Settings | File Templates. + * Represents a Dono object which contains three polynomials. + * + *
This class is used to store and manipulate polynomials in the context of + * polynomial operations. Each Dono object consists of three polynomials: p1, p2, and c.
*/ public class TDono { public TMono p1; public TMono p2; public TMono c; + /** + * Constructs a new TDono object with the specified polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param c the third polynomial + */ public TDono(TMono p1, TMono p2, TMono c) { this.p1 = p1; this.p2 = p2; diff --git a/src/main/java/maths/TMono.java b/src/main/java/maths/TMono.java index 2e6a3f8f..9b68e9e1 100644 --- a/src/main/java/maths/TMono.java +++ b/src/main/java/maths/TMono.java @@ -2,6 +2,9 @@ import java.math.BigInteger; +/** + * Represents a monomial in a polynomial. + */ public class TMono { public int x = 0; public int deg = 0; @@ -9,10 +12,17 @@ public class TMono { public TMono coef = null; public TMono next = null; + /** + * Default constructor. + */ public TMono() { - } + /** + * Returns the value of the monomial. + * + * @return the value of the monomial as a long + */ public long value() { if (val != null) return val.longValue(); @@ -23,6 +33,13 @@ public long value() { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, BigInteger val, int deg) { this.x = x; this.deg = deg; @@ -39,6 +56,13 @@ public TMono(int x, BigInteger val, int deg) { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, int val, int deg) { this.x = x; this.deg = deg; @@ -49,9 +73,15 @@ public TMono(int x, int val, int deg) { } else { this.coef = new TMono(0, val, 0); } - } + /** + * Constructs a monomial with the specified variable, coefficient, and degree. + * + * @param x the variable + * @param coef the coefficient + * @param deg the degree + */ public TMono(int x, TMono coef, int deg) { this.x = x; this.deg = deg; diff --git a/src/main/java/maths/TPoly.java b/src/main/java/maths/TPoly.java index aa449016..2e36a8bd 100644 --- a/src/main/java/maths/TPoly.java +++ b/src/main/java/maths/TPoly.java @@ -1,29 +1,62 @@ package maths; +/** + * Represents a polynomial linked list. + * + *This class is used to store and manipulate polynomials in a linked list structure. + * Each node in the list contains a polynomial (TMono) and a reference to the next node.
+ */ public class TPoly { public TMono poly; public TPoly next; + /** + * Default constructor. + */ public TPoly() { } + /** + * Returns the next node in the list. + * + * @return the next node + */ public TPoly getNext() { return next; } + /** + * Returns the polynomial of the current node. + * + * @return the polynomial + */ public TMono getPoly() { return poly; } + /** + * Sets the next node in the list. + * + * @param next the next node + */ public void setNext(TPoly next) { this.next = next; } + /** + * Sets the polynomial of the current node. + * + * @param poly the polynomial + */ public void setPoly(TMono poly) { this.poly = poly; } - + /** + * Returns the length of the polynomial linked list. + * + * @return the length of the list + */ public int length() { TPoly tp = this; int i = 0; @@ -33,31 +66,5 @@ public int length() { i++; } return i; - - } - - public long callength() { - TPoly p = this; - long len = 0; - while (p != null) { - long l = p.plength(p.getPoly()) + 1; - len = len + l; - p = p.getNext(); - } - return len; } - - private long plength(TMono p) { - TMono pt; - int i; - - pt = p; - i = -1; - while (pt != null) { - i = i + 1; - pt = pt.next; - } - return i; - } - } From 3aaa3020b61aa8c08ff1cbdf421b2040d9e428f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Kov=C3=A1cs?=This class is used to store and manipulate polynomials in the context of + * polynomial operations. Each Dono object consists of three polynomials: p1, p2, and c.
*/ public class TDono { public TMono p1; public TMono p2; public TMono c; + /** + * Constructs a new TDono object with the specified polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param c the third polynomial + */ public TDono(TMono p1, TMono p2, TMono c) { this.p1 = p1; this.p2 = p2; diff --git a/src/main/java/maths/TMono.java b/src/main/java/maths/TMono.java index 2e6a3f8f..9b68e9e1 100644 --- a/src/main/java/maths/TMono.java +++ b/src/main/java/maths/TMono.java @@ -2,6 +2,9 @@ import java.math.BigInteger; +/** + * Represents a monomial in a polynomial. + */ public class TMono { public int x = 0; public int deg = 0; @@ -9,10 +12,17 @@ public class TMono { public TMono coef = null; public TMono next = null; + /** + * Default constructor. + */ public TMono() { - } + /** + * Returns the value of the monomial. + * + * @return the value of the monomial as a long + */ public long value() { if (val != null) return val.longValue(); @@ -23,6 +33,13 @@ public long value() { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, BigInteger val, int deg) { this.x = x; this.deg = deg; @@ -39,6 +56,13 @@ public TMono(int x, BigInteger val, int deg) { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, int val, int deg) { this.x = x; this.deg = deg; @@ -49,9 +73,15 @@ public TMono(int x, int val, int deg) { } else { this.coef = new TMono(0, val, 0); } - } + /** + * Constructs a monomial with the specified variable, coefficient, and degree. + * + * @param x the variable + * @param coef the coefficient + * @param deg the degree + */ public TMono(int x, TMono coef, int deg) { this.x = x; this.deg = deg; diff --git a/src/main/java/maths/TPoly.java b/src/main/java/maths/TPoly.java index aa449016..2e36a8bd 100644 --- a/src/main/java/maths/TPoly.java +++ b/src/main/java/maths/TPoly.java @@ -1,29 +1,62 @@ package maths; +/** + * Represents a polynomial linked list. + * + *This class is used to store and manipulate polynomials in a linked list structure. + * Each node in the list contains a polynomial (TMono) and a reference to the next node.
+ */ public class TPoly { public TMono poly; public TPoly next; + /** + * Default constructor. + */ public TPoly() { } + /** + * Returns the next node in the list. + * + * @return the next node + */ public TPoly getNext() { return next; } + /** + * Returns the polynomial of the current node. + * + * @return the polynomial + */ public TMono getPoly() { return poly; } + /** + * Sets the next node in the list. + * + * @param next the next node + */ public void setNext(TPoly next) { this.next = next; } + /** + * Sets the polynomial of the current node. + * + * @param poly the polynomial + */ public void setPoly(TMono poly) { this.poly = poly; } - + /** + * Returns the length of the polynomial linked list. + * + * @return the length of the list + */ public int length() { TPoly tp = this; int i = 0; @@ -33,31 +66,5 @@ public int length() { i++; } return i; - - } - - public long callength() { - TPoly p = this; - long len = 0; - while (p != null) { - long l = p.plength(p.getPoly()) + 1; - len = len + l; - p = p.getNext(); - } - return len; } - - private long plength(TMono p) { - TMono pt; - int i; - - pt = p; - i = -1; - while (pt != null) { - i = i + 1; - pt = pt.next; - } - return i; - } - } From d36809024dbbd7aa5224ad65f876dfb1b23c4db6 Mon Sep 17 00:00:00 2001 From: Philip Hallwirth <37780428+Traumlos@users.noreply.github.com> Date: Mon, 24 Mar 2025 01:02:33 +0100 Subject: [PATCH 03/10] superficial refactor and added java doc to gprover folder --- src/main/java/gprover/ACir.java | 15 +- src/main/java/gprover/AngSt.java | 56 +- src/main/java/gprover/AngTn.java | 89 +- src/main/java/gprover/AngTr.java | 89 +- src/main/java/gprover/AngleT.java | 143 +- src/main/java/gprover/Angles.java | 38 +- src/main/java/gprover/Area.java | 1585 ++------------ src/main/java/gprover/AuxPt.java | 57 +- src/main/java/gprover/CClass.java | 44 +- src/main/java/gprover/CNdg.java | 80 +- src/main/java/gprover/CST.java | 379 ++-- src/main/java/gprover/CSegs.java | 46 +- src/main/java/gprover/Cm.java | 222 +- src/main/java/gprover/Cond.java | 200 +- src/main/java/gprover/CongSeg.java | 28 +- src/main/java/gprover/Cons.java | 205 +- src/main/java/gprover/DTerm.java | 52 +- src/main/java/gprover/ElTerm.java | 139 +- src/main/java/gprover/Elim.java | 3009 ++------------------------- src/main/java/gprover/Full.java | 1990 ++++++++++++------ src/main/java/gprover/GDD.java | 921 ++++++-- src/main/java/gprover/GDDAux.java | 652 +++++- src/main/java/gprover/GDDBase.java | 2581 ++++++++++++++++------- src/main/java/gprover/GDDBc.java | 1053 +++++++--- src/main/java/gprover/GTerm.java | 559 ++++- src/main/java/gprover/Gib.java | 741 ++++++- src/main/java/gprover/Gr.java | 546 +---- src/main/java/gprover/GrTerm.java | 65 +- src/main/java/gprover/Incenter.java | 26 +- src/main/java/gprover/LLine.java | 41 +- src/main/java/gprover/LList.java | 86 +- src/main/java/gprover/Main.java | 166 +- src/main/java/gprover/Main2.java | 72 +- src/main/java/gprover/MathBase.java | 220 +- src/main/java/gprover/MidPt.java | 29 +- src/main/java/gprover/Mnde.java | 18 +- src/main/java/gprover/NdgCs.java | 135 +- src/main/java/gprover/PLine.java | 19 +- src/main/java/gprover/Poly.java | 892 ++++---- src/main/java/gprover/Polygon.java | 15 +- src/main/java/gprover/ProPoint.java | 52 +- src/main/java/gprover/Prover.java | 173 +- src/main/java/gprover/RatioSeg.java | 24 +- src/main/java/gprover/Rule.java | 49 +- src/main/java/gprover/Rules.java | 6 + src/main/java/gprover/STris.java | 10 +- src/main/java/gprover/SimTri.java | 16 +- src/main/java/gprover/TLine.java | 19 +- src/main/java/gprover/Var.java | 52 +- src/main/java/gprover/Wu.java | 895 -------- src/main/java/gprover/XTerm.java | 34 +- 51 files changed, 9173 insertions(+), 9460 deletions(-) delete mode 100644 src/main/java/gprover/Wu.java diff --git a/src/main/java/gprover/ACir.java b/src/main/java/gprover/ACir.java index 2062a0ae..521000c9 100644 --- a/src/main/java/gprover/ACir.java +++ b/src/main/java/gprover/ACir.java @@ -1,12 +1,8 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:34:08 - * To change this template use File | Settings | File Templates. - */ -package gprover; + * Represents a geometric circle with various properties and methods. + */ public class ACir extends CClass { int lemma; @@ -16,8 +12,11 @@ public class ACir extends CClass public int []pt; public int []d; public ACir nx; -// private int type; + /** + * Default constructor for ACir. + * Initializes the properties of the circle. + */ public ACir() { type = lemma =0; diff --git a/src/main/java/gprover/AngSt.java b/src/main/java/gprover/AngSt.java index a6af10df..b8c7f831 100644 --- a/src/main/java/gprover/AngSt.java +++ b/src/main/java/gprover/AngSt.java @@ -1,21 +1,32 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 11, 2006 - * Time: 10:32:50 AM - * To change this template use File | Settings | File Templates. + * The AngSt class represents a geometric configuration of angles. + * It extends the CClass and includes properties for lines, dependencies, + * and other attributes related to angles. */ public class AngSt extends CClass { + /** The number of angles. */ public int no; + + /** The first set of lines that define the angles. */ public LLine[] ln1; + + /** The second set of lines that define the angles. */ public LLine[] ln2; + + /** The dependencies associated with the angles. */ long[] dep; + + /** A string representation of the angles. */ public String sd; - public AngSt nx; + /** The next AngSt object in a linked list structure. */ + public AngSt nx; + /** + * Constructs an AngSt object with default values. + */ public AngSt() { type = 1; no = 0; @@ -24,6 +35,11 @@ public AngSt() { dep = new long[1000]; } + /** + * Constructs an AngSt object with the specified number of lines. + * + * @param n the number of lines + */ public AngSt(int n) { no = 0; ln1 = new LLine[n]; @@ -31,6 +47,13 @@ public AngSt(int n) { dep = new long[n]; } + /** + * Checks if the specified lines are contained in the angles. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are contained in the angles, false otherwise + */ public boolean contain(LLine l1, LLine l2) { for (int i = 0; i < no; i++) { if (ln1[i] == l1 && ln2[i] == l2 || ln1[i] == l2 && ln2[i] == l1) @@ -39,6 +62,13 @@ public boolean contain(LLine l1, LLine l2) { return false; } + /** + * Gets the direction of the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return 1 if the lines are in the same direction, -1 if they are in opposite directions, 0 otherwise + */ public int get_dr(LLine l1, LLine l2) { for (int i = 0; i < no; i++) { if (ln1[i] == l1 && ln2[i] == l2) @@ -49,6 +79,12 @@ public int get_dr(LLine l1, LLine l2) { return 0; } + /** + * Adds an angle to the angles. + * + * @param as the Angles object to add + * @return true if the angle was added, false otherwise + */ public boolean addAngle(Angles as) { boolean r1, r2; LLine l1 = as.l1; @@ -104,7 +140,13 @@ else if (ln1[i] == l4 && ln2[i] == l3) { return true; } + /** + * Returns a string representation of the angles. + * + * @return a string representation of the angles + */ + @Override public String toString() { return sd; } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/AngTn.java b/src/main/java/gprover/AngTn.java index d14ea5b3..c77bb671 100644 --- a/src/main/java/gprover/AngTn.java +++ b/src/main/java/gprover/AngTn.java @@ -1,32 +1,61 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 16, 2006 - * Time: 2:21:58 PM - * To change this template use File | Settings | File Templates. - */ -public class AngTn extends CClass { - int lemma; - public LLine ln1, ln2, ln3, ln4; - public int t1, t2; - Cond co; - AngTn nx; - - public AngTn(LLine l1, LLine l2, LLine l3, LLine l4) { - this(); - ln1 = l1; - ln2 = l2; - ln3 = l3; - ln4 = l4; - } - - public AngTn() { - ln1 = ln2 = ln3 = ln4 = null; - co = null; - nx = null; - t1 = t2 = lemma = 0; - - } -} + /** + * The AngTn class represents a geometric configuration of four lines. + * It extends the CClass and includes properties for lemma, condition, + * and other attributes related to angles. + */ + public class AngTn extends CClass { + /** The lemma associated with the angles. */ + int lemma; + + /** The first line that defines the angles. */ + public LLine ln1; + + /** The second line that defines the angles. */ + public LLine ln2; + + /** The third line that defines the angles. */ + public LLine ln3; + + /** The fourth line that defines the angles. */ + public LLine ln4; + + /** The first integer attribute related to the angles. */ + public int t1; + + /** The second integer attribute related to the angles. */ + public int t2; + + /** The condition associated with the angles. */ + Cond co; + + /** The next AngTn object in a linked list structure. */ + AngTn nx; + + /** + * Constructs an AngTn object with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ + public AngTn(LLine l1, LLine l2, LLine l3, LLine l4) { + this(); + ln1 = l1; + ln2 = l2; + ln3 = l3; + ln4 = l4; + } + + /** + * Constructs an AngTn object with default values. + */ + public AngTn() { + ln1 = ln2 = ln3 = ln4 = null; + co = null; + nx = null; + t1 = t2 = lemma = 0; + } + } \ No newline at end of file diff --git a/src/main/java/gprover/AngTr.java b/src/main/java/gprover/AngTr.java index 76cb20ef..7131dfb4 100644 --- a/src/main/java/gprover/AngTr.java +++ b/src/main/java/gprover/AngTr.java @@ -1,34 +1,59 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 17, 2006 - * Time: 11:06:48 AM - * To change this template use File | Settings | File Templates. - */ -public class AngTr extends CClass { - public int v, t1, t2; - public LLine l1; - public LLine l2; - Cond co; - AngTr nx; - - public AngTr() { - l1 = l2 = null; - co = null; - nx = null; - v = 0; - } - - - public int get_lpt1() { - if (t1 != 0) return t1; - return LLine.get_lpt1(l1, v); - } - - public int get_lpt2() { - if (t2 != 0) return t2; - return LLine.get_lpt1(l2, v); - } -} + /** + * The AngTr class represents a geometric configuration of two lines. + * It extends the CClass and includes properties for values, lines, + * and other attributes related to angles. + */ + public class AngTr extends CClass { + /** An integer value associated with the angle. */ + public int v; + + /** The first integer attribute related to the angle. */ + public int t1; + + /** The second integer attribute related to the angle. */ + public int t2; + + /** The first line that defines the angle. */ + public LLine l1; + + /** The second line that defines the angle. */ + public LLine l2; + + /** The condition associated with the angle. */ + Cond co; + + /** The next AngTr object in a linked list structure. */ + AngTr nx; + + /** + * Constructs an AngTr object with default values. + */ + public AngTr() { + l1 = l2 = null; + co = null; + nx = null; + v = 0; + } + + /** + * Gets the first point of the first line that is not equal to the value t1. + * + * @return the first point of the first line that is not equal to the value t1 + */ + public int get_lpt1() { + if (t1 != 0) return t1; + return LLine.get_lpt1(l1, v); + } + + /** + * Gets the first point of the second line that is not equal to the value t2. + * + * @return the first point of the second line that is not equal to the value t2 + */ + public int get_lpt2() { + if (t2 != 0) return t2; + return LLine.get_lpt1(l2, v); + } + } \ No newline at end of file diff --git a/src/main/java/gprover/AngleT.java b/src/main/java/gprover/AngleT.java index d97e6a72..0437753b 100644 --- a/src/main/java/gprover/AngleT.java +++ b/src/main/java/gprover/AngleT.java @@ -1,54 +1,93 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 4, 2006 - * Time: 1:57:36 PM - * To change this template use File | Settings | File Templates. - */ -public class AngleT extends CClass { // angle with intersection; - public int lemma; - public int p; - public LLine l1; - public LLine l2; - public int v; - Cond co; - AngleT nx; - - public AngleT() { - p = 0; - l1 = l2 = null; - v = 0; - nx = null; - } - - public AngleT(int p, LLine l1, LLine l2, int v) { - this(); - this.p = p; - this.l1 = l1; - this.l2 = l2; - this.v = v; - } - - - public int get_pt1() { - if (l1.pt[0] == p) - return l1.pt[1]; - else - return l1.pt[0]; - } - - public int get_pt2() { - if (l2.pt[0] == p) - return l2.pt[1]; - else - return l2.pt[0]; - } - - public int get_val(int p1, int p2) { - if (l1.on_ln(p1) && l2.on_ln(p2)) return v; - if (l1.on_ln(p2) && l2.on_ln(p1)) return -v; - return 9999; // shall never happen. - } -} + /** + * The AngleT class represents an angle with an intersection. + * It extends the CClass and includes properties for lemma, points, lines, + * and other attributes related to the angle. + */ + public class AngleT extends CClass { // angle with intersection; + + /** The lemma associated with the angle. */ + public int lemma; + + /** The point associated with the angle. */ + public int p; + + /** The first line that defines the angle. */ + public LLine l1; + + /** The second line that defines the angle. */ + public LLine l2; + + /** An integer value associated with the angle. */ + public int v; + + /** The condition associated with the angle. */ + Cond co; + + /** The next AngleT object in a linked list structure. */ + AngleT nx; + + /** + * Constructs an AngleT object with default values. + */ + public AngleT() { + p = 0; + l1 = l2 = null; + v = 0; + nx = null; + } + + /** + * Constructs an AngleT object with the specified values. + * + * @param p the point associated with the angle + * @param l1 the first line that defines the angle + * @param l2 the second line that defines the angle + * @param v an integer value associated with the angle + */ + public AngleT(int p, LLine l1, LLine l2, int v) { + this(); + this.p = p; + this.l1 = l1; + this.l2 = l2; + this.v = v; + } + + /** + * Gets the first point of the first line that is not equal to the point p. + * + * @return the first point of the first line that is not equal to the point p + */ + public int get_pt1() { + if (l1.pt[0] == p) + return l1.pt[1]; + else + return l1.pt[0]; + } + + /** + * Gets the first point of the second line that is not equal to the point p. + * + * @return the first point of the second line that is not equal to the point p + */ + public int get_pt2() { + if (l2.pt[0] == p) + return l2.pt[1]; + else + return l2.pt[0]; + } + + /** + * Gets the value associated with the angle based on the points p1 and p2. + * + * @param p1 the first point + * @param p2 the second point + * @return the value associated with the angle, or 9999 if the points do not lie on the lines + */ + public int get_val(int p1, int p2) { + if (l1.on_ln(p1) && l2.on_ln(p2)) return v; + if (l1.on_ln(p2) && l2.on_ln(p1)) return -v; + return 9999; // shall never happen. + } + } \ No newline at end of file diff --git a/src/main/java/gprover/Angles.java b/src/main/java/gprover/Angles.java index 4d0a6b36..ce8889ff 100644 --- a/src/main/java/gprover/Angles.java +++ b/src/main/java/gprover/Angles.java @@ -1,23 +1,38 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:34:29 - * To change this template use File | Settings | File Templates. + * The Angles class represents a geometric configuration of four lines. + * It extends the CClass and includes properties for lemma, condition, + * and other attributes related to angles. */ -package gprover; - public class Angles extends CClass { - // int type; + /** The lemma associated with the angles. */ int lemma; + + /** The condition associated with the angles. */ Cond co; + + /** An integer attribute related to the angles. */ int sa; - public LLine l1,l2, l3, l4; + + /** The four lines that define the angles. */ + public LLine l1, l2, l3, l4; + + /** The next Angles object in a linked list structure. */ Angles nx; + + /** An integer attribute with a default value of 0. */ int atp = 0; + /** + * Constructs an Angles object with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ public Angles(LLine l1, LLine l2, LLine l3, LLine l4) { this.l1 = l1; @@ -25,6 +40,10 @@ public Angles(LLine l1, LLine l2, LLine l3, LLine l4) this.l3 = l3; this.l4 = l4; } + + /** + * Constructs an Angles object with default values. + */ public Angles() { type = lemma = sa = 0; @@ -32,5 +51,4 @@ public Angles() nx = null; l1 = l2 = l3 = l4 = null; } - } diff --git a/src/main/java/gprover/Area.java b/src/main/java/gprover/Area.java index 748a7f2f..2ad76561 100644 --- a/src/main/java/gprover/Area.java +++ b/src/main/java/gprover/Area.java @@ -1,1330 +1,129 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-1 - * Time: 13:18:45 - * To change this template use File | Settings | File Templates. - */ -public class Area extends Full -{ - boolean elim_cir = false; - - int pts_pno; - void prove_area() - { - int fpt_no, ptn; - - max_term = 1; - elim_cir = false; - last_pr = proof = new GrTerm(); - proof.nx = null; - pts_pno = cons_no; - pconc(); - if (qerror) return; - ptn = pts_pno; - - - while (ptn >= 1 && !elim_cir) - { - if (end_pr()) - { - print_end(); - return; - } - if (elim_cir == false && ATYPE(ptn) == C_CIRCUM) - pe_gr(ptn); - else if (circle_p(ptn)) - { - elim_cir = true; - } else if (ATYPE(ptn) == C_CIRCLE) - { - elim_cir = true; - } else if (ATYPE(ptn) == C_POINT) - { - } else if (ATYPE(ptn) == -100) - { - } - else - pe_gr(ptn); - if (qerror) return; - ptn--; - } - - if (end_pr()) - { - print_end(); - return; - } - if (elim_cir == true) - { - int k1, k2; - GrTerm gr1 = last_pr; - pe_gr(-13); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-11); - if (end_pr()) - { - print_end(); - return; - } - if (gr1 != last_pr) - { - k1 = gr_length(gr1); - k2 = gr_length(last_pr); - if (k2 >= k1) - { - put_gr(last_pr); - last_pr = gr1; - } - } - pe_gr(-20); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-21); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-22); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-23); - elim_cir = false; - print_end(); - return; - } - if (vec_gr(last_pr)) - { - pe_gr(-30); - if (end_pr()) - { - print_end(); - return; - } - print_end(); - return; - } - fpt_no = 0; - while (ATYPE(fpt_no + 1) == C_POINT) fpt_no++; - if (fpt_no < 3) - { - print_end(); - return; - } - if (fpt_no == 3) - { - pe_gr(-10); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-11); - print_end(); - return; - } - if (area_gr(last_pr)) - { - for (ptn = fpt_no; ptn > 3; ptn--) - { - pe_gr(ptn); - } - print_end(); - return; - } - pe_gr(-12); - print_end(); - } - - boolean end_pr() - { - return ((last_pr.ps1 == null) && (last_pr.ps2 == null)); - } - - void print_end() - { - XTerm p1, p2; - if (last_pr.ps1 == null) - { - if ((last_pr.ps2 == null) && (last_pr.c1 == last_pr.c2)) print_t(); else print_f(); - return; - } - if (last_pr.ps2 == null) - { - if ((last_pr.ps1 == null) && (last_pr.c1 == last_pr.c2)) print_t(); else print_f(); - return; - } - p1 = ps_times(cp_pols(last_pr.ps1)); - p1 = ptimes(get_n(last_pr.c1), p1); - p2 = ps_times(cp_pols(last_pr.ps2)); - p2 = ptimes(get_n(last_pr.c2), p2); - if (eq_poly(p1, p2)) - { - put_p(p1); - conc_gr(1L, null, 1L, null); - last_pr.c = -1; - last_pr.ps = get_dt(1, p2, null); - if (last_pr.c1 == last_pr.c2) - { - print_t(); - return; - } else - { - print_f(); - return; - } - } - put_p(p1); - put_p(p2); - print_f(); - return; - } - - void print_t() - { - if (print_conc) - { //gprint("\r\n***************The results****** \r\n"); + /** + * The Area class represents a geometric area and extends the Full class. + * It includes methods for printing results, creating geometric terms, + * and evaluating geometric expressions. + */ + public class Area extends Full { + + /** + * Prints the results if the print_conc flag is set. + */ + void print_t() { + if (print_conc) { + // gprint("\r\n***************The results****** \r\n"); gprint(Cm.s2300); - } - //pro_result = 1; - } - - void print_f() - { - if (print_conc) - { //gprint("\n The results \n"); - gprint(Cm.s2301); - } - - gprint("(" + last_pr.c1 + ")"); - print_ps(last_pr.ps1, (char) 0); - gprint(" = "); - gprint("(" + last_pr.c2 + ")"); - print_ps(last_pr.ps2, (char) 0); - gprint("\r\n"); - //pro_result = -1; - } - - boolean area_gr(GrTerm gr) - { - DTerm ps; - ps = gr.ps1; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - ps = gr.ps2; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - return (true); - } - - boolean area_p(XTerm p) - { - DTerm ps; - Var v; - if (p.var == null) return (true); - v = p.var; - if (v.nm == 2 || v.nm < 0) - { - ps = p.ps; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - return (true); - } else - return (false); - } - - boolean vec_gr(GrTerm gr) - { - DTerm ps; - ps = gr.ps1; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - ps = gr.ps2; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } - - boolean vec_p(XTerm p) -//xterm p; - { - DTerm ps; - Var v; - if (p.var == null) return (false); - v = p.var; - if (v.nm != 4) - { - ps = p.ps; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } else - return (true); - } - - boolean str_p(XTerm p) - { - DTerm ps; - Var v; - if (p.var == null) return (false); - v = p.var; - if (v.nm != 0) - { - ps = p.ps; - while (ps != null) if (str_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } else - return (true); - } - - -/* conclusions */ - void conc_gr(long c1, XTerm p1, long c2, XTerm p2) - { - GrTerm gr = mk_gr1(mk_num(c1), p1, mk_num(c2), p2); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; - } - - void pconc() - { - switch (conc.pred) - { - case CO_COLL: /* collinear */ - conc_coll(); - break; - case CO_PARA: /* parallel */ - conc_gr(1L, trim_a(conc.p[0], conc.p[2], conc.p[3], conc.p[3]), - 1L, trim_a(conc.p[1], conc.p[2], conc.p[3], conc.p[3])); - break; - case CO_PERP: /* perpendicular */ - conc_gr(1L, trim_g(conc.p[0], conc.p[2], conc.p[2], conc.p[3]), - 1L, trim_g(conc.p[1], conc.p[2], conc.p[2], conc.p[3])); - break; - case CO_CONG: /* eqdistance */ - conc_gr(1L, trim_g(conc.p[0], conc.p[0], conc.p[1], conc.p[1]), - 1L, trim_g(conc.p[2], conc.p[2], conc.p[3], conc.p[3])); - break; - case CO_ACONG: /* eqangle */ - conc_gr(1L, ptimes(trim_a(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - trim_g(conc.p[4], conc.p[5], conc.p[6], conc.p[7])), - 1L, ptimes(trim_g(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - trim_a(conc.p[4], conc.p[5], conc.p[6], conc.p[7]))); - break; - case CO_MIDP: /*midpoint */ - conc_gr(1L, trim_r(conc.p[0], conc.p[1], conc.p[0], conc.p[2]), -1L, null); - break; - case CO_PROD: /*eq-product */ - conc_eqproduct(); - break; - case CO_CYCLIC: /*cocircle */ - conc_gr(1L, ptimes(trim_a(conc.p[3], conc.p[1], conc.p[1], conc.p[4]), - trim_g(conc.p[3], conc.p[2], conc.p[2], conc.p[4])), - 1L, ptimes(trim_g(conc.p[3], conc.p[1], conc.p[1], conc.p[4]), - trim_a(conc.p[3], conc.p[2], conc.p[2], conc.p[4]))); - break; - case -9: /*on_radical */ - conc_gr(1L, pminus(trim_g(conc.p[0], conc.p[1], conc.p[1], conc.p[0]), - trim_g(conc.p[1], conc.p[2], conc.p[2], conc.p[1])), - 1L, pminus(trim_g(conc.p[0], conc.p[3], conc.p[3], conc.p[0]), - trim_g(conc.p[3], conc.p[4], conc.p[4], conc.p[3]))); - break; - case CO_TANGENT: /*tangent */ - pconc_11(conc.p[0], conc.p[1], conc.p[2], conc.p[3]); - break; - case -12: /* perp-b */ - conc_gr(1L, trim_g(conc.p[0], conc.p[0], conc.p[1], conc.p[1]), - 1L, trim_g(conc.p[0], conc.p[0], conc.p[2], conc.p[2])); - break; - case CO_HARMONIC: /* harmonic */ - conc_gr(1L, trim_r(conc.p[2], conc.p[0], conc.p[2], conc.p[1]), - -1L, trim_r(conc.p[3], conc.p[0], conc.p[3], conc.p[1])); - break; - case -16: /* inversion */ - if (xcoll4(conc.p[1], conc.p[2], conc.p[3], conc.p[0])) - conc_gr(1L, trim_r(conc.p[0], conc.p[2], conc.p[0], conc.p[1]), - 1L, trim_r(conc.p[0], conc.p[1], conc.p[0], conc.p[3])); - else - conc_gr(1L, trim_g(conc.p[0], conc.p[1], conc.p[1], conc.p[0]), - 1L, trim_g(conc.p[2], conc.p[0], conc.p[0], conc.p[3])); - break; - case CO_PETRI: /*-18 pe-traingle */ - conc_gr(1L, pplus3(trim_vec(conc.p[0], 0), - ptimes(get_s("w".toCharArray()), trim_vec(conc.p[1], 0)), - ptimes3(get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(conc.p[2], 0))), - 0L, null); - break; - -/* case CO_STRI: - conc_gr(1L,ptimes(trim_a(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_g(conc.p[4],conc.p[5],conc.p[6],conc.p[7])), - 1L,ptimes(trim_g(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_a(conc.p[4],conc.p[5],conc.p[6],conc.p[7]))); - break; - case CO_CTRI: - conc_gr(1L,ptimes(trim_a(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_g(conc.p[4],conc.p[5],conc.p[6],conc.p[7])), - 1L,ptimes(trim_g(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_a(conc.p[4],conc.p[5],conc.p[6],conc.p[7]))); - break; -*/ - case -21: /* eq-ratio */ - conc_gr(1L, trim_r(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - 1L, trim_r(conc.p[4], conc.p[5], conc.p[6], conc.p[7])); - break; - case CO_EQ: /* constants8 */ - if (npoly(conc_p1) && npoly(conc_p2)) - conc_gr(num_int(conc_p1.c), null, num_int(conc_p2.c), null); - if (npoly(conc_p1)) - conc_gr(num_int(conc_p1.c), null, 1L, conc_p2); - else if (npoly(conc_p2)) - conc_gr(1L, conc_p1, num_int(conc_p2.c), null); - else - conc_gr(1L, conc_p1, 1L, conc_p2); - break; - - default: - { - gerror(Cm.s2302 + conc.pred); - } - } - if (print_geo) - { - gprint("pconc:\r\n"); - print_gr(last_pr, (char) 0); - } - } - - - static int f_pt1, f_pt2; - - void fd_mpts(int pt) - { - int i, m; - LLine ln1 = null; - - m = 100; - LLine ln = all_ln.nx; - while (ln != null) - { - if (on_ln(pt, ln) && ln.no > 1) - { - for (i = 0; i <= ln.no; i++) - if (ln.pt[i] != pt && ln.pt[i] < m) - { - ln1 = ln; - m = ln.pt[i]; - } - } - ln = ln.nx; - } - f_pt1 = m; - m = 100; - for (i = 0; i <= ln1.no; i++) - if (ln1.pt[i] != pt && ln1.pt[i] != f_pt1 && ln1.pt[i] < m) m = ln1.pt[i]; - f_pt2 = m; - } - - void conc_coll() - { - int p, p1, p2, p3; - LLine ln; - p1 = conc.p[0]; - p2 = conc.p[1]; - p3 = conc.p[2]; - if (p1 > p2) - { - p = p1; - p1 = p2; - p2 = p; - } - if (p1 > p3) - { - p = p1; - p1 = p3; - p3 = p; - } - if (p2 > p3) - { - p = p2; - p2 = p3; - p3 = p; - } - - ln = fd_ln1(p3); - if (ln == null) - { - ln = fd_ln1(p2); - if (ln != null) - { - p = p2; - p2 = p3; - p3 = p; - ; - } else - { - ln = fd_ln1(p1); - if (ln != null) - { - p = p1; - p1 = p3; - p3 = p; - ; - } else - { - conc_gr(1L, trim_a(p1, p2, p3, p3), 0L, null); - return; - } - } - } - //l1: - fd_mpts(p3); - gprint("conc_coll: " + p1 + " " + p2 + " " + p3 + " " + f_pt1 + " " + f_pt2); - pts_pno++; - String s1 = ("I_{" + ANAME(p3) + "}"); - allpts[pts_pno] = new ProPoint(C_I_LL,s1,f_pt1,f_pt2,p1,p2,0,0,0,0); -// allpts[pts_pno].name = s1; -// allpts[pts_pno].type = C_I_LL; -// allpts[pts_pno].ps[0] = f_pt1; -// allpts[pts_pno].ps[1] = f_pt2; -// allpts[pts_pno].ps[2] = p1; -// allpts[pts_pno].ps[3] = p2; - add_line(0, pts_pno, APTS(pts_pno, 0), APTS(pts_pno, 1)); - add_line(0, pts_pno, APTS(pts_pno, 2), APTS(pts_pno, 3)); - conc_gr(1L, trim_r(f_pt1, p3, f_pt2, p3), 1L, trim_r(f_pt1, pts_pno, f_pt2, pts_pno)); - - - gprint("\r\n***************************************\r\n"); - gprint(Cm.s2303 + " " + ANAME(pts_pno) + " " + Cm.s2304); - // do_cons(6, pts_pno); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - gprint("\r\n\r\n"); - gprint(Cm.s2305); - gprint(ANAME(f_pt1) + " " + ANAME(p3) + " " + ANAME(f_pt2) + " " + ANAME(p3) + - ANAME(f_pt1) + " " + ANAME(pts_pno) + " " + ANAME(f_pt2) + " " + ANAME(pts_pno) + "\n" + - "\r\n\r\n"); - - } - - void conc_eqproduct() - { - int p1, p2, p3, p4, p5, p6, p7, p8; - p1 = conc.p[0]; - p2 = conc.p[1]; - p3 = conc.p[6]; - p4 = conc.p[7]; - p5 = conc.p[2]; - p6 = conc.p[3]; - p7 = conc.p[4]; - p8 = conc.p[5]; - if (xpara(p1, p2, p5, p6) && xpara(p3, p4, p7, p8)) - conc_gr(1L, trim_r(p1, p2, p5, p6), 1L, trim_r(p7, p8, p3, p4)); - else if (xpara(p1, p2, p7, p8) && xpara(p3, p4, p5, p6)) - conc_gr(1L, trim_r(p1, p2, p7, p8), 1L, trim_r(p5, p6, p3, p4)); - else if (xpara(p1, p2, p3, p4) && xpara(p5, p6, p7, p8)) - conc_gr(1L, trim_g(p1, p3, p2, p4), 1L, trim_g(p5, p7, p6, p8)); - else if (xcoll4(p1, p2, p3, p4)) - conc_gr(1L, ptimes(trim_g(p1, p3, p2, p4), trim_g(p1, p3, p2, p4)), - 1L, ptimes(trim_g(p5, p6, p6, p5), trim_g(p7, p8, p8, p7))); - else - conc_gr(1L, ptimes(trim_g(p1, p2, p2, p1), trim_g(p3, p4, p4, p3)), - 1L, ptimes(trim_g(p5, p6, p6, p5), trim_g(p7, p8, p8, p7))); - } - -/* -void pconc_11(p0,p1,p2,p3) -int p0,p1,p2,p3; -{ gr_term *gr; - xterm *po1,*po2,*po3; - dterm *ps1, *ps2; - po1=pminus(trim_g(p2,p3,p3,p2),trim_g(p0,p2,p2,p0)); - po2=trim_g(p0,p1,p1,p0); - po3=pplus3(ptimes(get_n(2L),trim_g(p0,p2,p2,p0)), - ptimes(get_n(2L),trim_g(p2,p3,p3,p2)), - ptimes(get_n(-1L),trim_g(p0,p1,p1,p0))); - ps1 = get_dt(2,po1,null); - ps2 = get_dt(1,po2,null); - ps2 = get_dt(1,po3,ps2); - - gr = mk_gr(mk_num(1L),ps1,mk_num(1L),ps2,0,null); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; -} */ - - void pconc_11(int p0, int p1, int p2, int p3) - { - GrTerm gr; - XTerm po1, po2, po3; - DTerm ps1, ps2; - po1 = pminus(pplus(trim_g(p0, p1, p1, p0), trim_g(p2, p3, p3, p2)), - trim_g(p0, p2, p2, p0)); - po2 = trim_g(p0, p1, p1, p0); - po3 = trim_g(p2, p3, p3, p2); - ps1 = get_dt(2, po1, null); - ps2 = get_dt(1, po2, null); - ps2 = get_dt(1, po3, ps2); - - gr = mk_gr(mk_num(1L), ps1, mk_num(4L), ps2, 0, null); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; - } - - - -/* eliminations */ - - ElTerm all_elim = new ElTerm(); - DTerm ds_set = new DTerm(); - DTerm last_ds; - - ElTerm mk_elim(Var v, XTerm p1, XTerm p2) - { - ElTerm v1 = new ElTerm();//(el_term )calloc(1,sizeof(el_term)); - v1.v = v; - v1.p1 = p1; - v1.p2 = p2; - v1.nx = all_elim.nx; - all_elim.nx = v1; - return (v1); - } - - - void pe_gr(int ptn) - { - GrTerm gr, gr0; - DTerm ps, ps1, ps2, qs1, qs2; - gr = last_pr; - - if (print_geo && ptn > 0) - { - gprint("\r\npe_gr: " + ptn + "(" + pt_name(ptn) + "\r\n"); - } - all_elim.nx = null; - ps1 = cp_pols(gr.ps1); - if (test_pt(ptn)) - { - ps1 = get_dt(1, ps_times(ps1), null); - } - ps = ps1; - ds_set.nx = null; - last_ds = ds_set; - while (ps != null) - { - ps.p = pe_p(ps.p, ptn, ps.deg); - ps = ps.nx; - if (qerror) - { - return; - } - } - qs1 = ds_set.nx; - if (qerror) return; - - ps2 = cp_pols(gr.ps2); - if (test_pt(ptn)) - { - ps2 = get_dt(1, ps_times(ps2), null); - } - ps = ps2; - ds_set.nx = null; - last_ds = ds_set; - while (ps != null) - { - ps.p = pe_p(ps.p, ptn, ps.deg); - ps = ps.nx; - if (qerror) - { - return; - } - } - qs2 = ds_set.nx; - - if (all_elim.nx != null) - { - gr0 = mk_gr(gr.c1, ps_append(ps1, qs2), - gr.c2, ps_append(ps2, qs1), ptn, null); - gr0.el = all_elim.nx; - last_pr.nx = gr0; - last_pr = gr0; - gr0 = simp_gr(gr0); - if (gr0 != null) - { - if (num_zop(gr0.c1) && num_zop(gr0.c2)) - { - last_pr = gr0; - } else - { - last_pr.nx = gr0; - last_pr = gr0; - } - last_pr.nx = null; - } - } - } - - boolean test_pt(int ptn) - { - if (ptn > 0) return (ATYPE(ptn) == -1); - return (ptn == -10 || ptn == -23); - } - - XTerm pe_p(XTerm p, int c, int d) - { - Var v1; - ElTerm el1; - XTerm p1; - -// if (print_geo) { wsprintf(txt,"\r\n\r\npe_p: (%d)",c); gprint(txt); } - - if (c < 0) return (pe_pv(p, c, d)); - if (ATYPE(c) == C_CONSTANT) return (pe_pv(p, c, d)); - - p1 = p; - l1: ///////////////////////??????????? - //if (c==5) { gprint("\r\npe_p:"); pprint(p1); } - while (true) - { - if (p1.var == null) - { - return (p1); - } - v1 = p1.var; - if (v1.nm <= 0) - { - return (p1); - } else if (lpt(v1) < c) - { - return (p1); - } else if (lpt(v1) == c) - { - if (elim_varp(v1, c)) - { - el1 = all_elim.nx; - while ((el1 != null) && (el1.v != v1)) el1 = el1.nx; - if (el1 == null) el1 = pe_v_c(v1, c); - if (qerror) - { - return (null); - } - if (el1 == null) - { - gerror(Cm.s2314); - return (null); - } - p1 = eprem(p1, el1); - if (init_deg > 0) - { - last_ds.nx = get_dt(d * init_deg, cp_poly(el1.p2), null); - last_ds = last_ds.nx; - } - if (max_termp) - { - int tem = plength(p1); - if (tem > max_term) max_term = tem; - } - //goto l1; - } else - return (p1); - } else - { - gerror("pe_p: ERRRRROR"); - } - } - // return (null); //???? - } - - boolean elim_varp(Var v, int pt) - { - if (ATYPE(pt) == 11) - { - if (v.nm == 3) - { - if (c_pt(v.pt[0], pt) && c_pt(v.pt[1], pt) && - c_pt(v.pt[2], pt) && c_pt(v.pt[3], pt)) - return (true); - else - return (false); - } else - return (false); - } - return (true); - } - - boolean c_pt(int pt, int c) - { - return ((pt == c) || (pt == APTS(c, 0)) || (pt == APTS(c, 1))); - } - - - XTerm eprem(XTerm p, ElTerm e) - { - XTerm p1, p2, p3; - if (e == null) return p; - p2 = get_n(1L); - if (e.p1 == null) - { - p1 = prem_var(p, e.p2, e.v); - p3 = init_v(cp_poly(e.p2), e.v); - if (eq_poly(p3, p2)) - { - init_deg = 0; - } - put_p(p3); - } else - { - p1 = get_m(e.v); - p1 = ptimes(p1, cp_poly(e.p2)); - p1 = pminus(p1, cp_poly(e.p1)); - p1 = prem_var(p, p1, e.v); - if (eq_poly(e.p2, p2)) - { - init_deg = 0; - } - } - put_x(p2); - return (p1); - } - - ElTerm pe_v_c(Var v, int ptn) - { - int etype = 0; - - int[] p = new int[9]; - ElTerm e1 = null; - int j; - for (j = 0; j <= 5; j++) p[j + 1] = APTS(ptn, j); - - switch (ATYPE(ptn)) - { - case C_POINT: /*free point*/ - e1 = pe_v_fpt(v, ptn); - break; - case C_MIDPOINT: /* midpoint */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_n(1L), get_n(2L)); - break; - case C_SYM: /* sym */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_n(1L), get_n(1L)); - break; - case C_LRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - case 100://C_MRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], cp_poly(P1(ptn)), - c_pplus(P1(ptn), P2(ptn))); - break; - case C_PRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[2], p[3], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - case 71: /* tratio */ - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - - case C_O_L: /* on-line */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_m(mk_var(-1, p[1], ptn, p[1], p[2])), get_n(1L)); - break; - case C_O_T: /*on-tline*/ - String s = ("t_{" + ANAME(ptn) + "}"); - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], get_s(s.toCharArray()), get_n(1L)); - break; - case C_O_P: /* on-pline */ - e1 = pe_v_pratio(v, ptn, p[1], p[2], p[3], get_m(mk_var(-1, p[1], ptn, p[3], p[4])), get_n(1L)); - break; -// case C_O_C: /* on-circle */ -// break; - case C_O_A: /* on-aline */ - e1 = pe_v_tratio(v, ptn, p[2], p[2], p[1], - ptimes(get_n(-4L), trim_a(p[3], p[4], p[4], p[5])), - trim_g(p[3], p[4], p[4], p[5])); - break; - case C_I_LL: /* intersection-ll */ - e1 = pe_v_ipp(v, ptn, p[1], p[1], p[2], p[3], p[3], p[4]); -/* - switch(v.nm) - { case 1: - e1 = pe_r_ill(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4]); - break; - case 2: - e1 = pe_a_ill(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4]); - break; - case 3: - e1 = pe_g_ill(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4]); - break; - case 4: - e1 = pe_vec_ill(v,v.pt[0],v.pt[1],ptn,p[1],p[2],p[3],p[4]); - break; - } -*/ - break; - case C_FOOT: /* foot */ - e1 = pe_v_ipt(v, ptn, p[2], p[2], p[3], p[1], p[2], p[3]); -/* switch(v.nm) - { case 1: - e1 = pe_r_foot(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3]); - break; - case 2: - e1 = pe_a_foot(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3]); - break; - case 3: - e1 = pe_g_foot(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3]); - break; - } -*/ - break; - case C_I_TT: /* intersection-tt */ - switch (v.nm) - { - case 1: - /* e1 = pe_r_itt(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4],p[5],p[6]); */ - //sprintf(txt, "%s %s %s", ANAME(ptn), PDSTR(2307), PDSTR(2308)); - gerror(ANAME(ptn) + Cm.s2307 + " " + Cm.s2308); - e1 = null; - break; - case 2: - e1 = pe_a_itt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - case 3: - e1 = pe_g_itt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - default: - gerror("pe_v_c: itt"); - } - break; - case C_I_LT: /* intersection-lt */ - e1 = pe_v_ipt(v, ptn, p[1], p[1], p[2], p[3], p[4], p[5]); - break; - case C_I_LP: /* intersection-lp */ - e1 = pe_v_ipp(v, ptn, p[1], p[1], p[2], p[3], p[4], p[5]); -/* switch(v.nm) - { case 1: - e1 = pe_r_ilp(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - case 2: - e1 = pe_a_ilp(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - case 3: - e1 = pe_g_ilp(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - } -*/ - break; - case C_I_PP: /* intersection-pp */ - e1 = pe_v_ipp(v, ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - case C_I_PT: /* intersection-pt */ - e1 = pe_v_ipt(v, ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - -/* intersection of line and circle */ - case C_I_LC: /* intersection-lc */ - if (p[2] == p[4]) - e1 = pe_v_ipc(v, ptn, p[2], p[2], p[1], p[3], p[4]); - else if (p[1] == p[4]) - e1 = pe_v_ipc(v, ptn, p[1], p[1], p[2], p[3], p[4]); - //else goto err3; - else - etype = 3; - break; - case C_I_PC: /* intersection-pc */ - if (p[1] == p[5]) - e1 = pe_v_ipc(v, ptn, p[1], p[2], p[3], p[4], p[5]); - //else goto err3; - else - etype = 3; - break; - case C_I_CC: /* intersection-cc */ - if (p[2] != p[4]) - etype = 3; - else - e1 = pe_v_tratio(v, ptn, p[2], p[1], p[3], - ptimes(get_n(-8L), trim_a(p[2], p[1], p[3], p[3])), - trim_g(p[1], p[3], p[3], p[1])); - break; - case C_REF: /* reflection */ - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], - ptimes(get_n(-8L), trim_a(p[1], p[2], p[3], p[3])), - trim_g(p[2], p[3], p[3], p[2])); - break; - case C_CENT: /* CENTROID */ - e1 = pe_v_cent(v, ptn, p[1], p[2], p[3]); - break; - case C_ORTH: /* orthocenter */ - switch (v.nm) - { - case 1: -/* e1 = pe_r_orth(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3]); */ - //goto err3; - etype = 3; - break; - case 2: - e1 = pe_a_orth(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 3: - e1 = pe_g_orth(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 4: - e1 = orth_md(v, ptn, p[1], p[2], p[3]); - break; - } - break; - case C_CIRCUM: /* circumcenter */ - switch (v.nm) - { - case 1: - e1 = pe_r_circum(v, v.pt[1], v.pt[0], v.pt[3], v.pt[2], ptn, p[1], p[2], p[3]); - break; - case 2: - e1 = pe_a_circum(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 3: - e1 = pe_g_circum(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 4: - e1 = circum_md(v, ptn, p[1], p[2], p[3]); - break; - default: - gerror("pe_v_c111"); - } - break; - case C_ICENT1: /* incenter */ - gerror(ANAME(ptn) + " " + Cm.s2311 + " " + Cm.s2312); - e1 = null; - return null; - - case C_ICENT: /* incenter */ - switch (v.nm) - { - case 1: - e1 = pe_r_incent(v, v.pt[1], v.pt[0], v.pt[3], v.pt[2], ptn, p[3], p[1], p[2]); - break; - case 2: - e1 = pe_a_incent(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[3], p[1], p[2]); - break; - case 3: - e1 = pe_g_incent(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[3], p[1], p[2]); - break; - case 4: - e1 = incent_md(v, ptn, p[3], p[1], p[2]); - break; - default: - gerror("pe_v_c111"); - } - break; - case C_INVERSION: /* inversion */ - if (xcoll(p[1], p[2], p[3])) - e1 = pe_v_pratio(v, ptn, p[2], p[2], p[3], trim_r(p[2], p[3], p[2], p[1]), get_n(1L)); - else - e1 = pe_v_pratio(v, ptn, p[2], p[2], p[1], - trim_g(p[2], p[3], p[3], p[2]), trim_g(p[2], p[1], p[1], p[2])); - break; - case C_PSQUARE: /* psquare */ - e1 = pe_v_square(v, ptn, p[1], p[2], 1); - break; - case C_NSQUARE: /* nsquare */ - e1 = pe_v_square(v, ptn, p[1], p[2], -1); - break; - case C_PETRIANGLE: /* pe-triangle */ - if (v.nm != 4) - { - gerror(Cm.s2313); - return null; - } - e1 = pe_v_ptri(v, ptn, p[1], p[2]); - break; - -// case C_NETRIANGLE: /* ne-triangle */ -// e1 = pe_v_ntri(v,ptn,p[1],p[2]); -// break; -/* - case -71: // harmonic - e1 = pe_v_pratio(v,ptn,p[2],p[2],p[3], - trim_r(p[2],p[1],p[3],p[1]), - pplus(trim_r(p[2],p[1],p[3],p[1]),get_n(1L))); - break; - case -76: // ps-triangle similar - e1 = pe_v_sim(v,ptn,p[1],p[2],p[3],p[4],p[5]); - -*/ - default: - gerror(ANAME(ptn) + " " + Cm.s2307 + " " + Cm.s2308); - e1 = null; - } - if (etype == 0) - return (e1); - - err3: - gerror(ANAME(ptn) + " " + Cm.s2310); - e1 = null; - return null; - } - - - XTerm pe_pv(XTerm p, int c, int d) - { - Var v1; - ElTerm e1; - XTerm p1, p2, p3; - - if (c > 0) - p1 = get_xt(P1(c).var, null); - else - p1 = vars_in_p(p); - { - //sprintf(txt,"\r\npe_pv: %d %d\r\n",c,d); gprint(txt); pprint(p); - } - while (p1 != null) - { - v1 = p1.var; - if (test_pv(v1, c)) - { - e1 = all_elim.nx; - while ((e1 != null) && (e1.v != v1)) e1 = e1.nx; - if (e1 == null) e1 = pe_v_nc(v1, c); - if (e1 == null) - { - p2 = p1; - p1 = p1.p; - put_x(p2); - continue; - } - p = eprem(p, e1); - if (init_deg > 0) - { - if (e1.p1 == null) - p3 = init_v(cp_poly(e1.p2), e1.v); - else - p3 = cp_poly(e1.p2); - { - last_ds.nx = get_dt(d * init_deg, p3, null); - last_ds = last_ds.nx; - } - } - if (max_termp) - { - int tem = plength(p); - if (tem > max_term) max_term = tem; - } - } - p2 = p1; - p1 = p1.p; - put_x(p2); - } - return (p); - } - - boolean test_pv(Var v, int c) - { - switch (c) - { - case -10: - return (v.nm == 2); - case -11: - return (v.nm == 3 && !(v.pt[1] == v.pt[2] && v.pt[0] == v.pt[3])); - case -12: - return (v.nm > 0); - case -13: - return (v.nm == 3); - case -20: - return (v.nm == 2 || v.nm == 3); - case -21: - return (v.nm == 5); - case -22: - return (v.nm == 6 || v.nm == 7); - case -23: - return (v.nm == 17); - case -30: - return (v.nm == 4 && v.pt[1] != 0); - - } - return (true); - } - - ElTerm pe_v_nc(Var v, int ptn) - { - ElTerm e1 = null; - -/* if (print_geo) { printf("\r\npe_v_nc in \r\n");print_var(v); printf("\r\n"); } */ - if (ptn > 0) return (mk_elim(v, null, P1(ptn))); - switch (ptn) - { - case -10: /* herron */ - e1 = mk_elim(v, null, - pplus(ptimes(get_n(16L), get_v(v, 2, get_n(1L))), - pplus(ptimes(trim_g(v.pt[0], v.pt[2], v.pt[2], v.pt[0]), - trim_g(v.pt[1], v.pt[1], v.pt[3], v.pt[3])), - ptimes(trim_g(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), - trim_g(v.pt[0], v.pt[1], v.pt[2], v.pt[3]))))); - break; - case -11: /* d2s */ - e1 = mk_elim(v, pminus(pplus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2])), - pplus(trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1]), - trim_g(v.pt[3], v.pt[0], v.pt[0], v.pt[3]))), - get_n(2L)); - break; - case -12: /* o-xy */ - switch (v.nm) - { - case 2: - e1 = mk_elim(v, area_q(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), get_n(2L)); - break; - case 3: - e1 = mk_elim(v, py_q(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), get_n(1L)); - break; - default: - gerror("pe_v_nc1"); - } - break; - case -13: /* for the circumcenter */ - { - if (xcir3(v.pt[0], v.pt[1], v.pt[2], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2]), - trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1])), - get_n(2L)); - else if (xcir3(v.pt[1], v.pt[0], v.pt[2], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2]), - trim_g(v.pt[0], v.pt[3], v.pt[3], v.pt[0])), get_n(2L)); - else if (xcir3(v.pt[2], v.pt[0], v.pt[1], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[0], v.pt[3], v.pt[3], v.pt[0])), get_n(2L)); - else if (xcir3(v.pt[3], v.pt[0], v.pt[1], v.pt[2])) - e1 = mk_elim(v, pminus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1])), get_n(2L)); - - } - break; - case -20: /* circle */ - e1 = pe_circle(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3]); - break; - case -21: /* chord */ - e1 = mk_elim(v, ptimes(get_m(mk_svar("\\d".toCharArray())), trim_s(v.pt[0], v.pt[1])), get_n(1L)); - break; - case -22: /* sin-cos */ - e1 = pe_sc(v, v.pt[0], v.pt[1]); - break; - case -23: /* sin^2 + cos^2=1 */ - e1 = mk_elim(v, null, pplus3(get_n(-1L), ppower(sc(v.pt[0]), 2), ppower(cc(v.pt[0]), 2))); - break; - case -30: /* vector */ - e1 = mk_elim(v, pminus(trim_vec(v.pt[0], 0), trim_vec(v.pt[1], 0)), get_n(1L)); - break; - default: - gerror("pe_v_nc2"); - } - if (print_geo) - { - gprint("\r\npe_v_nc = \r\n"); - print_elim(e1, (char) 0); - gprint("\r\n"); - } - return (e1); - } - - XTerm geval(Var var, int y, int p) - { - int[] pt = new int[9]; - - for (int i = 0; i < 4; i++) + } + // pro_result = 1; + } + + /** + * Creates a geometric term with the specified coefficients and terms. + * + * @param c1 the first coefficient + * @param p1 the first term + * @param c2 the second coefficient + * @param p2 the second term + */ + void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { + GrTerm gr = mk_gr1(mk_num(c1), p1, mk_num(c2), p2); + gr.c = 0; + last_pr.nx = gr; + last_pr = gr; + } + + /** The head of the elimination term linked list. */ + ElTerm all_elim = new ElTerm(); + + /** + * Creates an elimination term with the specified variable and terms. + * + * @param v the variable + * @param p1 the first term + * @param p2 the second term + * @return the created elimination term + */ + ElTerm mk_elim(Var v, XTerm p1, XTerm p2) { + ElTerm v1 = new ElTerm(); // (el_term )calloc(1,sizeof(el_term)); + v1.v = v; + v1.p1 = p1; + v1.p2 = p2; + v1.nx = all_elim.nx; + all_elim.nx = v1; + return v1; + } + + /** + * Evaluates a geometric expression with the specified variable, integer, and point. + * + * @param var the variable + * @param y the integer + * @param p the point + * @return the evaluated geometric term + */ + XTerm geval(Var var, int y, int p) { + int[] pt = new int[9]; + + for (int i = 0; i < 4; i++) if (var.pt[i] == y) - pt[i] = p; + pt[i] = p; else - pt[i] = var.pt[i]; - switch (var.nm) - { + pt[i] = var.pt[i]; + switch (var.nm) { case 1: case -1: - return (trim_r(pt[0], pt[1], pt[2], pt[3])); + return trim_r(pt[0], pt[1], pt[2], pt[3]); case 2: case -2: - return (trim_a(pt[0], pt[1], pt[2], pt[3])); + return trim_a(pt[0], pt[1], pt[2], pt[3]); case 3: case -3: - return (trim_g(pt[0], pt[1], pt[2], pt[3])); + return trim_g(pt[0], pt[1], pt[2], pt[3]); case 4: case -4: - return (trim_vec(pt[0], pt[1])); + return trim_vec(pt[0], pt[1]); default: - exit(1); - } - return (null); - } - - - XTerm trim_r(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 == p2) return (pzero()); - if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); - if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); - if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(1, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); - - } - - XTerm trim_a(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_a1 %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xpara(p1, p3, p2, p4)) return (pzero()); - if (xcoll(p1, p2, p3)) - { + exit(1); + } + return null; + } + + /** + * Trims a geometric term with the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the trimmed geometric term + */ + XTerm trim_a(int p1, int p2, int p3, int p4) { + int p; + char sn = 1; + if (xpara(p1, p3, p2, p4)) return pzero(); + if (xcoll(p1, p2, p3)) { p2 = p1; - } else if (xcoll(p4, p2, p3)) - { + } else if (xcoll(p4, p2, p3)) { p3 = p4; - } else if (xcoll(p4, p1, p3)) - { + } else if (xcoll(p4, p1, p3)) { p4 = p3; - } else if (xcoll(p4, p2, p1)) - { + } else if (xcoll(p4, p2, p1)) { p1 = p4; - } -/* if (print_geo) printf("trim_a2 %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 < p3) - { + } + if (p1 < p3) { sn *= -1; p = p1; p1 = p3; p3 = p; - } - if (p2 < p4) - { + } + if (p2 < p4) { sn *= -1; p = p2; p2 = p4; p4 = p; - } - if (p1 < p2) - { + } + if (p1 < p2) { sn *= -1; p = p1; p1 = p2; @@ -1332,105 +131,53 @@ XTerm trim_a(int p1, int p2, int p3, int p4) p = p3; p3 = p4; p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { + } else if ((p1 == p2) && (p3 < p4)) { sn *= -1; p = p3; p3 = p4; p4 = p; - } + } - if (p1 == p2) - { + if (p1 == p2) { p2 = p3; p3 = p4; - } else if (p2 == p3) - { - p3 = p4; - } - - if (sn == 1) - return (get_m(mk_var(2, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); - } - - XTerm trim_g(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xperp(p1, p3, p2, p4)) return (get_n(0L)); - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - p = p3; + } else if (p2 == p3) { p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - sn *= -1; - p1 = p3; - p3 = p2; - } else if (p3 == p4) - { - sn *= -1; - p4 = p2; - p2 = p3; - } - //The largest index is either p1 or p2 - if (sn == 1) - return (get_m(mk_var(3, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); - } - - XTerm trim_f(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (print_geo) - { + } + + if (sn == 1) + return get_m(mk_var(2, p1, p2, p3, p4)); + else + return neg_poly(get_m(mk_var(2, p1, p2, p3, p4))); + } + + /** + * Trims a geometric term with the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the trimmed geometric term + */ + XTerm trim_f(int p1, int p2, int p3, int p4) { + int p; + char sn = 1; + if (print_geo) { gprint("trim_a1 " + p1 + p2 + p3 + p4 + "\r\n"); - } - if (xcoll4(p1, p2, p3, p4)) return (pzero()); - if (p1 < p2) - { + } + if (xcoll4(p1, p2, p3, p4)) return pzero(); + if (p1 < p2) { p = p1; p1 = p2; p2 = p; - } - if (p3 < p4) - { + } + if (p3 < p4) { p = p3; p3 = p4; p4 = p; - } - if (p1 < p3) - { + } + if (p1 < p3) { sn *= -1; p = p1; p1 = p3; @@ -1438,56 +185,28 @@ XTerm trim_f(int p1, int p2, int p3, int p4) p = p2; p2 = p4; p4 = p; - } else if ((p1 == p3) && (p2 < p4)) - { + } else if ((p1 == p3) && (p2 < p4)) { sn *= -1; p = p2; p2 = p4; p4 = p; - } - if (sn == 1) - return (get_m(mk_var(10, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); - } - - XTerm trim_fl(LLine l1, LLine l2) - { - if (l1 == l2) return (pzero()); - return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); + } + if (sn == 1) + return get_m(mk_var(10, p1, p2, p3, p4)); + else + return neg_poly(get_m(mk_var(10, p1, p2, p3, p4))); + } + + /** + * Trims a geometric term with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the trimmed geometric term + */ + @Override + XTerm trim_fl(LLine l1, LLine l2) { + if (l1 == l2) return pzero(); + return trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1]); + } } - - XTerm trim_vec(int p1, int p2) - { - if (p2 == 0) - { - return (get_m(mk_var(4, p1, 0, 0, 0))); - } - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); - return (get_m(mk_var(4, p1, p2, 0, 0))); - } - - XTerm trim_l(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(5, p2, p1, 0, 0)))); - return (get_m(mk_var(5, p1, p2, 0, 0))); - } - - XTerm trim_s(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(6, p2, p1, 0, 0)))); - return (get_m(mk_var(6, p1, p2, 0, 0))); - } - - XTerm trim_c(int p1, int p2) - { - if (p1 == p2) return (get_n(1L)); - if (p1 < p2) return (neg_poly(get_m(mk_var(7, p2, p1, 0, 0)))); - return (get_m(mk_var(7, p1, p2, 0, 0))); - } - - -} diff --git a/src/main/java/gprover/AuxPt.java b/src/main/java/gprover/AuxPt.java index 8db79d8f..f0be8072 100644 --- a/src/main/java/gprover/AuxPt.java +++ b/src/main/java/gprover/AuxPt.java @@ -3,30 +3,49 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 4, 2006 - * Time: 7:13:10 PM - * To change this template use File | Settings | File Templates. + * The AuxPt class represents an auxiliary point in a geometric construction. + * It includes methods for managing a list of ProPoint objects and retrieving + * information about the auxiliary point. */ public class AuxPt { - String name; + /** The type of the auxiliary point. */ int type; - Vector vptlist = new Vector(); - String str; + /** The list of ProPoint objects associated with the auxiliary point. */ + VectorThis class provides arrays for construction types, intersection types, + * and conclusion types, along with methods to retrieve indices, generate + * descriptive strings for geometric constructions, and perform various + * validations and conversions. + * + *
The static method {@link #charCons(int, Cons, Cons, Object[])} constructs a new + * construction by combining two given constructions, performing necessary + * validations and point adjustments based on geometric rules. + */ public class CST { - final public static String[] cst = - { - "POINT", - "LINE", - "ON_LINE", - "ON_PLINE", - "ON_TLINE", - "ON_BLINE", - "ON_ALINE", - - "FOOT", - "CIRCLE", - "ON_CIRCLE", - "CIRCUMCENTER", - "ON_RCIRCLE", - - "MIDPOINT", - - "EQDISTANCE", //"ON_RCIRCLE", - "EQANGLE", - - "TRATIO", - "PRATIO", - "NRATIO", - "LRATIO", - - "INVERSION", - "REFLECTION", - "SYM", - - "TRIANGLE", - "QUADRANGLE", - "PENTAGON", - "POLYGON", - "ISO_TRIANGLE", - "R_TRIANGLE", - "EQ_TRIANGLE", - "TRAPEZOID", - "R_TRAPEZOID", - "PARALLELOGRAM", - "LOZENGE", - "RECTANGLE", - "SQUARE", - - "INCENTER", - "ORTHOCENTER", - "CENTROID", - - "CONSTANT", - - "PSQUARE", - "NSQUARE", - "S_ANGLE", - "ANGLE_BISECTOR", - "LC_TANGENT", - "RATIO", - "CCTANGENT", - "ON_SCIRCLE", - "ON_BALINE", - "ON_DCIRCLE", - "EQANGLE3P" - }; - + // Array of geometric construction types + final public static String[] cst = { + "POINT", "LINE", "ON_LINE", "ON_PLINE", "ON_TLINE", "ON_BLINE", "ON_ALINE", + "FOOT", "CIRCLE", "ON_CIRCLE", "CIRCUMCENTER", "ON_RCIRCLE", + "MIDPOINT", "EQDISTANCE", "EQANGLE", "TRATIO", "PRATIO", "NRATIO", "LRATIO", + "INVERSION", "REFLECTION", "SYM", "TRIANGLE", "QUADRANGLE", "PENTAGON", + "POLYGON", "ISO_TRIANGLE", "R_TRIANGLE", "EQ_TRIANGLE", "TRAPEZOID", + "R_TRAPEZOID", "PARALLELOGRAM", "LOZENGE", "RECTANGLE", "SQUARE", + "INCENTER", "ORTHOCENTER", "CENTROID", "CONSTANT", "PSQUARE", "NSQUARE", + "S_ANGLE", "ANGLE_BISECTOR", "LC_TANGENT", "RATIO", "CCTANGENT", + "ON_SCIRCLE", "ON_BALINE", "ON_DCIRCLE", "EQANGLE3P" + }; + // Array of intersection types final public static String[] inters = { - "INTERSECTION_LL", - "INTERSECTION_LP", - "INTERSECTION_LC", - "INTERSECTION_LB", - "INTERSECTION_LT", - "INTERSECTION_LR", - "INTERSECTION_LS", - "INTERSECTION_PP", - "INTERSECTION_PC", - "INTERSECTION_PT", - "INTERSECTION_PB", - "INTERSECTION_TC", - "INTERSECTION_TT", - "INTERSECTION_TB", - "INTERSECTION_BB", - "INTERSECTION_BC", - "INTERSECTION_CC", - "INTERSECTION_CR", - "INTERSECTION_RR", - "INTERSECTION_SS", - "INTERSECTION_AA", - - "INTERSECTION_LA", - "INTERSECTION_PA", - "INTERSECTION_PR", - "INTERSECTION_TA", - "INTERSECTION_TR", - "INTERSECTION_BA", - "INTERSECTION_BR", + "INTERSECTION_LL", "INTERSECTION_LP", "INTERSECTION_LC", "INTERSECTION_LB", + "INTERSECTION_LT", "INTERSECTION_LR", "INTERSECTION_LS", "INTERSECTION_PP", + "INTERSECTION_PC", "INTERSECTION_PT", "INTERSECTION_PB", "INTERSECTION_TC", + "INTERSECTION_TT", "INTERSECTION_TB", "INTERSECTION_BB", "INTERSECTION_BC", + "INTERSECTION_CC", "INTERSECTION_CR", "INTERSECTION_RR", "INTERSECTION_SS", + "INTERSECTION_AA", "INTERSECTION_LA", "INTERSECTION_PA", "INTERSECTION_PR", + "INTERSECTION_TA", "INTERSECTION_TR", "INTERSECTION_BA", "INTERSECTION_BR", "PT_EQUAL" }; + // Array of conclusion types final public static String[] conclusion = { - "COLLINEAR", - "PARALLEL", - "PERPENDICULAR", - "MIDPOINT", - "CYCLIC", - "EQDISTANCE", - "EQANGLE", - "PERP_BISECT", - "TANGENT", - "HARMONIC_PAIR", - "EQ_TRIANGLE", - "SIM_TRIANGLE", - "CON_TRIANGLE", - "EQ_PRODUCT", - "ORTHOCENTER", - "INCENTER", - "RATIO", - "S_ANGLE", - "N_ANGLES", - "N_SEGMENTS" - + "COLLINEAR", "PARALLEL", "PERPENDICULAR", "MIDPOINT", "CYCLIC", + "EQDISTANCE", "EQANGLE", "PERP_BISECT", "TANGENT", "HARMONIC_PAIR", + "EQ_TRIANGLE", "SIM_TRIANGLE", "CON_TRIANGLE", "EQ_PRODUCT", "ORTHOCENTER", + "INCENTER", "RATIO", "S_ANGLE", "N_ANGLES", "N_SEGMENTS" }; - public static String[] s_conc_detail = - { - "Collinear", - "Parallel", - "Perpendicular", - "Midpoint", - "Cyclic", - "Equal Distance", - "Equal Angle", - "Bisect", - "Tangent", - "Harmonic Pair", - "Equilateral Triangle", - "Similiar Triangle", - "Congruent Triangle", - "Equal product", - "Orthocenter", - "Incenter", - "Ratio", - "Special angle", - "Angles Equation", - "Segment Equation" - }; - - private CST() { - } + // Array of detailed conclusion descriptions + public static String[] s_conc_detail = { + "Collinear", "Parallel", "Perpendicular", "Midpoint", "Cyclic", + "Equal Distance", "Equal Angle", "Bisect", "Tangent", "Harmonic Pair", + "Equilateral Triangle", "Similiar Triangle", "Congruent Triangle", + "Equal product", "Orthocenter", "Incenter", "Ratio", "Special angle", + "Angles Equation", "Segment Equation" + }; - public static String get_detail_info(int n, Object[] p) { - return null; - } + // Private constructor to prevent instantiation + private CST() {} + // Constants for index ranges final private static int CONC_INDEX = 70; final private static int INTER_INDEX = 100; - + /** + * Gets the index of a conclusion type. + * @param s The conclusion type as a string. + * @return The index of the conclusion type. + */ public static int getClu(String s) { s = s.toUpperCase(); for (int i = 0; i < conclusion.length; i++) @@ -173,6 +84,11 @@ public static int getClu(String s) { return 0; } + /** + * Gets the index of a detailed conclusion description. + * @param s The detailed conclusion description as a string. + * @return The index of the detailed conclusion description. + */ public static int getClu_D(String s) { for (int i = 0; i < s_conc_detail.length; i++) if (s.equalsIgnoreCase(s_conc_detail[i])) @@ -180,8 +96,12 @@ public static int getClu_D(String s) { return 0; } + /** + * Gets the conclusion or intersection type as a string. + * @param n The index of the type. + * @return The type as a string. + */ public static String getClus(int n) { - int i = n - CONC_INDEX; if (i >= 0 && i < conclusion.length) return conclusion[i]; @@ -196,11 +116,14 @@ public static String getClus(int n) { return inters[i]; } + /** + * Gets the index of a predicate type. + * @param s The predicate type as a string. + * @return The index of the predicate type. + */ public static int get_pred(String s) { - int n = 0; - if (n == 0) for (int i = 0; i < cst.length; i++) if (s.equals(cst[i])) { @@ -215,13 +138,17 @@ public static int get_pred(String s) { break; } - if (n == 0) n = getClu(s); return n; } + /** + * Gets the predicate type as a string. + * @param n The index of the type. + * @return The type as a string. + */ public static String get_preds(int n) { if (n >= 1 && n <= cst.length) return cst[n - 1]; @@ -233,10 +160,23 @@ public static String get_preds(int n) { return getClus(n); } + /** + * Gets a descriptive string for a given type and parameters. + * @param pss The parameters. + * @param t The type. + * @return The descriptive string. + */ public static String getDString(Object[] pss, int t) { return getDString(pss, t, true); } + /** + * Gets a descriptive string for a given type and parameters. + * @param pss The parameters. + * @param t The type. + * @param d Whether to include detailed descriptions. + * @return The descriptive string. + */ public static String getDString(Object[] pss, int t, boolean d) { switch (t) { @@ -615,7 +555,14 @@ public static String getDString(Object[] pss, int t, boolean d) { } } - + /** + * Generates a concatenated String of the non-null elements in the specified subarray. + * + * @param m the starting index (inclusive) + * @param n the ending index (inclusive) + * @param ps the array of Objects + * @return a String containing the concatenation of each non-null element's String representation + */ public static String vprint(int m, int n, Object[] ps) { String s = ""; for (int i = m; i <= n; i++) @@ -624,6 +571,19 @@ public static String vprint(int m, int n, Object[] ps) { return s; } + /** + * Constructs a new construction by combining two given construction objects. + * + *
This method performs the necessary validations and adjustments of point indices + * according to geometric rules. If the primary construction (c1) is null, the method + * uses the secondary construction (c2) as the basis for constructing the new Cons object. + * + * @param pt the reference point index used for adjustments + * @param c1 the primary Cons object; may be null + * @param c2 the secondary Cons object to use if c1 is null + * @param pss the array of point information associated with the construction + * @return the resulting Cons object after combining and validating the constructions + */ public static Cons charCons(int pt, Cons c1, Cons c2, Object[] pss) { if (c1 == null) { c1 = c2; @@ -850,6 +810,15 @@ public static Cons charCons(int pt, Cons c1, Cons c2, Object[] pss) { } + /** + * Adjusts the specification fields of the given construction based on the reference point. + * + *
This method analyzes and modifies the type and point indices of the provided + * construction (c) according to geometric rules and validations. + * + * @param pt the reference point index used for adjustments + * @param c the construction object to be adjusted; may be {@code null} + */ public static void spec(int pt, Cons c) { if (c == null) return; @@ -922,6 +891,15 @@ public static void spec(int pt, Cons c) { } } + /** + * Adds additional point specification data to the given construction. + * + *
This method processes the provided array of point specification data and updates the + * corresponding fields in the construction object accordingly.
+ * + * @param c the construction object to update + * @param pss the array of additional point specification data + */ public static void addPss(Cons c, Object[] pss) { int[] p = c.ps; int i = 0; @@ -936,6 +914,17 @@ public static void addPss(Cons c, Object[] pss) { c.no = i - 1; } + /** + * Revalidates the provided array of point indices based on the reference point and count. + *+ * This method applies revalidation rules to adjust the point indices in the array + * so that they are consistent with the given reference point. + *
+ * + * @param pt the reference point used for revalidation + * @param p the array of point indices to validate + * @param n the number of valid entries in the point indices array + */ public static void reval(int pt, int[] p, int n) { int n1 = n / 2; boolean c = false; @@ -964,6 +953,14 @@ public static void reval(int pt, int[] p, int n) { reval(pt, p, n1); } + /** + * Adjusts the type code for a line-to-foot construction. + * Applies foot-specific rules and validations on the provided type and point array. + * + * @param t the original type code + * @param p the array of point indices associated with the construction + * @return the adjusted type code after applying the foot-specific rules + */ public static int ge_lt_foot(int t, int[] p) { if (p[1] == p[4] && p[2] == p[5] || p[1] == p[5] && p[2] == p[4]) { p[4] = p[5] = 0; @@ -976,6 +973,18 @@ public static int ge_lt_foot(int t, int[] p) { return t; } + /** + * Validates and adjusts the type code for a construction based on the reference point and its associated point indices. + * + *This method checks the provided point index array and the initial type code, applying specific geometric rules + * to ensure the correctness of the construction. It returns an adjusted type code reflecting any validations applied, + * or 0 if the validation fails. + * + * @param pt the reference point index used during validation + * @param t1 the initial type code of the construction + * @param p1 an array of point indices associated with the construction (may be modified during validation) + * @return the validated (and possibly adjusted) type code, or 0 if validation fails + */ public static int validate_all(int pt, int t1, int[] p1) { if (t1 == Gib.C_EQDISTANCE || t1 == Gib.CO_CONG) { @@ -991,6 +1000,17 @@ else if (t1 == Gib.CO_PERP || t1 == Gib.C_O_T) return t1; } + /** + * Validates and adjusts the construction type for an angle-related scenario. + * + *
This method checks and modifies the provided point indices array for angle-related constructions, + * applying specific geometric validations. It returns an adjusted type code if the validation is successful, + * or 0 if validation fails.
+ * + * @param pt the reference point index used for validation + * @param ps an array of point indices related to the construction + * @return the validated (and possibly adjusted) type code, or 0 if validation fails + */ public static int validate_ea(int pt, int[] ps) { int t1 = Gib.C_O_A; int i = 0; @@ -1034,6 +1054,17 @@ public static int validate_ea(int pt, int[] ps) { return t1; } + /** + * Validates and adjusts the construction type for a collinearity scenario. + * + *This method examines the provided array of point indices and determines if they satisfy + * the conditions for defining a collinear construction. It returns the validated type code + * if successful, or 0 if validation fails.
+ * + * @param pt the reference point index used for validation + * @param ps the array of point indices to validate + * @return the validated type code for the collinear construction, or 0 if validation fails + */ public static int validate_coll(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1044,6 +1075,17 @@ public static int validate_coll(int pt, int[] ps) { return Gib.C_O_L; } + /** + * Validates and adjusts the construction type for a parallel scenario. + * + *This method examines the array of point indices and validates them according to + * the rules for parallel constructions. It returns the validated type code if the + * validation is successful, or 0 if validation fails. + * + * @param pt the reference point index used during validation + * @param ps the array of point indices associated with the parallel construction + * @return the validated construction type code for a parallel configuration, or 0 if invalid + */ public static int validate_p(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1056,6 +1098,19 @@ public static int validate_p(int pt, int[] ps) { return Gib.C_O_P; } + /** + * Validates and adjusts the construction type for a perpendicular construction. + * + *
This method examines the provided array of point indices and applies + * perpendicular-specific validation rules. It may reorder or adjust the point indices + * to ensure consistency with the geometric definition of a perpendicular construction. + * If the validation is successful, the method returns the adjusted construction type; + * otherwise, it returns 0.
+ * + * @param pt the reference point index used during validation + * @param ps the array of point indices associated with the construction + * @return the validated (and possibly adjusted) construction type code, or 0 if validation fails + */ public static int validate_t(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1068,6 +1123,18 @@ public static int validate_t(int pt, int[] ps) { return Gib.C_O_T; } + /** + * Validates and adjusts the construction type for a congruence of distances construction. + * + *This method examines the provided array of point indices associated + * with a congruence construction (e.g., verifying segment congruence) and applies + * specific validations. It returns an adjusted type code reflecting the outcome of the + * validation, or 0 if validation fails.
+ * + * @param pt the reference point index used for validation + * @param ps the array of point indices associated with the congruence construction + * @return the validated construction type code, or 0 if validation fails + */ public static int validate_cg(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1086,12 +1153,28 @@ public static int validate_cg(int pt, int[] ps) { return Gib.C_O_R; } + + /** + * Exchanges the elements at indices i and j in the given array. + * + * @param i the index of the first element to exchange + * @param j the index of the second element to exchange + * @param ps the array in which the elements will be swapped + */ public static void exchange(int i, int j, int[] ps) { int t = ps[i]; ps[i] = ps[j]; ps[j] = t; } + + /** + * Creates a copy of the given integer array. + * This method returns a new array containing the same elements as the input array. + * + * @param p the array to copy + * @return a new array that is a copy of p + */ public static int[] pcopy(int[] p) { if (p == null) return null; diff --git a/src/main/java/gprover/CSegs.java b/src/main/java/gprover/CSegs.java index 98681824..d241525f 100644 --- a/src/main/java/gprover/CSegs.java +++ b/src/main/java/gprover/CSegs.java @@ -1,22 +1,30 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 23, 2006 - * Time: 5:17:01 PM - * To change this template use File | Settings | File Templates. - */ -public class CSegs extends CClass { - public int no; - public int[] p1; - public int[] p2; - CSegs nx; + /** + * The CSegs class represents a collection of geometric segments in a proof. + * It includes properties for the number of segments, arrays of points defining the segments, + * and a reference to the next segment in the list. + */ + public class CSegs extends CClass { + /** The number of segments. */ + public int no; - public CSegs() { - type = no = 0; - p1 = new int[MAX_GEO * 2]; - p2 = new int[MAX_GEO * 2]; - nx = null; - } -} + /** The array of starting points of the segments. */ + public int[] p1; + + /** The array of ending points of the segments. */ + public int[] p2; + + /** The next segment in the list. */ + CSegs nx; + + /** + * Constructs a CSegs object with default values. + */ + public CSegs() { + type = no = 0; + p1 = new int[MAX_GEO * 2]; + p2 = new int[MAX_GEO * 2]; + nx = null; + } + } diff --git a/src/main/java/gprover/Cm.java b/src/main/java/gprover/Cm.java index fcab1a42..844fd786 100644 --- a/src/main/java/gprover/Cm.java +++ b/src/main/java/gprover/Cm.java @@ -1,110 +1,114 @@ /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-16 - * Time: 13:37:35 - * To change this template use File | Settings | File Templates. - */ -package gprover; - - -import wprover.GExpert; - -final public class Cm { - - static public boolean isWindows() { - return System.getProperty("os.name").startsWith("Windows"); - } - - final public static String s2070 = "(hyp)"; - - final public static String s2072 = "The Machine Proof"; - - final public static String PERPENDICULAR_SIGN = " ⊥ "; - final public static String PARALLEL_SIGN = " ∥ "; - final public static String TRIANGLE_SIGN = "∆"; - - final public static String ANGLE_SIGN = "∠"; - final public static String EQUAL_SIGN = " = "; - final public static String SIMILAR_SIGN = " ~ "; - final public static String INTERSECT_SIGN = " ∩ "; - - final public static String s2707 = "lines"; - - final public static String s2713 = "circles in the database."; - - final public static String s2720 = "similar triangles"; - - final public static String s2722 = "congruent triangles"; - - final public static String s2727 = " because "; - final public static String s2728 = " and "; - - final public static String PC_COLL = "COLLINEAR"; - final public static String PC_PARA = "PARALLEL"; - final public static String PC_PERP = "PERPENDICULAR"; - final public static String PC_CONG = "EQDISTANCE"; - final public static String PC_ACONG = "EQANGLE"; - final public static String PC_CYCLIC = "COCIRCLE"; - - final public static String PC_STRI = "SIM_TRIANGLE"; - final public static String PC_CTRI = "CON_TRIANGLE"; - final public static String PC_MIDP = "MIDPOINT"; - - // predicate. - - final public static String P_POINT = "POINT"; - - final public static String DR_WPT = "WPT"; - - //////////////// - final public static String s2810 = "\r\n\r\nOnly full-angles are allowd in this case"; - final public static String s2811 = "\r\nConclusion cannot be represented with full-angles.\r\n"; - final public static String s2812 = "\r\nCannot solve this problem with full-angles.\r\n"; - - /// ----------------------------------------- - final public static String s1993 = "Index"; - - //-------------area-------------------------------------- - final public static String s2300 = "\r\n\r\nThe statement is true.\r\n\r\n"; - final public static String s2301 = "\r\n\\rnThe statement is false.\r\n\r\n"; - final public static String s2302 = "Conclusion not fund:"; - final public static String s2303 = "A new point"; - final public static String s2304 = "is introduced by construction\r\n"; - final public static String s2305 = "The new conclusion is: "; - final public static String s2306 = "EQ_RATIO"; - final public static String s2307 = "Construction for point"; - final public static String s2308 = "is not allowd in area method.\r\n"; - - final public static String s2310 = "In the area method, the lines and circles must meet in one point"; - final public static String s2311 = "construction INCENTER is not allowed in the prover.\r\n"; - final public static String s2312 = "Please use construction:\r\n construct a vertex from the incenter and two other vertex.\r\n"; - final public static String s2313 = "In the area method, PTRIANGLE can be used only when the conclusion is about vectors."; - final public static String s2314 = "\r\n Proving failed. Statement is not proved."; - - final public static String s2220 = "\r\nThere exists no proof.\r\n"; - final public static String s2221 = "The conclusion is: "; - final public static String s2222 = "This is equivalent to: "; - final public static String s2223 = "Eliminating the common factors: "; - - final public static String s2225 = "\r\nThe geometric quantities used in the proof.\r\n"; - final public static String s2226 = "Eliminate variables"; - - - final public static String sfe_exp_error = "The conclusion can not be translated to full-angle expression."; - - final public static String getFError(int n) { - if (n == 1) - return sfe_exp_error; - return GExpert.getLanguage("Failed to prove this theorem with Full Angle Method.") + "\n"; - } - - final public static boolean DEBUG = false; - - final public static void print(String s) { - if (DEBUG) - System.out.println(s); - } - - -} + * The Cm class contains various constants and utility methods used in geometric proofs. + * It includes string constants for geometric symbols, predicates, and messages, + * as well as a debug flag and a print method for debugging purposes. + */ + package gprover; + + final public class Cm { + + /** Hypothesis string constant. */ + final public static String s2070 = "(hyp)"; + + /** The machine proof string constant. */ + final public static String s2072 = "The Machine Proof"; + + /** Perpendicular sign constant. */ + final public static String PERPENDICULAR_SIGN = " ⊥ "; + /** Parallel sign constant. */ + final public static String PARALLEL_SIGN = " ∥ "; + /** Triangle sign constant. */ + final public static String TRIANGLE_SIGN = "∆"; + + /** Angle sign constant. */ + final public static String ANGLE_SIGN = "∠"; + /** Equal sign constant. */ + final public static String EQUAL_SIGN = " = "; + /** Similar sign constant. */ + final public static String SIMILAR_SIGN = " ~ "; + /** Intersect sign constant. */ + final public static String INTERSECT_SIGN = " ∩ "; + + /** Lines string constant. */ + final public static String s2707 = "lines"; + + /** Circles in the database string constant. */ + final public static String s2713 = "circles in the database."; + + /** Similar triangles string constant. */ + final public static String s2720 = "similar triangles"; + + /** Congruent triangles string constant. */ + final public static String s2722 = "congruent triangles"; + + /** Because string constant. */ + final public static String s2727 = " because "; + /** And string constant. */ + final public static String s2728 = " and "; + + /** Collinear predicate constant. */ + final public static String PC_COLL = "COLLINEAR"; + /** Parallel predicate constant. */ + final public static String PC_PARA = "PARALLEL"; + /** Perpendicular predicate constant. */ + final public static String PC_PERP = "PERPENDICULAR"; + /** Equal distance predicate constant. */ + final public static String PC_CONG = "EQDISTANCE"; + /** Equal angle predicate constant. */ + final public static String PC_ACONG = "EQANGLE"; + /** Cocircle predicate constant. */ + final public static String PC_CYCLIC = "COCIRCLE"; + + /** Similar triangle predicate constant. */ + final public static String PC_STRI = "SIM_TRIANGLE"; + /** Congruent triangle predicate constant. */ + final public static String PC_CTRI = "CON_TRIANGLE"; + /** Midpoint predicate constant. */ + final public static String PC_MIDP = "MIDPOINT"; + + /** Point predicate constant. */ + final public static String P_POINT = "POINT"; + + /** WPT string constant. */ + final public static String DR_WPT = "WPT"; + + /** Only full-angles allowed message constant. */ + final public static String s2810 = "\r\n\r\nOnly full-angles are allowd in this case"; + /** Conclusion cannot be represented with full-angles message constant. */ + final public static String s2811 = "\r\nConclusion cannot be represented with full-angles.\r\n"; + /** Cannot solve problem with full-angles message constant. */ + final public static String s2812 = "\r\nCannot solve this problem with full-angles.\r\n"; + + /** Index string constant. */ + final public static String s1993 = "Index"; + + /** The statement is true message constant. */ + final public static String s2300 = "\r\n\r\nThe statement is true.\r\n\r\n"; + + /** No proof exists message constant. */ + final public static String s2220 = "\r\nThere exists no proof.\r\n"; + /** Conclusion message constant. */ + final public static String s2221 = "The conclusion is: "; + /** Equivalent message constant. */ + final public static String s2222 = "This is equivalent to: "; + /** Eliminating common factors message constant. */ + final public static String s2223 = "Eliminating the common factors: "; + + /** Geometric quantities used in proof message constant. */ + final public static String s2225 = "\r\nThe geometric quantities used in the proof.\r\n"; + /** Eliminate variables message constant. */ + final public static String s2226 = "Eliminate variables"; + + /** Debug flag. */ + final public static boolean DEBUG = false; + + /** + * Prints the specified string if the debug flag is set. + * + * @param s the string to print + */ + public static void print(String s) { + if (DEBUG) + System.out.println(s); + } + } \ No newline at end of file diff --git a/src/main/java/gprover/Cond.java b/src/main/java/gprover/Cond.java index 39de4118..a637676b 100644 --- a/src/main/java/gprover/Cond.java +++ b/src/main/java/gprover/Cond.java @@ -11,59 +11,125 @@ import java.util.Vector; +/** + * Represents a condition in the proof structure. + * It contains details like rule, predicate, step number, description, + * proof structure and related attributes. + */ public class Cond { + /** Maximum number of geometric elements. */ final public static int MAX_GEO = 16; - protected int rule = 0; // the rule being used in this step (theorems or lemmas) + /** The rule being used in this step (theorems or lemmas). */ + protected int rule = 0; + /** Predicate identifier. */ public int pred; - public int no; // the number of the current step + /** The number of the current step. */ + public int no; + /** Array of geometric elements. */ public int[] p; + /** Structure holding different geometric entities. */ public UStruct u; - public Cond nx, cd; // nx: next - public String sd = null; // step description - public Vector vlist = null; // the list of the direct steps in this node + /** Next condition. */ + public Cond nx; + /** Additional condition. */ + public Cond cd; + /** Step description. */ + public String sd = null; + /** List of the direct steps in this node. */ + public Vector vlist = null; + /** Depth of the condition, initialized from Gib.depth. */ public long dep = Gib.depth; + /** + * Retrieves the step description. + * + * @return the step description text + */ public String getText() { return sd; } + /** + * Sets the step description. + * + * @param s the new description text + */ public void setText(String s) { sd = s; } + /** + * Retrieves the current step number. + * + * @return the step number + */ public int getNo() { return no; } + /** + * Retrieves the current rule. + * + * @return the rule applied + */ public int getRule() { return rule; } + /** + * Sets the rule from the related facts in the internal structure. + */ public void getRuleFromeFacts() { rule = u.get_lemma(); } + /** + * Sets the current rule. + * + * @param r the rule to be set + */ public void setRule(int r) { rule = r; } + /** + * Retrieves the condition from the internal structure. + * + * @return the condition pointer (PCO) + */ public Cond getPCO() { return u.get_co(); } + /** + * Returns the step description as the string representation. + * + * @return the step description + */ public String toString() { return sd; } + /** + * Prepends the step description with a language specific "To Prove:" message. + */ public void setCondToBeProveHead() { sd = GExpert.getLanguage("To Prove:") + " " + sd; } + /** + * Constructs a condition with a given predicate. + * + * @param t the predicate + */ public Cond(int t) { this(); pred = t; } + /** + * Default condition constructor that initializes required fields. + */ public Cond() { pred = no = 0; p = new int[MAX_GEO]; @@ -71,17 +137,26 @@ public Cond() { nx = null; } + /** + * Constructs a condition optionally initializing the geometric array. + * + * @param r if true, initializes the geometric array; otherwise leaves it null + */ public Cond(boolean r) { pred = no = 0; if (r) p = new int[MAX_GEO]; else p = null; - u = new UStruct(); nx = null; } + /** + * Copy constructor for creating a duplicate of a given condition. + * + * @param co the condition to copy + */ public Cond(Cond co) { pred = co.pred; no = co.no; @@ -94,6 +169,11 @@ public Cond(Cond co) { sd = null; } + /** + * Adds a condition as a direct child. + * + * @param co the condition to add + */ public void addcond(Cond co) { rule = 0; if (co == null) return; @@ -102,6 +182,12 @@ public void addcond(Cond co) { vlist.add(co); } + /** + * Adds a condition with a specified rule. + * + * @param r the rule value to set + * @param co the condition to add + */ public void addcond(int r, Cond co) { rule = r; if (co == null) return; @@ -110,19 +196,36 @@ public void addcond(int r, Cond co) { vlist.add(co); } + /** + * Adds all conditions from a given vector. + * + * @param v the vector containing conditions to add + */ public void add_allco(Vector v) { if (v == null) return; if (vlist == null) vlist = new Vector(); vlist.addAll(v); - } + /** + * Adds two conditions as direct children with a specified rule. + * + * @param lm the rule value to set + * @param co1 the first condition to add + * @param co2 the second condition to add + */ public void addcond(int lm, Cond co1, Cond co2) { rule = lm; addcond(co1, co2); } + /** + * Adds two conditions as direct children. + * + * @param co1 the first condition to add + * @param co2 the second condition to add + */ public void addcond(Cond co1, Cond co2) { rule = 0; if (vlist == null) @@ -131,23 +234,41 @@ public void addcond(Cond co1, Cond co2) { if (co2 != null) vlist.add(co2); } + /** + * Retrieves the attributes associated with the condition. + * + * @return a CClass representing the condition's attributes + */ public CClass get_attr() { return u.get_attr(); } + /** + * Determines the type of the condition's conclusion. + * + * @return 1 if the internal structure is null; 2 if the condition obtained from the structure is null; otherwise 0 + */ public int get_conc_type() { if (u.isnull()) // Hype return 1; - else if (u.get_co() == null) // Obviousely + else if (u.get_co() == null) // Obviously return 2; else return 0; } + /** + * Dummy method for rule processing. Implementation pending. + */ public void gRule() { } } +/** + * Represents a structure holding various geometric elements. + * This class contains fields for different types of geometric data and provides + * methods for comparing, copying, and retrieving attributes from the stored elements. + */ class UStruct { MidPt md; LLine ln; @@ -163,6 +284,13 @@ class UStruct { Polygon pg; LList ns; + /** + * Compares this UStruct to another UStruct for equality. + * Equality is defined as all corresponding fields referring to the same object. + * + * @param u1 the UStruct to compare with + * @return true if all fields are equal; false otherwise + */ public boolean equal(UStruct u1) { return md == u1.md @@ -180,6 +308,11 @@ public boolean equal(UStruct u1) { && ns == u1.ns; } + /** + * Checks if all the fields in this UStruct are null. + * + * @return true if every field is null; false otherwise + */ public boolean isnull() { return md == null @@ -197,6 +330,9 @@ public boolean isnull() { && ns == null; } + /** + * Sets all fields in this UStruct to null. + */ public void setnull() { md = null; ln = null; @@ -213,6 +349,11 @@ public void setnull() { ns = null; } + /** + * Copies all field values from the specified UStruct into this UStruct. + * + * @param us the UStruct to copy from + */ public void cpv(UStruct us) { md = us.md; pn = us.pn; @@ -229,6 +370,9 @@ public void cpv(UStruct us) { ns = us.ns; } + /** + * Constructs an empty UStruct with all fields initialized to null. + */ public UStruct() { md = null; ln = null; @@ -245,6 +389,11 @@ public UStruct() { ns = null; } + /** + * Retrieves the type of the first non-null geometric element. + * + * @return the type if found; -1 if no element is present + */ public int get_type() { if (md != null) return md.type; if (ln != null) return ln.type; @@ -262,6 +411,11 @@ public int get_type() { return -1; } + /** + * Retrieves the lemma value from the first non-null geometric element. + * + * @return the lemma if found; -1 if no element is present + */ public int get_lemma() { if (md != null) return md.lemma; if (ln != null) return ln.lemma; @@ -278,6 +432,11 @@ public int get_lemma() { return -1; } + /** + * Retrieves the attributes from the first non-null geometric element. + * + * @return the attributes as a CClass; null if no element is found + */ public CClass get_attr() { if (md != null) return md; if (ln != null) return ln; @@ -291,10 +450,14 @@ public CClass get_attr() { if (at != null) return at; if (pg != null) return pg; if (atn != null) return atn; - return null; } + /** + * Retrieves the condition (Cond) associated with the first non-null geometric element. + * + * @return the associated Cond; null if no element is found + */ Cond get_co() { if (md != null) return md.co; if (ln != null) return ln.co; @@ -308,10 +471,14 @@ Cond get_co() { if (at != null) return at.co; if (pg != null) return pg.co; if (atn != null) return atn.co; - return null; } + /** + * Retrieves the step number from the first non-null geometric element that contains it. + * + * @return the step number if found; -1 otherwise + */ public int get_no() { //if (d != null) return d.no; //if (md != null) return md.no; @@ -320,13 +487,18 @@ public int get_no() { //if (tn != null) return tn.no; if (cr != null) return cr.no; //if (as != null) return as.no; -// if (st != null) return st.no; -// if (cg != null) return cg.no; + //if (st != null) return st.no; + //if (cg != null) return cg.no; //if (ra != null) return ra.no; return -1; } - + /** + * Sets the type of the first non-null geometric element to the specified value. + * + * @param t the new type value + * @return 0 after setting the type + */ public int set_type(int t) { if (md != null) md.type = t; @@ -354,7 +526,5 @@ else if (atn != null) atn.type = t; return 0; } - - } diff --git a/src/main/java/gprover/CongSeg.java b/src/main/java/gprover/CongSeg.java index a10b85b8..6f805992 100644 --- a/src/main/java/gprover/CongSeg.java +++ b/src/main/java/gprover/CongSeg.java @@ -1,25 +1,41 @@ /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:00 - * To change this template use File | Settings | File Templates. + * The CongSeg class represents a congruent segment in a geometric proof. + * It includes properties for lemma, condition, points, types, and the next segment. */ package gprover; public class CongSeg extends CClass { + /** The lemma associated with the congruent segment. */ int lemma; + + /** The condition associated with the congruent segment. */ Cond co; + + /** The first point of the segment. */ public int p1; + + /** The second point of the segment. */ public int p2; + + /** The third point of the segment. */ public int p3; + + /** The fourth point of the segment. */ public int p4; - public int t1,t2; + /** The first type of the segment. */ + public int t1; + + /** The second type of the segment. */ + public int t2; + /** The next congruent segment in the list. */ CongSeg nx; + /** + * Constructs a CongSeg object with default values. + */ public CongSeg() { type = lemma = 0; t1 = t2 = 1; diff --git a/src/main/java/gprover/Cons.java b/src/main/java/gprover/Cons.java index c8fdd98d..dd4c5f46 100644 --- a/src/main/java/gprover/Cons.java +++ b/src/main/java/gprover/Cons.java @@ -2,20 +2,41 @@ import wprover.GExpert; +/** + * The Cons class represents a geometric construction in a proof. + * It includes properties for type, points, and descriptions, + * as well as methods for managing and retrieving information about the construction. + */ public class Cons { + /** The maximum length of the points array. */ final public static int MAXLEN = 16; + /** The unique identifier of the construction. */ int id = 0; + + /** The type of the construction. */ public int type = 0; + + /** The number of points in the construction. */ int no = 0; + + /** The flag indicating if the construction is a conclusion. */ boolean conc = false; + /** The array of point identifiers. */ public int[] ps; + + /** The array of point objects. */ public Object[] pss; + /** The string description of the construction. */ private String sd = null; - + /** + * Constructs a Cons object with the specified type. + * + * @param t the type of the construction + */ public Cons(int t) { type = t; ps = new int[MAXLEN]; @@ -24,6 +45,11 @@ public Cons(int t) { conc = false; } + /** + * Constructs a Cons object by copying another Cons object. + * + * @param c the Cons object to copy + */ public Cons(Cons c) { this(c.type); @@ -39,21 +65,41 @@ public Cons(Cons c) { sd = c.sd; } - + /** + * Gets the number of points in the construction. + * + * @return the number of points in the construction + */ int getPts() { for (int i = 0; i < ps.length; i++) if (ps[i] == 0) return i; return ps.length; } + /** + * Sets the unique identifier of the construction. + * + * @param id the unique identifier to set + */ public void setId(int id) { this.id = id; } + /** + * Gets the unique identifier of the construction. + * + * @return the unique identifier of the construction + */ public int getId() { return id; } + /** + * Checks if the construction contains the specified point. + * + * @param pt the point to check + * @return true if the construction contains the specified point, false otherwise + */ public boolean contains(int pt) { for (int i = 0; i < ps.length; i++) if (pt == ps[i]) @@ -61,14 +107,11 @@ public boolean contains(int pt) { return false; } - - public int getPtIndex(int pt) { - for (int i = 0; i < ps.length; i++) - if (pt == ps[i]) - return i; - return -1; - } - + /** + * Gets the last point in the construction. + * + * @return the last point in the construction + */ public int getLastPt() { int pt = 0; for (int i = 0; i < ps.length; i++) @@ -77,6 +120,12 @@ public int getLastPt() { return pt; } + /** + * Constructs a Cons object with the specified type and length. + * + * @param t the type of the construction + * @param len the length of the points array + */ public Cons(int t, int len) { type = t; ps = new int[len + 1]; @@ -84,7 +133,11 @@ public Cons(int t, int len) { no = -1; } - + /** + * Adds a point to the construction. + * + * @param n the point to add + */ public void add_pt(int n) { if (n == 0) return; @@ -92,10 +145,21 @@ public void add_pt(int n) { ps[++no] = n; } + /** + * Adds a point object to the construction. + * + * @param s the point object to add + */ public void add_pt(Object s) { pss[++no] = s; } + /** + * Adds a point to the construction at the specified index. + * + * @param n the point to add + * @param id the index to add the point at + */ public void add_pt(int n, int id) { if (ps.length <= id) { // TODO. Handle this. @@ -105,6 +169,12 @@ public void add_pt(int n, int id) { ps[no = id] = n; } + /** + * Adds a point object to the construction at the specified index. + * + * @param s the point object to add + * @param id the index to add the point object at + */ public void add_pt(Object s, int id) { if (pss.length <= id) { // TODO. Handle this. @@ -114,7 +184,11 @@ public void add_pt(Object s, int id) { pss[no = id] = s; } - + /** + * Returns a string representation of the construction. + * + * @return the string description of the construction + */ public String toString() { if (sd == null) { String s = ""; @@ -137,6 +211,11 @@ public String toString() { return sd; } + /** + * Returns an extended string representation of the construction. + * + * @return the extended string description of the construction + */ public String toStringEx() { if (sd == null) { String s = ""; @@ -156,10 +235,21 @@ public String toStringEx() { return sd; } + /** + * Sets the string description of the construction. + * + * @param s the string description to set + */ public void setText(String s) { sd = s; } + /** + * Gets the print text of the construction. + * + * @param isSelected the flag indicating if the construction is selected + * @return the print text of the construction + */ public String getPrintText(boolean isSelected) { if (sd == null) { String s = ""; @@ -181,41 +271,82 @@ public String getPrintText(boolean isSelected) { return sd; } + /** + * Trims the string to the specified length. + * + * @param st the string to trim + * @param len the length to trim to + * @return the trimmed string + */ public String trim(String st, int len) { if (st.length() > len) return st.substring(0, len) + "..."; return st; } + /** + * Trims the string to the default length. + * + * @param st the string to trim + * @return the trimmed string + */ public String trim(String st) { return trim(st, 32); } + /** + * Revalidates the construction. + */ public void revalidate() { if (this.type == Gib.CO_NANG || this.type == Gib.CO_NSEG) return; sd = null; } - + /** + * Sets the conclusion flag of the construction. + * + * @param r the conclusion flag to set + */ public void set_conc(boolean r) { conc = r; } + /** + * Checks if the construction is a conclusion. + * + * @return true if the construction is a conclusion, false otherwise + */ public boolean is_conc() { return type >= 50 && type < 100 && conc; } + /** + * Gets the point object at the specified index. + * + * @param n the index to get the point object from + * @return the point object at the specified index + */ public Object getPTN(int n) { if (n < 0 || n >= pss.length) return null; return pss[n]; } + /** + * Returns a short string representation of the construction. + * + * @return the short string description of the construction + */ public String toSString() { return CST.getDString(pss, type); } + /** + * Returns a detailed string representation of the construction. + * + * @return the detailed string description of the construction + */ public String toDString() { String s = CST.getDString(pss, type); if (conc) @@ -225,6 +356,11 @@ public String toDString() { return s; } + /** + * Returns a detailed string representation of the construction without trimming. + * + * @return the detailed string description of the construction without trimming + */ public String toDDString() { String s = CST.getDString(pss, type, false); if (conc) @@ -232,6 +368,12 @@ public String toDDString() { return s; } + /** + * Copies the specified Cons object. + * + * @param c the Cons object to copy + * @return the copied Cons object + */ public static Cons copy(Cons c) { Cons c1 = new Cons(c.type, c.no); for (int i = 0; i < c1.no; i++) { @@ -243,8 +385,12 @@ public static Cons copy(Cons c) { return c1; } - - /////////////////////////////////////////////////////////////////// + /** + * Replaces the specified point with another point in the construction. + * + * @param a the point to replace + * @param b the point to replace with + */ public void replace(int a, int b) { for (int i = 0; i <= no; i++) { if (ps[i] == a) @@ -252,6 +398,12 @@ public void replace(int a, int b) { } } + /** + * Checks if the construction is equal to another construction. + * + * @param c the construction to compare + * @return true if the constructions are equal, false otherwise + */ public boolean isEqual(Cons c) { if (c.type != type) return false; @@ -264,6 +416,9 @@ public boolean isEqual(Cons c) { return true; } + /** + * Reorders the points in the construction based on the type. + */ public void reorder() { switch (type) { case Gib.C_O_L: @@ -274,11 +429,9 @@ public void reorder() { case Gib.C_O_P: case Gib.C_O_T: reorder2(); - break; case Gib.C_I_EQ: reorder1(0, 1); - break; case Gib.C_CIRCUM: reorder1(1, 2); @@ -288,6 +441,12 @@ public void reorder() { } } + /** + * Reorders two points in the construction. + * + * @param m the first point index + * @param n the second point index + */ public void reorder1(int m, int n) { if (m == n) return; @@ -298,6 +457,9 @@ public void reorder1(int m, int n) { } } + /** + * Reorders the points in the construction for specific types. + */ public void reorder2() { reorder1(0, 1); reorder1(2, 3); @@ -311,6 +473,12 @@ public void reorder2() { } } + /** + * Gets the point less than the specified point in the construction. + * + * @param n the point to compare + * @return the point less than the specified point + */ public int getLessPt(int n) { int k = 0; @@ -320,5 +488,4 @@ public int getLessPt(int n) { } return k; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/DTerm.java b/src/main/java/gprover/DTerm.java index 2e68d64d..9f5687dc 100644 --- a/src/main/java/gprover/DTerm.java +++ b/src/main/java/gprover/DTerm.java @@ -1,31 +1,39 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-4 - * Time: 11:32:44 - * To change this template use File | Settings | File Templates. + * The DTerm class represents a term in a polynomial with a specific degree. + * It includes properties for the degree, the term itself, the next term in the list, + * and a string representation of the term. */ +public class DTerm { + /** The degree of the term. */ + public int deg; -public class DTerm -{ - public int deg; //degree - public XTerm p; //A term - public DTerm nx; // All next terms. + /** The term itself. */ + public XTerm p; - public String text; + /** The next term in the list. */ + public DTerm nx; - public DTerm() - { - deg = 0; - p = null; - nx = null; - text = null; - } + /** The string representation of the term. */ + public String text; - public String toString() - { - return text; - } + /** + * Constructs a DTerm object with default values. + */ + public DTerm() { + deg = 0; + p = null; + nx = null; + text = null; + } + + /** + * Returns the string representation of the term. + * + * @return the string representation of the term + */ + public String toString() { + return text; + } } diff --git a/src/main/java/gprover/ElTerm.java b/src/main/java/gprover/ElTerm.java index f02878c8..a13901f5 100644 --- a/src/main/java/gprover/ElTerm.java +++ b/src/main/java/gprover/ElTerm.java @@ -3,16 +3,11 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 13:17:41 - * To change this template use File | Settings | File Templates. + * The ElTerm class represents an element term in the geometric theorem + * proving framework. It encapsulates the term type, its associated variable, + * geometric expressions (XTerm instances), conditions, and linked terms. */ public class ElTerm { - final public static int EL_CYCLIC = 11; - final public static int EL_PARA = 2; - final public static int EL_PERP = 3; public int etype = 0; public Var v; public XTerm p1, p2, p; @@ -23,67 +18,95 @@ public class ElTerm { public ElTerm et; - public ElTerm() { - int k = 0; - } + /** + * Constructs an ElTerm object with default values. + */ + public ElTerm() { + int k = 0; + } - public void setText(String s) { - text = s; - } + /** + * Sets the text description of the element term. + * + * @param s the text description to set + */ + public void setText(String s) { + text = s; + } - public String toString() { - return text; - } + /** + * Returns the string representation of the element term. + * + * @return the string representation of the element term + */ + public String toString() { + return text; + } - public Vector getAllxterm() { - Vector v = new Vector(); - v.add(p); + /** + * Gets all XTerm objects associated with the element term. + * + * @return a vector of all XTerm objects + */ + public Vector getAllxterm() { + Vector v = new Vector(); + v.add(p); - XTerm x = p1; - while (x != null) { - v.add(x); - DTerm d = x.ps; - if (d != null) - d = d.nx; - if (d != null) - x = d.p; - else - break; - } - - if (v.size() > 0) { - x = (XTerm) v.get(0); - x.cutMark(); - } - return v; - } + XTerm x = p1; + while (x != null) { + v.add(x); + DTerm d = x.ps; + if (d != null) + d = d.nx; + if (d != null) + x = d.p; + else + break; + } - public int getEType() { - return etype; - } + if (v.size() > 0) { + x = (XTerm) v.get(0); + x.cutMark(); + } + return v; + } - public Vector getAllCond() { - Vector v = new Vector(); - if (co != null) { - Cond c = co; - while (c != null) { - v.add(c); - c = c.nx; + /** + * Gets the type of the element term. + * + * @return the type of the element term + */ + public int getEType() { + return etype; } - } - if (et != null) { - ElTerm e = et; - while (e != null) { - if (e.co != null) { - Cond c = e.co; + + /** + * Gets all Cond objects associated with the element term. + * + * @return a vector of all Cond objects + */ + public Vector getAllCond() { + Vector v = new Vector(); + if (co != null) { + Cond c = co; while (c != null) { v.add(c); c = c.nx; } } - e = e.nx; + if (et != null) { + ElTerm e = et; + while (e != null) { + if (e.co != null) { + Cond c = e.co; + while (c != null) { + v.add(c); + c = c.nx; + } + } + e = e.nx; + } + } + return v; } - } - return v; - } } diff --git a/src/main/java/gprover/Elim.java b/src/main/java/gprover/Elim.java index 0ad28fbe..5d834084 100644 --- a/src/main/java/gprover/Elim.java +++ b/src/main/java/gprover/Elim.java @@ -1,2883 +1,260 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-20 - * Time: 14:41:03 - * To change this template use File | Settings | File Templates. + * The Elim class provides methods for trimming geometric terms under various constraints. + * It extends the Gr class. */ public class Elim extends Gr { - - ElTerm all_elim; - DTerm ds_set, last_ds; - - ElTerm mk_elim(Var v, XTerm p1, XTerm p2) - { - ElTerm v1 = new ElTerm(); - v1.v = v; - v1.p1 = p1; - v1.p2 = p2; - v1.nx = all_elim.nx; - all_elim.nx = v1; - return (v1); - } - - ElTerm lratio_md1(Var var, int y, int u, int v, XTerm p1, XTerm p2, XTerm q1, XTerm q2) - { - if (print_geo) - { - gprint("\nlratio_md1" + y + " " + u + " " + v); - print_var(var, 0); - gprint("\n"); - pprint(p1); - pprint(p2); - pprint(q1); - pprint(q2); - } - if (eq_poly(p2, q2)) - { /*put_p(q2); */ - return (mk_elim(var, pplus(ptimes(geval(var, y, v), p1), - ptimes(geval(var, y, u), q1)), p2)); - } else - { - return (mk_elim(var, pplus(ptimes3(geval(var, y, v), p1, cp_poly(q2)), - ptimes3(geval(var, y, u), q1, cp_poly(p2))), - ptimes(cp_poly(p2), cp_poly(q2)))); - } - } - -//var = (py a y y c) - ElTerm lratio_md2(Var var, int y, int u, int v, XTerm p1, XTerm p2, XTerm q1, XTerm q2) - { - return (mk_elim(var, - pplus3(ptimes(geval(var, y, v), ptimes(cp_poly(p1), cp_poly(q2))), - ptimes(geval(var, y, u), ptimes(cp_poly(q1), cp_poly(p2))), - ptimes(trim_g(v, v, u, u), ptimes(cp_poly(p1), cp_poly(q1)))), - ptimes(cp_poly(p2), cp_poly(q2)))); - } - - - ElTerm pratio_md1(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - - return (mk_elim(var, - pplus(ptimes(geval(var, y, w), cp_poly(p2)), - ptimes(cp_poly(p1), geval1(var, y, v, u))), - cp_poly(p2))); - } - - XTerm geval1(Var var, int y, int v, int u) - { - switch (var.nm) - { - case 2: - case -2: - return (trim_a(v, var.pt[1], u, var.pt[3])); - case 3: - case -3: - return (trim_g(v, var.pt[1], u, var.pt[3])); - case 4: - case -4: - return (trim_vec(v, u)); -/* case 4: case -4: return(pminus(trim_vec(v,0),trim_vec(u,0))); */ - default: - gprint("geval11\n"); - exit(1); - } - return (null); - } - - ElTerm pratio_md2(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(var, - pplus4(ptimes3(geval(var, y, w), cp_poly(p2), cp_poly(p2)), - pminus(ptimes3(geval(var, y, v), cp_poly(p1), cp_poly(p2)), - ptimes3(geval(var, y, u), cp_poly(p1), cp_poly(p2))), - ptimes4(get_n(2L), trim_g(w, u, u, v), cp_poly(p1), cp_poly(p2)), - ptimes3(trim_g(v, v, u, u), cp_poly(p1), pminus(cp_poly(p2), cp_poly(p1)))), - ptimes(cp_poly(p2), cp_poly(p2)))); - } - - - ElTerm pe_v_pratio(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) - { - gprint("pratio: \n"); - pprint(p1); - pprint(p2); - } - switch (var.nm) - { - case 1: - return (pe_r_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 2: - return (pe_a_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 3: - return (pe_g_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 4: - if (w == u) - return (lratio_md1(var, y, u, v, p1, p2, pminus(cp_poly(p2), cp_poly(p1)), cp_poly(p2))); - else - return (pratio_md1(var, y, w, u, v, p1, p2)); - default: - gerror("pe_v_ipp: (" + var.nm + ")" + "is not a proper variable."); - - } - return (null); - } - - ElTerm pe_r_pratio(Var var, int n2, int n1, int d2, int d1, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) gprint("pe_r_pratio: " + n1 + n2 + d1 + d2 + y + w + u + v); - if ((n2 == y) && (d2 == y)) - { - if (xcoll(n1, w, y)) - return (mk_elim(var, - pplus(ptimes(cp_poly(p2), trim_r(n1, w, u, v)), cp_poly(p1)), - pplus(ptimes(cp_poly(p2), trim_r(d1, w, u, v)), cp_poly(p1)))); - else if (xcoll(w, u, v)) - return (mk_elim(var, trim_a(n1, n1, u, v), trim_a(d1, d1, u, v))); - else - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(var, - pplus(ptimes(cp_poly(p2), trim_r(n1, w, u, v)), cp_poly(p1)), - ptimes(cp_poly(p2), trim_r(d1, d2, u, v)))); - else if (xcoll(w, u, v)) - return (mk_elim(var, trim_a(n1, n1, u, v), trim_a(d1, u, d2, v))); - else - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_pratio(var, d2, d1, n2, n1, y, w, u, v, p1, p2))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_pratio(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e1; - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(w, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), - pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), - cp_poly(p1))), - p2)); - } - - if ((w == u) && ((p1.var == null && p2.var == null))) - { - e1 = lratio_md1(var, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - } else - e1 = pratio_md1(var, y, w, u, v, p1, p2); - return (e1); - } - - ElTerm pe_g_pratio(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e1; - int n; - XTerm q1, q2; - Var v1; - - q1 = get_n(1L); - q2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - q1 = ptimes(q1, pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), cp_poly(p1))); - q2 = ptimes(q2, cp_poly(p2)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - q1 = ptimes(q1, pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), cp_poly(p1))); - q2 = ptimes(q2, cp_poly(p2)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(var, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - else - e1 = pratio_md2(var, y, w, u, v, p1, p2); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u) - e1 = lratio_md1(v1, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - else - e1 = pratio_md1(v1, y, w, u, v, p1, p2); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, q1); - e1.p2 = ptimes(e1.p2, q2); - return (e1); - } - - ElTerm pe_v_ipp(Var var, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (w == u && w > v) - { - w = v; - v = u; - u = w; - } - if (r == p && r > q) - { - r = q; - q = p; - p = r; - } - if (r > w) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - switch (var.nm) - { - case 1: - return (pe_r_ipp(var, var.pt[1], var.pt[0], var.pt[3], var.pt[2], y, w, u, v, r, p, q)); - case 2: - return (pe_a_ipp(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, r, p, q)); - case 3: - return (pe_g_ipp(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, r, p, q)); - case 4: - if (w == u) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - else - return (pratio_md1(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q))); - default: - gerror("pe_v_ipp: (" + var.nm + ")" + "is not a proper variable."); - } - return (null); - } - - ElTerm pe_r_ipp(Var var, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (print_geo) - gprint("pe_r_ipp: " + n1 + n2 + d1 + d2 + y + w + u + v + r + p + q); - if (xpara(n1, n2, u, v)) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - if ((n2 == y) && d2 == y) - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - else if (n2 == y) - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - else if (d2 == y) - return (mk_elim(var, trim_a(n1, u, n2, v), trim_a(d1, u, w, v))); - else - exit(1); - return (null); - } - - ElTerm pe_a_ipp(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - - if (r == n2 || r == n3 || r == n4) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(w, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, p, q)) - { - return (mk_elim(var, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, q, r, p)), trim_a(v, q, u, p))); - } - if (n3 == n4 && xpara(y, n2, p, q)) - { - n3 = n2; - } - if (xpara(y, n3, p, q)) - { - return (mk_elim(var, ptimes(trim_a(p, n2, q, n4), trim_a(n3, u, w, v)), trim_a(q, u, p, v))); - } - - if (xcoll(w, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4))) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - if (xcoll(r, p, q) && (xpara(p, n3, n2, n4) || xpara(q, n3, n2, n4))) - return (lratio_md1(var, y, p, q, - trim_a(p, u, w, v), trim_a(p, u, q, v), - trim_a(q, v, w, u), trim_a(p, u, q, v))); - if (w == u) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - return (pratio_md1(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q))); - } - - ElTerm pe_g_ipp(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, p, q)) - { - n2 = r; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n2 == y && xpara(n2, n4, p, q)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, w, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, w, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - else - e1 = pratio_md2(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(-3, n1, n2, n3, n4); - if (w == u) - { - e1 = lratio_md1(v1, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - } else - { - e1 = pratio_md1(v1, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q)); - } - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ElTerm pe_r_ill(Var var, int n1, int n2, int d1, int d2, int y, int u, int v, int i, int j) - { - int n0; - - if (n2 == y) - { - if (xcoll(n1, u, v)) - { - n0 = i; - i = u; - u = n0; - n0 = j; - j = v; - v = n0; - } - if (d2 == y) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ill(var, d1, d2, n1, n2, y, u, v, i, j))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_ill(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int i, int j) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, i, j)) - { - return (mk_elim(var, trim_a(i, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, i, j, j)), trim_a(v, i, u, j))); - } - if (n3 == n4 && xcoll(i, j, n2)) - { - n3 = n2; - } - if (xcoll(i, j, n3)) - { - return (mk_elim(var, ptimes(trim_a(i, n2, j, n4), trim_a(n3, u, v, v)), trim_a(j, u, i, v))); - } - - if (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)) - { - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - if (xpara(i, n3, n2, n4) || xpara(j, n3, n2, n4)) - { - return (lratio_md1(var, y, i, j, - trim_a(i, u, v, v), trim_a(i, u, j, v), - trim_a(j, v, u, u), trim_a(i, u, j, v))); - } - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - - ElTerm pe_g_ill(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int i, int j) - { - int n; - ElTerm e1; - XTerm p1, p2; - Var v1; - - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, i, j)) - { - n1 = n2; - n2 = i; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, i, j)) - { - n1 = n2; - n2 = i; - n = n3; - n3 = n4; - n4 = n; - } - - - if (n2 == y && xcoll(u, v, n4)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, i, j, j)); - p2 = ptimes(p2, trim_a(v, i, u, j)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, i, j, j)); - p2 = ptimes(p2, trim_a(v, i, u, j)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && xcoll(i, j, n4)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(i, j, n3)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(j, u, i, v)); - n1 = n2; - n3 = n4; - n2 = i; - n4 = j; - } - if (n1 == y && xcoll(i, j, n3)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(j, u, i, v)); - n1 = n2; - n3 = n4; - n2 = i; - n4 = j; - } - - if (n2 == y && n3 == y) - { - e1 = lratio_md2(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j)); - } else if (n1 == y) - { - if (n3 == i || n3 == j || xperp(i, n3, n2, n4) || xperp(j, n3, n2, n4)) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j)); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ElTerm pe_vec_ill(Var var, int n1, int n2, int y, int u, int v, int i, int j) - { - int n; - - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - - ElTerm pe_r_ilp(Var var, int n1, int n2, int d1, int d2, int y, int u, int v, int r, int p, int q) - { - - if ((n2 == y) && (d2 == y)) - { - if (xcoll(n1, u, v)) - return (mk_elim(var, trim_a(n1, p, r, q), trim_a(d1, p, r, q))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - } - if (n2 == y) - { - if (xcoll(n1, u, v)) - return (mk_elim(var, trim_a(n1, p, r, q), trim_a(d1, p, d2, q))); - else if (xcoll(d2, u, v)) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - else if (xcoll(d1, u, v)) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d2, v, u, u))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ilp(var, d1, d2, n1, n2, y, u, v, r, p, q))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_ilp(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int r, int p, int q) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, p, q)) - { - return (mk_elim(var, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, p, r, q)), trim_a(v, p, u, q))); - } - if (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)) - { - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - } - - if (n3 == n4 && xpara(y, n2, p, q)) - { - n3 = n2; - } - if (xpara(y, n3, p, q)) - { - return (mk_elim(var, ptimes(trim_a(p, n2, q, n4), trim_a(n3, u, v, v)), trim_a(q, u, p, v))); - } - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - } - - ElTerm pe_g_ilp(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int r, int p, int q) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - if (v < u) - { - n = u; - u = v; - v = n; - } - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n2 == y && n3 == y) - { - e1 = lratio_md2(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ////////////////////////////////////////// - -/* trim functions */ -/* -xterm *mk_trim (v) -var *v; -{ var *v1; - int i; - - v1 = all_var.nx; - while ((v1 != null) && !(eq_var(v,v1))) { v1 = v1.nx;} - if (v1 == null) - { v1=(var *)calloc(1,sizeof(var)); - v1.nm = v.nm; - for (i=0;i<9;i++) v1.pt[i] = v.pt[i]; - v1.nx = null; - last_var.nx = v1; last_var = v1; - } - return(get_m(v1)); -} -*/ - ///////////////////////////////////////////////////////////////from area.cpp trim function. - XTerm geval(Var var, int y, int p) - { - int k; - int i, pt[]; - pt = new int[9]; - - for (i = 0; i < 4; i++) - if (var.pt[i] == y) - pt[i] = p; - else - pt[i] = var.pt[i]; - switch (var.nm) - { - case 1: - case -1: - return (trim_r(pt[0], pt[1], pt[2], pt[3])); - case 2: - case -2: - return (trim_a(pt[0], pt[1], pt[2], pt[3])); - case 3: - case -3: - return (trim_g(pt[0], pt[1], pt[2], pt[3])); - case 4: - case -4: - return (trim_vec(pt[0], pt[1])); - default: - exit(1); - } - return (null); - } - - - XTerm trim_r(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 == p2) return (pzero()); - if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); - if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); - if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(1, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); - - } - - XTerm trim_a(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (xpara(p1, p3, p2, p4)) return (pzero()); - if (xcoll(p1, p2, p3)) - { - p2 = p1; - } else if (xcoll(p4, p2, p3)) - { - p3 = p4; - } else if (xcoll(p4, p1, p3)) - { - p4 = p3; - } else if (xcoll(p4, p2, p1)) - { - p1 = p4; - } - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - p2 = p3; - p3 = p4; - } else if (p2 == p3) - { - p3 = p4; - } - - if (sn == 1) - return (get_m(mk_var(2, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); - } - - XTerm trim_g(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xperp(p1, p3, p2, p4)) return (get_n(0L)); - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - p = p3; - p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - sn *= -1; - p1 = p3; - p3 = p2; - } else if (p3 == p4) - { - sn *= -1; - p4 = p2; - p2 = p3; - } - //The largest index is either p1 or p2 - if (sn == 1) - return (get_m(mk_var(3, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); - } - - XTerm trim_f(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (xcoll4(p1, p2, p3, p4)) return (pzero()); - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - p = p3; - p3 = p4; - p4 = p; - } - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - p = p2; - p2 = p4; - p4 = p; - } else if ((p1 == p3) && (p2 < p4)) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(10, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); - } - - XTerm trim_fl(LLine l1, LLine l2) - { - if (l1 == l2) return (pzero()); - return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); - } - - XTerm trim_vec(int p1, int p2) - { - if (p2 == 0) - { - return (get_m(mk_var(4, p1, 0, 0, 0))); - } - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); - return (get_m(mk_var(4, p1, p2, 0, 0))); - } - - XTerm trim_l(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(5, p2, p1, 0, 0)))); - return (get_m(mk_var(5, p1, p2, 0, 0))); - } - - XTerm trim_s(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(6, p2, p1, 0, 0)))); - return (get_m(mk_var(6, p1, p2, 0, 0))); - } - - XTerm trim_c(int p1, int p2) - { - if (p1 == p2) return (get_n(1L)); - if (p1 < p2) return (neg_poly(get_m(mk_var(7, p2, p1, 0, 0)))); - return (get_m(mk_var(7, p1, p2, 0, 0))); - } - /////////////////////////////////////////////////////////////////////////////////////////////from elimt; - - ElTerm tratio_a_md1(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), geval(v_a, y, w)), - ptimes(cp_poly(p1), trim_g(v, v_a.pt[1], u, v_a.pt[3]))), - ptimes(get_n(4L), cp_poly(p2)))); - } - - ElTerm tratio_g_md1(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus(ptimes(cp_poly(p2), geval(v_a, y, w)), - ptimes3(get_n(4L), cp_poly(p1), trim_a(u, v_a.pt[1], v, v_a.pt[3]))), - cp_poly(p2))); - } - - ElTerm tratio_md2(Var v_a, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus3(ptimes3(cp_poly(p2), cp_poly(p2), geval(v_a, y, w)), - ptimes4(get_n(-4L), cp_poly(p1), cp_poly(p2), - pplus(trim_a(n3, u, w, v), trim_a(n4, u, w, v))), - ptimes3(cp_poly(p1), cp_poly(p1), trim_g(v, u, u, v))), - ptimes(cp_poly(p2), cp_poly(p2)))); - } - - ElTerm pe_v_tratio(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) - { //printf("pe_v_tratio. %s %s %s %s\n",ANAME(y),ANAME(w),ANAME(u),ANAME(v)); - print_var(v_a, 0); - gprint("\n"); - pprint(p1); - pprint(p2); - } - switch (v_a.nm) - { - case 1: - return (pe_r_tratio(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, p1, p2)); - case 2: - return (pe_a_tratio(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, p1, p2)); - case 3: - return (pe_g_tratio(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, p1, p2)); - default: - gerror("pe_v_tratio: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int r, int p, int q, XTerm p1, XTerm p2) - { - if (n2 == y && n4 == y) - { - if (xcoll(n1, r, y)) - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), trim_a(n1, p, r, q)), - ptimes(cp_poly(p1), trim_g(p, p, q, q))), - pplus(ptimes3(get_n(4L), p2, trim_a(n3, p, r, q)), - ptimes(p1, trim_g(p, p, q, q))))); - else - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(n3, p, r, q))); - } else if (n2 == y) - { - if (xcoll(n1, r, y)) - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), trim_a(n1, p, r, q)), - ptimes(cp_poly(p1), trim_g(p, p, q, q))), - ptimes3(get_n(4L), p2, trim_a(n3, p, n4, q)))); - else - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(n3, p, n4, q))); - } else if (n3 == y) - { - return (rev_elim(pe_r_tratio(v_a, n3, n4, n1, n2, y, r, p, q, p1, p2))); - } else - gerror("pe_r_taio"); - return (null); - } - - ElTerm pe_a_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (xperp(n2, n4, u, v)) return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - return (tratio_a_md1(v_a, y, w, u, v, p1, p2)); - } - - ElTerm pe_g_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e = null; - if (n1 == y && n2 != y) - { - if (xpara(n2, n4, u, v)) return (mk_elim(v_a, trim_g(w, n2, n3, n4), get_n(1L))); - return (tratio_g_md1(v_a, y, w, u, v, p1, p2)); - } - - - if (n2 == y && n3 == y) - { - if (n1 == w && n4 == w) - e = mk_elim(v_a, ptimes3(cp_poly(p1), cp_poly(p1), trim_g(v, u, u, v)), ppower(p2, 2)); - else - e = tratio_md2(v_a, n1, n4, y, w, u, v, p1, p2); - } - return (e); - } - - - ElTerm pe_a_itt1(Var v_a, int n1, int n2, int n3, int y, int o, int u, int v) - { - int n; - if ((n1 == u && n2 == v) || (n1 == v && n2 == u)) - return (mk_elim(v_a, ptimes(trim_g(o, n1, n1, n2), trim_g(o, n2, n2, n1)), - ptimes(get_n(-16L), trim_a(n1, n2, o, o)))); - if ((n1 == o && n2 == v) || (n1 == v && n2 == o)) - { - n = u; - u = v; - v = n; - } - if ((n1 == o && n2 == u) || (n1 == u && n2 == o)) - return (mk_elim(v_a, ptimes(trim_g(n1, n2, n2, n1), trim_g(n1, v, v, n2)), - ptimes(get_n(16L), trim_a(n1, n2, v, v)))); - return (null); - } - - ElTerm pe_a_itt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - ElTerm e1; - if (xperp(n2, n4, u, v)) return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - if (xperp(n2, n4, p, q)) return (mk_elim(v_a, trim_a(r, n2, n3, n4), get_n(1L))); - - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (n3 == n4 && w == r && w == u && r == p) - { - e1 = pe_a_itt1(v_a, n2, n3, n1, y, w, v, q); - if (e1 != null) return (e1); - } - - if (n3 == n4 && xcoll(r, n2, n3)) - { - n3 = n2; - } - if (xpara(r, n3, n2, n4)) - return (tratio_a_md1(v_a, y, r, p, q, trim_g(r, u, w, v), ptimes(get_n(-4L), trim_a(p, u, q, v)))); - return (tratio_a_md1(v_a, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q)))); - } - - - ElTerm pe_g_itt1(Var v_a, int n1, int n2, int n3, int y, int o, int u, int v) - { - int n; - if ((n1 == u && n3 == v) || (n1 == v && n3 == u)) - { - return (mk_elim(v_a, ptimes3(trim_g(u, o, o, v), trim_g(o, u, u, v), trim_g(o, v, v, u)), - ptimes3(get_n(-16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - if ((n1 == o && n3 == v) || (n1 == v && n3 == o) || (n1 == v && n3 == v)) - { - n = u; - u = v; - v = n; - } - if ((n1 == o && n3 == u) || (n1 == u && n3 == o) || (n1 == u && n3 == u)) - { - return (mk_elim(v_a, ptimes3(trim_g(u, o, o, u), trim_g(o, v, v, u), trim_g(o, v, v, u)), - ptimes3(get_n(16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - if (n1 == o && n3 == o) - { - return (mk_elim(v_a, ptimes3(trim_g(v, o, o, v), trim_g(u, o, o, u), trim_g(v, u, u, v)), - ptimes3(get_n(16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - return (null); - } - - ElTerm pe_g_itt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - ElTerm e1; - int n; - - if (n1 == y) - { - if (xpara(n2, n4, u, v)) return (mk_elim(v_a, trim_g(w, n2, n3, n4), get_n(1L))); - if (xpara(n2, n4, p, q)) return (mk_elim(v_a, trim_g(r, n2, n3, n4), get_n(1L))); - if (xperp(r, n3, n2, n4)) - return (tratio_g_md1(v_a, y, r, p, q, trim_g(r, u, w, v), ptimes(get_n(-4L), trim_a(p, u, q, v)))); - return (tratio_g_md1(v_a, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q)))); - } - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - - int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - - if (n2 == y && n3 == y && w == r && w == u && r == p) - { - return (pe_g_itt1(v_a, n1, n2, n4, y, w, v, q)); - } - - if (n2 == y && n3 == y) - e1 = tratio_md2(v_a, n1, n4, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q))); - else - return (null); - return e1; - - } - -/* -el_term pe_r_itt (v_a,n1,n2,n3,n4,y,w,u,v,r,p,q) -var v_a; -int n1,n2,n3,n4,y,w,u,v,r,p,q; -{ return(null);} - -*/ - ElTerm pe_v_ipt(Var v_a, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (w == u && w > v) - { - w = v; - v = u; - u = w; - } - switch (v_a.nm) - { - case 1: - return (pe_r_ipt(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, r, p, q)); - - case 2: - return (pe_a_ipt(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, r, p, q)); - case 3: - return (pe_g_ipt(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, r, p, q)); - case 4: - if (w == u) - return (lratio_md1(v_a, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q))); - return (pratio_md1(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q))); - default: - gerror("pe_v_ipt: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_ipt(Var v_a, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int r, int p, int q) - { - if (n2 == y && d2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(d1, p, r, q))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(d1, p, d2, q))); - else if (xcoll(n2, p, q) && xcoll(d2, p, q)) - { - return (mk_elim(v_a, trim_a(n1, p, p, q), trim_a(d1, p, p, q))); - } else if (xcoll(n2, p, q) && d2 != y && xcoll(d1, p, q)) - { - return (mk_elim(v_a, trim_a(n1, p, p, q), trim_a(d2, q, q, p))); - } else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ipt(v_a, d1, d2, n1, n2, y, w, u, v, r, p, q))); - } else - exit(1); - return (null); - } - - ElTerm pe_a_ipt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - } - if (xperp(n2, n4, p, q)) - { - return (mk_elim(v_a, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(v_a, ptimes(trim_a(u, n2, v, n4), trim_g(n3, q, r, p)), trim_g(v, q, u, p))); - } - if (w == u || (xcoll(y, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)))) - return (lratio_md1(v_a, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q))); - return (pratio_md1(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q))); - } - - ElTerm pe_g_ipt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - ElTerm e1; - XTerm p1, p2; - Var v1; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - - if (xcoll(y, p, q) && n2 == y && n3 == y && n1 == r && n4 == r) - { - e1 = mk_elim(v_a, ptimes3(get_n(16L), trim_a(r, p, q, q), trim_a(r, p, q, q)), trim_g(p, q, q, p)); - return e1; - } - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - - if (n1 == y && xpara(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, p, q)) - { - n2 = r; - } - if (n1 == y && xpara(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, p, q)) - { - n2 = r; - } - - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_g(n3, p, r, q)); - p2 = ptimes(p2, trim_g(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_g(n3, p, r, q)); - p2 = ptimes(p2, trim_g(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - if (xperp(n1, n3, p, q) && xperp(n2, n4, p, q)) - { - e1 = mk_elim(v_a, - ptimes4(get_n(-16L), trim_a(n3, u, w, v), trim_a(n4, u, w, v), trim_g(p, p, q, q)), - ptimes(trim_g(p, u, q, v), trim_g(p, u, q, v))); - } else - e1 = pratio_md2(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u || (xcoll(y, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)))) - e1 = lratio_md1(v1, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q)); - else - e1 = pratio_md1(v1, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if (e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - ElTerm pe_v_ipc(Var v_a, int y, int w, int u, int v, int o, int p) - { - if (print_geo) gprint("\nCP " + " " + y + " " + w + " " + u + " " + v + " " + o + " " + p); - switch (v_a.nm) - { - case 1: - return (pe_r_ipc(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, o, p)); - case 2: - return (pe_a_ipc(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, o, p)); - case 3: - return (pe_g_ipc(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, o, p)); - case 4: - if (w == u) - return (lratio_md1(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v))); - return (pratio_md1(v_a, y, w, u, v, pplus(trim_g(w, u, o, v), trim_g(w, u, o, v)), trim_g(u, u, v, v))); - default: - gerror("pe_v_ipc: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_ipc(Var v_a, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int o, int p) - { - if (print_geo) gprint("\nr_icp: " + " " + y + " " + w + " " + u + " " + v + " " + o + " " + p); - if (w != p) gerror("pe_r_ipc"); - if (n2 == y && d2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, - pplus(trim_g(n1, u, o, v), trim_g(w, u, o, v)), - pplus(trim_g(d1, u, o, v), trim_g(w, u, o, v)))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, pplus(trim_g(n1, u, o, v), trim_g(w, u, o, v)), trim_g(d1, u, d2, v))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ipc(v_a, d1, d2, n1, n2, y, w, u, v, o, p))); - } else - exit(1); - return (null); - } - - ElTerm pe_a_ipc(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int o, int p) - { - if (w != p) gerror("pe_r_ipc"); - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && n2 == w) - { - n3 = n2; - } - if (n3 == w) - return (mk_elim(v_a, - ptimes3(get_n(2), trim_g(w, v, o, u), trim_a(u, n2, v, n4)), - trim_g(u, u, v, v))); - if (n3 == n4 && xpara(n1, n2, u, v)) - { - n3 = n2; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - return (mk_elim(v_a, - ptimes(pminus(trim_g(n3, o, o, n3), trim_g(w, o, o, w)), trim_a(u, n2, v, n4)), - trim_g(u, n3, v, w))); - } - if (w == u) - return (lratio_md1(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v))); - return (pratio_md1(v_a, y, w, u, v, pplus(trim_g(w, u, o, v), trim_g(w, u, o, v)), trim_g(u, u, v, v))); - } - - - ElTerm pe_g_ipc(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int o, int p) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - ElTerm e; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - if (n2 == y && n3 == y && n1 == o && n4 == o) - { - e1 = mk_elim(v_a, trim_g(n3, p, p, n4), get_n(1L)); - return (e1); - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && n4 == w) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && n3 == w) - { - p1 = ptimes3(p1, get_n(2), trim_g(w, v, o, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && n3 == w) - { - p1 = ptimes3(p1, get_n(2), trim_g(w, v, o, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } -/* if (n2 == y && xpara(n2,n4,u,v)) {n=n1;n1=n2;n2=n; n=n3;n3=n4;n4=n; } - if (n1 == y && xpara(n1,n3,u,v)) - { p1 = ptimes(p1,pminus(trim_g(n3,o,o,n3),trim_g(w,o,o,w))); - p2 = ptimes(p2,trim_g(u,n3,v,w)); - n1=n2;n3=n4;n2=u,n4=v; - } - if (n1 == y && xpara(n1,n3,u,v)) - { p1 = ptimes(p1,pminus(trim_g(n3,o,o,n3),trim_g(w,o,o,w))); - p2 = ptimes(p2,trim_g(u,n3,v,w)); - n1=n2;n3=n4;n2=u,n4=v; - } -*/ - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v)); - else - e1 = pratio_md2(v_a, y, w, u, v, ptimes(get_n(2L), trim_g(w, u, o, v)), trim_g(u, u, v, v)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u) - e1 = lratio_md1(v1, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v)); - else - e1 = pratio_md1(v1, y, w, u, v, ptimes(get_n(2L), trim_g(w, u, o, v)), trim_g(u, u, v, v)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if (e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - - ElTerm pe_r_foot(Var v_a, int n1, int n2, int d1, int d2, int y, int p, int u, int v) - { - int n; - ElTerm e1 = null; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (print_geo) gprint("pe_r_foot: " + " " + n1 + " " + n2 + " " + d1 + " " + d2 + " " + y + " " + p + " " + u + " " + v); - if (n2 == y) - { - if (xcoll(d2, u, v) && xperp(d1, d2, u, v)) - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, v, v)); - else if (d2 == y) - { - if (xcoll(n1, u, v)) - { - if (u > n1 && u > d1) - e1 = mk_elim(v_a, trim_g(n1, n1, p, d1), trim_g(d1, n1, p, d1)); - else - e1 = mk_elim(v_a, trim_g(n1, u, p, v), trim_g(d1, u, p, v)); - } else - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, v, v)); - } else if (xcoll(n1, u, v)) - { - e1 = mk_elim(v_a, trim_g(n1, u, p, v), trim_g(d1, u, d2, v)); - } else - { - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, d2, v)); - } - } else if (d2 == y) - { - e1 = rev_elim(pe_r_foot(v_a, d1, d2, n1, n2, y, p, u, v)); - } else - gerror("pe_r_foot"); - return (e1); - } - - ElTerm pe_a_foot(Var v_a, int n1, int n2, int n3, int n4, int y, int p, int u, int v) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (xperp(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(p, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(v_a, ptimes(trim_a(u, n2, v, n4), trim_g(n3, u, p, v)), trim_g(v, u, u, v))); - } - return (lratio_md1(v_a, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u))); - } - - ElTerm pe_g_foot(Var v_a, int n1, int n2, int n3, int n4, int y, int p, int u, int v) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - if (print_geo) gprint("pe_g_foot: " + " " + n1 + " " + n2 + " " + n3 + " " + n4 + " " + y + " " + p + " " + u + " " + v); - if (v < u) - { - n = u; - u = v; - v = n; - } - - if (n2 == y && n3 == y && n1 == p && n4 == p) - { - e1 = mk_elim(v_a, ptimes(get_n(-16L), ptimes(trim_a(p, u, v, v), trim_a(p, u, v, v))), - trim_g(u, u, v, v)); - return (e1); - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = u; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n2, n4, u, v)) - { - n1 = n2; - n2 = p; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, u, v)) - { - n2 = p; - } - if (n1 == y && xpara(n2, n4, u, v)) - { - n1 = n2; - n2 = p; - n = n3; - n3 = n4; - n4 = n; - } - if (print_geo) gprint("pe_g_foot: " + " " + n1 + " " + n2 + " " + n3 + " " + n4 + " " + y + " " + p + " " + u + " " + v); - - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_g(n3, v, p, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_g(n3, v, p, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - e1 = lratio_md2(v_a, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if(e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - - ////////////////////////////////////////////////elimm.cpp - XTerm trim_fa(int p1, int p2, int p3) -//int p1,p2,p3; - { - if (xcoll(p1, p2, p3)) return (pzero()); - if ((p1 == 3 && p2 == 2) || (p1 == 2 && p2 == 3)) return (trim_a(p1, p2, p3, p3)); - return (get_m(mk_var(-2, p1, p2, p3, p3))); - } - - XTerm fpt_a(int n1, int n2, int n3) -//int n1,n2,n3; - { - XTerm p1; - p1 = ptimes(trim_fa(n1, 2, 1), trim_fa(n2, 3, 1)); - p1 = pplus(p1, ptimes(trim_fa(n2, 2, 1), trim_fa(n3, 3, 1))); - p1 = pplus(p1, ptimes(trim_fa(n3, 2, 1), trim_fa(n1, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n3, 2, 1), trim_fa(n2, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n2, 2, 1), trim_fa(n1, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n1, 2, 1), trim_fa(n3, 3, 1))); - return (p1); - } - - ElTerm pe_a_fpt(Var v_a, int n1, int n2, int n3, int n4) -//var v_a; -//int n1,n2,n3,n4; + /** + * Trims a ratio geometric term based on four point parameters. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed ratio term as an XTerm + */ + XTerm trim_r(int p1, int p2, int p3, int p4) { - XTerm p0, p1, p2; - if (n3 == n4 && n3 == 1 && (n2 == 2 || n2 == 3)) + int p; + char sn = 1; + /* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ + if (p1 == p2) return (pzero()); + if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); + if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); + if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); + if (p1 < p2) { - return (mk_elim(v_a, get_m(mk_var(-2, n1, n2, n3, n4)), get_n(1L))); + sn *= (char) -1; + p = p1; + p1 = p2; + p2 = p; } - if (n3 == n4 && n2 == 3 && n3 == 2) + if (p3 < p4) { - p1 = pminus(trim_a(3, 2, 1, 1), trim_fa(n1, 2, 1)); - p1 = pplus(p1, trim_fa(n1, 3, 1)); - return (mk_elim(v_a, p1, get_n(1L))); + sn *= (char) -1; + p = p3; + p3 = p4; + p4 = p; } - - if (n3 == n4) - p1 = fpt_a(n1, n2, n3); - else - p1 = pplus(fpt_a(n1, n2, n3), fpt_a(n1, n3, n4)); - p0 = trim_a(1, 2, 3, 3); - p2 = pdiv(cp_poly(p1), p0); - if (p2 == null) return (mk_elim(v_a, p1, p0)); - put_p(p1); - put_p(p0); - return (mk_elim(v_a, p2, get_n(1L))); - } - - ElTerm pe_v_fpt(Var v, int pt) -//var v; -//int pt; - { - ElTerm e1 = null; - if (v.nm == 2) e1 = pe_a_fpt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3]); - return (e1); - } - - XTerm x(int n) - { - if (n == 1 || n == 2) return (get_n(0L)); - String s = "x_" + n; - return (get_m(mk_svar(s.toCharArray()))); - } - - XTerm y(int n) - { - if (n == 1) return (get_n(0L)); - String s = "y_" + n; - return (get_m(mk_svar(s.toCharArray()))); - } - - XTerm area_t(int n1, int n2, int n3) - { - return (pplus3(pminus(ptimes(x(n1), y(n2)), ptimes(x(n2), y(n1))), - pminus(ptimes(x(n2), y(n3)), ptimes(x(n3), y(n2))), - pminus(ptimes(x(n3), y(n1)), ptimes(x(n1), y(n3))))); - } - - XTerm area_q(int n1, int n2, int n3, int n4) - { - return (pplus(area_t(n1, n2, n3), area_t(n1, n3, n4))); - } - - XTerm dis_xy(int n1, int n2) -//int n1,n2; - { - if (n1 == n2) - return (get_n(0L)); + if (sn == 1) + return (get_m(mk_var(1, p1, p2, p3, p4))); else - return (pplus(ppower(pminus(x(n1), x(n2)), 2), ppower(pminus(y(n1), y(n2)), 2))); - } - - XTerm py_q(int n1, int n2, int n3, int n4) -//int n1,n2,n3,n4; - { - return (pminus(pplus(dis_xy(n1, n2), dis_xy(n3, n4)), - pplus(dis_xy(n2, n3), dis_xy(n4, n1)))); + return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); } - XTerm oarea(int p1, int p2, int p3) -//int p1,p2,p3; + /** + * Trims an angle geometric term based on four point parameters. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed angle term as an XTerm + */ + XTerm trim_a(int p1, int p2, int p3, int p4) { - int n; - if (xcir2(p2, p1, p3)) - { - n = p1; - p1 = p2; - p2 = p3; - p3 = n; - } - if (xcir2(p3, p1, p2)) + int p; + char sn = 1; + if (xpara(p1, p3, p2, p4)) return (pzero()); + if (xcoll(p1, p2, p3)) { - n = p1; - p1 = p3; - p3 = p2; - p2 = n; - } - return (ptimes4(get_m(mk_svar("\\d".toCharArray())), get_m(mk_svar("\\d".toCharArray())), trim_s(p2, p3), trim_c(p2, p3))); - } - - XTerm opy(int p1, int p2, int p3) - { - if (p1 == p2) return (pzero()); - if (p3 == p2) return (pzero()); - if (xcir2(p1, p2, p3)) return (ptimes3(get_n(2L), trim_l(p2, p3), trim_l(p2, p3))); - if (xcir2(p3, p2, p1)) return (ptimes3(get_n(2L), trim_l(p2, p1), trim_l(p2, p1))); - return (pminus(ptimes(get_m(mk_svar("\\d".toCharArray())), get_m(mk_svar("\\d".toCharArray()))), - ptimes3(get_n(2L), trim_l(p1, p3), trim_l(p1, p3)))); - } - - ElTerm pe_circle(Var v_a, int p1, int p2, int p3, int p4) - { - int n; - if (v_a.nm == 2) + p2 = p1; + } else if (xcoll(p4, p2, p3)) { - if (xcir4(0, p1, p2, p3, p4)) - return (mk_elim(v_a, - pminus(ptimes3(trim_l(p1, p2), trim_l(p2, p4), trim_l(p4, p1)), - ptimes3(trim_l(p3, p2), trim_l(p2, p4), trim_l(p4, p3))), - ptimes(get_n(2L), get_m(mk_svar("\\d".toCharArray()))))); - else if (p1 == p2) - return (mk_elim(v_a, oarea(p1, p3, p4), get_n(4L))); - else if (xcir3(p1, p2, p3, p4) || xcir3(p3, p1, p2, p4)) - return (mk_elim(v_a, pplus(oarea(p1, p2, p3), oarea(p1, p3, p4)), get_n(4L))); - else - return (mk_elim(v_a, pplus(oarea(p2, p3, p4), oarea(p2, p4, p1)), get_n(4L))); - } - if (v_a.nm == 3) + p3 = p4; + } else if (xcoll(p4, p1, p3)) { - if (p3 == p4) - { - n = p1; - p1 = p3; - p3 = n; - n = p2; - p2 = p4; - p4 = n; - } - if (xcir4(0, p1, p2, p3, p4)) - return (mk_elim(v_a, - pminus(ptimes4(get_n(2L), trim_l(p2, p1), trim_l(p2, p4), trim_c(p1, p4)), - ptimes4(get_n(2L), trim_l(p2, p3), trim_l(p2, p4), trim_c(p3, p4))), - get_n(1L))); - else if (p2 == p3) - return (mk_elim(v_a, opy(p1, p2, p4), get_n(2L))); - else if (xcir3(p2, p1, p3, p4) || xcir3(p4, p1, p2, p3)) - return (mk_elim(v_a, pminus(opy(p1, p2, p4), opy(p3, p2, p4)), get_n(2L))); - else - return (mk_elim(v_a, pminus(opy(p2, p1, p3), opy(p4, p1, p3)), get_n(2L))); - } - gerror("pe_circle"); - return (null); - } - - XTerm sc(int n) -//int n; - { - if (n == 1) return (get_n(0L)); - return (get_m(mk_var(16, n, 0, 0, 0))); - } - - XTerm cc(int n) -//int n; - { - if (n == 1) return (get_n(1L)); - return (get_m(mk_var(17, n, 0, 0, 0))); - } - - ElTerm pe_sc(Var v_a, int p1, int p2) -//var v_a; -//int p1,p2; - { - if (v_a.nm == 6) + p4 = p3; + } else if (xcoll(p4, p2, p1)) { - return (mk_elim(v_a, pminus(ptimes(sc(p2), cc(p1)), ptimes(sc(p1), cc(p2))), get_n(1L))); + p1 = p4; } - if (v_a.nm == 7) + if (p1 < p3) { - return (mk_elim(v_a, pplus(ptimes(cc(p1), cc(p2)), ptimes(sc(p2), sc(p1))), get_n(1L))); + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; } - gerror("pe_sc"); - return (null); - } - - - ElTerm pe_v_bline(Var v_a, int y, int u, int v) -//var v_a; -//int y,u,v; - { - int n; - if (u > v) + if (p2 < p4) { - n = u; - u = v; - v = n; + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - if (v_a.nm == 3) - return (pe_g_3bline(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, u, v)); - gerror("11111111111"); - return (null); - } - - ElTerm pe_g_3bline(Var v_a, int n1, int n2, int n3, int n4, int y, int u, int v) - { - if (n1 == v) - { - return (mk_elim(v_a, get_m(mk_var(-3, n1, n2, n3, n4)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == u && n4 == u) - { - return (mk_elim(v_a, get_m(mk_var(-3, n1, n2, n3, n4)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == v && n4 == v) - { - return (mk_elim(v_a, get_m(mk_var(-3, n3, u, u, n2)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == v && n4 == u) - { - return (mk_elim(v_a, pplus(trim_g(v, u, u, v), - ptimes(get_n(2L), get_m(mk_var(-3, y, y, u, u)))), - get_n(-2L))); - } else if (n1 == y && n2 == v && n3 == u && n4 == u) + if (p1 < p2) { - return (mk_elim(v_a, trim_g(v, v, u, u), get_n(2L))); - } else if (n1 == y && n2 == v && n3 == v && n4 == u) + sn *= (char) -1; + p = p1; + p1 = p2; + p2 = p; + p = p3; + p3 = p4; + p4 = p; + } else if ((p1 == p2) && (p3 < p4)) { - return (mk_elim(v_a, trim_g(v, u, u, v), get_n(2L))); + sn *= (char) -1; + p = p3; + p3 = p4; + p4 = p; } - gerror("pe_g_3bline"); - return (null); - } - ElTerm pe_v_square(Var v_a, int p1, int p2, int p3, int sn) -//var v_a; -//int p1,p2,p3,sn; - { - if (v_a.nm != 4) return (pe_v_tratio(v_a, p1, p2, p2, p3, get_n(1L * sn), get_n(1L))); - if (v_a.pt[1] == 0) + if (p1 == p2) { - return (mk_elim(v_a, - pplus(trim_vec(p2, 0), - ptimes3(get_n(1L * sn), get_s("i".toCharArray()), trim_vec(p3, p2))), - get_n(1L))); - } else + p2 = p3; + p3 = p4; + } else if (p2 == p3) { - return (mk_elim(v_a, - pplus(trim_vec(p2, v_a.pt[1]), - ptimes3(get_n(1L * sn), get_s("i".toCharArray()), trim_vec(p3, p2))), - get_n(1L))); + p3 = p4; } - } - ElTerm pe_v_ptri(Var v_a, int p1, int p2, int p3) -//var v_a; -//int p1,p2,p3; - { - if (v_a.pt[1] == 0) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p3, 0))), - get_n(1L))); - } else - { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes(get_n(-1L), trim_vec(v_a.pt[1], 0))), - get_n(1L))); - } + if (sn == 1) + return (get_m(mk_var(2, p1, p2, p3, p4))); + else + return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); } - ElTerm pe_v_ntri(Var v_a, int p1, int p2, int p3) -//var v_a; -//int p1,p2,p3; + /** + * Trims a geometric term based on perpendicularity constraints. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed geometric term as an XTerm + */ + XTerm trim_g(int p1, int p2, int p3, int p4) { - if (v_a.nm != 4) + int p; + char sn = 1; + /* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ + if (xperp(p1, p3, p2, p4)) return (get_n(0L)); + if (p1 < p3) { - gerror("pe_ntri"); + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; } - if (v_a.pt[1] == 0) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p2, 0))), - get_n(1L))); - } else + if (p2 < p4) { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes(get_n(-1L), trim_vec(v_a.pt[1], 0))), - get_n(1L))); + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - } - - ElTerm pe_v_sim(Var v_a, int p1, int p2, int p3, int q1, int q2, int q3) -//var v_a; -//int p1,p2,p3,q1,q2,q3; - { - if (v_a.nm != 4) gerror("pe_v_sim"); - if (v_a.pt[1] == 0) + if (p1 < p2) { - return (mk_elim(v_a, - pplus(ptimes(trim_vec(p2, 0), trim_vec(q2, q3)), - ptimes(trim_vec(q2, q1), trim_vec(p2, p3))), - trim_vec(q2, q3))); - } else + p = p1; + p1 = p2; + p2 = p; + p = p3; + p3 = p4; + p4 = p; + } else if ((p1 == p2) && (p3 < p4)) { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), trim_vec(q2, q3), trim_vec(v_a.pt[1], 0)), - ptimes(trim_vec(p2, 0), trim_vec(q2, q3)), - ptimes(trim_vec(q1, q2), trim_vec(p2, p3))), - trim_vec(q2, q3))); + p = p3; + p3 = p4; + p4 = p; } - } - - /////////////////////////////////////////////////////////////////////////elima.cpp - ElTerm radius_e = new ElTerm(); - - ElTerm rcir(int a, int b, int c) - { - radius_e.v = mk_svar("x".toCharArray()); - radius_e.p1 = ptimes3(trim_g(a, b, b, a), trim_g(a, c, c, a), trim_g(b, c, c, b)); - radius_e.p2 = ptimes3(get_n(64L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - return (radius_e); - } - - ElTerm pe_v_cent(Var v_a, int y, int a, int b, int c) - { - int n; - XTerm p; - if (v_a.nm == 2 || - (v_a.nm == 3 && v_a.pt[0] == y && v_a.pt[1] != y) || - v_a.nm == 4) - { - return (mk_elim(v_a, pplus(geval(v_a, y, a), - pplus(geval(v_a, y, b), geval(v_a, y, c))), get_n(3L))); - } else if (v_a.nm == 3 && v_a.pt[1] == y && v_a.pt[2] == y) + if (p1 == p2) { - p = pplus(geval(v_a, y, a), pplus(geval(v_a, y, b), geval(v_a, y, c))); - p = ptimes(get_n(3L), p); - p = pplus(p, pplus3(trim_g(a, a, b, b), trim_g(a, a, c, c), trim_g(b, b, c, c))); - return (mk_elim(v_a, p, get_n(9L))); - } else if (v_a.nm == 1) + sn *= (char) -1; + p1 = p3; + p3 = p2; + } else if (p3 == p4) { - if (v_a.pt[0] == y && v_a.pt[2] == y) - { - if (xcoll(c, y, v_a.pt[1])) - { - n = c; - c = b; - b = n; - } - if (xcoll(c, y, v_a.pt[1])) - { - n = c; - c = a; - a = n; - } - return (mk_elim(v_a, - pplus(trim_a(a, a, c, v_a.pt[1]), trim_a(b, b, c, v_a.pt[1])), - pplus(trim_a(a, a, c, v_a.pt[3]), trim_a(b, b, c, v_a.pt[3])))); - } else if (v_a.pt[0] == y) - { - return (mk_elim(v_a, - pplus(trim_a(a, a, c, v_a.pt[1]), trim_a(b, b, c, v_a.pt[1])), - ptimes(get_n(3L), trim_a(c, c, v_a.pt[2], v_a.pt[3])))); - } else if (v_a.pt[2] == y) - { - return (mk_elim(v_a, - ptimes(get_n(3L), trim_a(c, c, v_a.pt[0], v_a.pt[1])), - pplus(trim_a(a, a, c, v_a.pt[3]), trim_a(b, b, c, v_a.pt[3])))); - } + sn *= (char) -1; + p4 = p2; + p2 = p3; } - gerror("pe_v_cent"); - return (null); - } - - - ElTerm orth_md(Var v_a, int y, int a, int b, int c) - { - return (mk_elim(v_a, - pplus3(ptimes3(geval(v_a, y, a), trim_g(a, b, b, c), trim_g(a, c, c, b)), - ptimes3(geval(v_a, y, b), trim_g(b, a, a, c), trim_g(b, c, c, a)), - ptimes3(geval(v_a, y, c), trim_g(c, a, a, b), trim_g(c, b, b, a))), - ptimes3(get_n(16L), trim_a(a, b, c, c), trim_a(a, b, c, c)))); - } - -/* -el_term *pe_r_orth (v_a,n1,n2,n3,n4,y,a,b,c) -var *v_a; -int n1,n2,n3,n4,y,a,b,c; -{ gerror("pe_r_orth"); return(null);} - -*/ - - ElTerm pe_a_orth(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) -//var v_a; -//int n1,n2,n3,n4,y,a,b,c; - { - if (n1 != y) gerror("pe_a_orth"); - if (xperp(n2, n4, a, b)) - return (mk_elim(v_a, trim_a(c, n2, n3, n4), get_n(1L))); - else if (xperp(n2, n4, a, c)) - return (mk_elim(v_a, trim_a(b, n2, n3, n4), get_n(1L))); - else if (xperp(n2, n4, b, c)) - return (mk_elim(v_a, trim_a(a, n2, n3, n4), get_n(1L))); + //The largest index is either p1 or p2 + if (sn == 1) + return (get_m(mk_var(3, p1, p2, p3, p4))); else - return (orth_md(v_a, y, a, b, c)); - } - - ElTerm pe_g_orth(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) - { - ElTerm e1, rr; - int n; - XTerm r1, r2, r3, r4; - - e1 = null; - if (n1 == y && n2 != y) - { - if (xpara(n2, n4, a, b)) - e1 = mk_elim(v_a, trim_g(c, n2, n3, n4), get_n(1L)); - else if (xpara(n2, n4, a, c)) - e1 = mk_elim(v_a, trim_g(b, n2, n3, n4), get_n(1L)); - else if (xpara(n2, n4, b, c)) - e1 = mk_elim(v_a, trim_g(a, n2, n3, n4), get_n(1L)); - else - e1 = orth_md(v_a, y, a, b, c); - } else if (n2 == y && n3 == y) - { - if (n1 == n4 && (n1 == a || n1 == b || n1 == c)) - { - if (n1 == b) - { - n = a; - a = b; - b = n; - } - if (n1 == c) - { - n = a; - a = c; - c = n; - } - e1 = mk_elim(v_a, - ptimes3(trim_g(b, b, c, c), trim_g(b, a, a, c), trim_g(b, a, a, c)), - ptimes3(get_n(-16L), trim_a(a, b, c, c), trim_a(a, b, c, c))); - } else if (n1 == n4 && xcir3(n1, a, b, c)) - { - rr = rcir(a, b, c); - e1 = mk_elim(v_a, - pplus4(ptimes(get_n(9L), rr.p1), - ptimes(trim_g(a, a, b, b), cp_poly(rr.p2)), - ptimes(trim_g(b, b, c, c), cp_poly(rr.p2)), - ptimes(trim_g(a, a, c, c), cp_poly(rr.p2))), - rr.p2); - } else if ((n1 == a || n1 == b || n1 == c) && (n4 == a || n4 == b || n4 == c)) - { - e1 = mk_elim(v_a, - ptimes3(trim_g(a, b, b, c), trim_g(a, c, c, b), trim_g(b, a, a, c)), - ptimes3(get_n(-16L), trim_a(a, b, c, c), trim_a(a, b, c, c))); - } else - { - r1 = ptimes(trim_g(c, b, b, a), trim_g(c, a, a, b)); - r2 = ptimes(trim_g(b, a, a, c), trim_g(b, c, c, a)); - r3 = ptimes(trim_g(a, b, b, c), trim_g(a, c, c, b)); - r4 = ptimes3(get_n(16L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, pplus(pplus3(ptimes3(cp_poly(r1), cp_poly(r3), trim_g(a, a, c, c)), - ptimes3(cp_poly(r2), cp_poly(r3), trim_g(a, a, b, b)), - ptimes3(cp_poly(r1), cp_poly(r2), trim_g(b, b, c, c))), - pplus3(ptimes3(cp_poly(r1), cp_poly(r4), trim_g(n1, c, c, n4)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(n1, b, b, n4)), - ptimes3(cp_poly(r3), cp_poly(r4), trim_g(n1, a, a, n4)))), - ptimes(cp_poly(r4), cp_poly(r4))); - } - } else - gerror("pe_g_orth"); - return (e1); - } - - - ElTerm circum_md(Var v_a, int y, int a, int b, int c) - { - return (mk_elim(v_a, - pplus3(ptimes3(geval(v_a, y, a), trim_g(b, c, c, b), trim_g(b, a, a, c)), - ptimes3(geval(v_a, y, b), trim_g(a, c, c, a), trim_g(a, b, b, c)), - ptimes3(geval(v_a, y, c), trim_g(a, b, b, a), trim_g(a, c, c, b))), - ptimes3(get_n(32L), trim_a(a, b, c, c), trim_a(a, b, c, c)))); + return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); } - ElTerm pe_a_circum(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) + /** + * Trims a geometric term based on four point parameters, typically representing line intersections. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed term as an XTerm + */ + XTerm trim_f(int p1, int p2, int p3, int p4) { - int n; - if (xperp(n2, n4, b, c)) - { - n = a; - a = c; - c = n; - } - if (xperp(n2, n4, a, c)) + int p; + char sn = 1; + if (xcoll4(p1, p2, p3, p4)) return (pzero()); + if (p1 < p2) { - n = b; - b = c; - c = n; + p = p1; + p1 = p2; + p2 = p; } - if (xperp(n2, n4, a, b)) - return (mk_elim(v_a, pplus(trim_a(a, n2, n3, n4), trim_a(b, n2, n3, n4)), get_n(2L))); - if (n3 == n4 && (xcir5(y, n2, n3, a, b, c))) + if (p3 < p4) { - if (a != n2 && a != n3) - n = a; - else if (b != n2 && b != n3) - n = b; - else - n = c; - return (mk_elim(v_a, - ptimes(trim_g(n2, n3, n3, n2), trim_g(n2, n, n, n3)), - ptimes(get_n(32L), trim_a(n, n2, n3, n4)))); + p = p3; + p3 = p4; + p4 = p; } - return (circum_md(v_a, y, a, b, c)); - } - - ElTerm pe_g_circum(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) - { - ElTerm e1; - XTerm r1, r2, r3, r4; - - e1 = null; - if (n1 == y && n2 != y) - { - if (xcir2(y, n2, n4)) - { - e1 = mk_elim(v_a, pplus(trim_g(n2, n2, n3, n4), trim_g(n4, n2, n3, n4)), get_n(2L)); - } else - e1 = circum_md(v_a, y, a, b, c); - } else if (n2 == y && n3 == y) - { - if (n1 == n4 && xcir4(y, n1, a, b, c)) - { - e1 = rcir(a, b, c); - e1 = mk_elim(v_a, e1.p1, e1.p2); - } else if (xcir5(y, n1, n4, a, b, c)) - { - r1 = ptimes3(trim_g(a, b, b, a), trim_g(a, c, c, a), trim_g(b, c, c, b)); - r2 = ptimes3(get_n(64L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, - pplus(ptimes(get_n(2L), r1), - ptimes(trim_g(n1, n1, n4, n4), r2)), - ptimes(get_n(2L), cp_poly(r2))); - } else - { - r1 = ptimes(trim_g(a, b, b, a), trim_g(a, c, c, b)); - r2 = ptimes(trim_g(a, c, c, a), trim_g(a, b, b, c)); - r3 = ptimes(trim_g(b, c, c, b), trim_g(b, a, a, c)); - r4 = ptimes3(get_n(32L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, - pplus(pplus3(ptimes3(cp_poly(r1), cp_poly(r3), trim_g(a, a, c, c)), - ptimes3(cp_poly(r2), cp_poly(r3), trim_g(a, a, b, b)), - ptimes3(cp_poly(r1), cp_poly(r2), trim_g(b, b, c, c))), - pplus3(ptimes3(cp_poly(r1), cp_poly(r4), trim_g(n3, c, c, n4)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(n3, b, b, n4)), - ptimes3(cp_poly(r3), cp_poly(r4), trim_g(n3, a, a, n4)))), - ptimes(cp_poly(r4), cp_poly(r4))); - } - } else - gerror("pe-g-circum2"); - return (e1); - } - - - ElTerm pe_r_circum(Var v_a, int n1, int n2, int d1, int d2, int y, int a, int b, int c) - { - int a1 = 0, b1 = 0, c1 = 0; - if (a == n1 || a == n2 || a == d1 || a == d2) a1 = a; - if (b == n1 || b == n2 || b == d1 || b == d2) b1 = b; - if (c == n1 || c == n2 || c == d1 || c == d2) c1 = c; - if (c1 != 0 && !(a1 != 0)) - { - a1 = c; - b1 = b; - } else if (c1 != 0 && !(b1 != 0)) + if (p1 < p3) { - a1 = c; - b1 = a; - } else + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; + p = p2; + p2 = p4; + p4 = p; + } else if ((p1 == p3) && (p2 < p4)) { - a1 = a; - b1 = b; + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - - - if (n2 == y) - { - if (d2 == y) - return (mk_elim(v_a, - pplus(trim_g(n1, a1, a1, b1), trim_g(n1, a1, b1, b1)), - pplus(trim_g(d1, a1, a1, b1), trim_g(d1, a1, b1, b1)))); - else - return (mk_elim(v_a, - pplus(trim_g(n1, a1, a1, b1), trim_g(n1, a1, b1, b1)), - ptimes(get_n(2L), trim_g(d1, a1, d2, b1)))); - } else if (d2 == y) - return (rev_elim(pe_r_circum(v_a, d1, d2, n1, n2, y, a, b, c))); + if (sn == 1) + return (get_m(mk_var(10, p1, p2, p3, p4))); else - gerror("pe-r-circum1"); - return (null); - } - - - ElTerm incent_md(Var v_a, int y, int i, int a, int b) - { - return (mk_elim(v_a, - pplus3(ptimes4(get_n(-2L), geval(v_a, y, i), trim_g(i, a, a, b), trim_g(i, b, b, a)), - ptimes3(geval(v_a, y, a), trim_g(i, a, a, b), trim_g(b, i, i, b)), - ptimes3(geval(v_a, y, b), trim_g(i, b, b, a), trim_g(a, i, i, a))), - ptimes(trim_g(a, i, i, b), trim_g(a, b, b, a)))); - } - - ElTerm pe_a_incent(Var v_a, int n1, int n2, int n3, int n4, int y, int i, int a, int b) - { - return (incent_md(v_a, y, i, a, b)); + return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); } - ElTerm pe_g_incent(Var v_a, int n1, int n2, int n3, int n4, int y, int i, int a, int b) + /** + * Trims a geometric term derived from two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the trimmed term as an XTerm + */ + XTerm trim_fl(LLine l1, LLine l2) { - ElTerm e1; - int n, sn; - XTerm r1, r2, r3, r4, r5, r6, ar; - e1 = null; - sn = 1; - if (n1 == y && n2 != y) - { - if (n3 == n4) - { - n = n2; - n2 = n4; - n4 = n; - sn = -1; - } - if (n2 == n3 && n4 == b) - { - n = a; - a = b; - b = n; - } - if (n2 == n3 && n2 == i && n4 == a) - { - e1 = mk_elim(v_a, - ptimes4(get_n(16L), trim_g(i, a, a, i), trim_a(i, a, a, b), trim_a(i, a, a, b)), - ptimes(trim_g(a, b, b, a), trim_g(a, i, i, b))); - if (sn == -1) e1.p1 = neg_poly(e1.p1); - } else - e1 = incent_md(v_a, y, i, a, b); - } else if (n2 == y && n3 == y) - { - r1 = trim_g(i, a, a, b); - r2 = trim_g(i, b, b, a); - r3 = trim_g(a, i, i, b); - r4 = trim_g(i, a, a, i); - r5 = trim_g(i, b, b, i); - r6 = trim_g(a, b, b, a); - ar = trim_a(a, i, i, b); - if (n1 == i && n4 == i) - { - e1 = mk_elim(v_a, - ptimes4(ptimes(get_n(16L), r4), r5, ar, cp_poly(ar)), - ptimes3(r3, cp_poly(r3), r6)); - put_p(r1); - put_p(r2); - } else if (n1 == a && n4 == a) - { - e1 = mk_elim(v_a, ptimes4(r4, cp_poly(r4), r2, cp_poly(r2)), - ptimes4(get_n(1L), r6, r3, cp_poly(r3))); - put_p(r1); - put_p(r5); - } else if (n1 == b && n4 == b) - { - e1 = mk_elim(v_a, ptimes4(r5, cp_poly(r5), r1, cp_poly(r1)), - ptimes4(get_n(1L), r6, r3, cp_poly(r3))); - put_p(r2); - put_p(r4); - } else if ((n1 == a && n4 == b) || (n1 == b && n4 == a)) - { - e1 = mk_elim(v_a, - ptimes3(r1, r2, pminus(ptimes(r4, r5), ptimes3(get_n(2L), r3, cp_poly(r3)))), - ptimes3(cp_poly(r3), cp_poly(r3), r6)); - } else if ((n1 == a && n4 == i) || (n1 == i && n4 == a)) - { - e1 = mk_elim(v_a, ptimes4(ptimes(get_n(-16L), r4), r2, ar, cp_poly(ar)), - ptimes3(r6, r3, cp_poly(r3))); - put_p(r1); - put_p(r5); - } else if ((n1 == b && n4 == i) || (n1 == i && n4 == b)) - { - e1 = mk_elim(v_a, ptimes4(ptimes(get_n(16L), r5), r1, ar, cp_poly(ar)), - ptimes3(r6, r3, cp_poly(r3))); - put_p(r2); - put_p(r4); - } else - { - e1 = mk_elim(v_a, - pminus(pplus3(ptimes(ptimes3(get_n(-2L), r1, r2), - ptimes3(cp_poly(r1), r5, trim_g(a, i, i, a))), - ptimes(ptimes3(cp_poly(r1), cp_poly(r5), cp_poly(r2)), - ptimes(r4, trim_g(a, b, b, a))), - ptimes(ptimes3(get_n(-2L), cp_poly(r1), cp_poly(r2)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(b, i, i, b)))), - pplus3(ptimes(ptimes3(get_n(-2L), cp_poly(r1), cp_poly(r2)), - ptimes3(r3, r6, trim_g(n1, i, i, n1))), /* check trig_g */ - ptimes(ptimes3(cp_poly(r1), cp_poly(r5), cp_poly(r3)), - ptimes(cp_poly(r6), trim_g(n1, a, a, n1))), - ptimes(ptimes3(cp_poly(r2), cp_poly(r4), cp_poly(r3)), - ptimes(cp_poly(r6), trim_g(n1, b, b, n1))))), - ptimes4(cp_poly(r3), cp_poly(r3), cp_poly(r6), cp_poly(r6))); - e1.p1 = neg_poly(e1.p1); - } - } else - gerror("pe-g-incent2"); - - return (e1); + if (l1 == l2) return (pzero()); + return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); } - - ElTerm pe_r_incent(Var v_a, int n1, int n2, int d1, int d2, int y, int i, int a, int b) + /** + * Trims a geometric term representing a vector. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @return the trimmed vector term as an XTerm + */ + XTerm trim_vec(int p1, int p2) { - if (n2 == y && d2 == y) - { - return (mk_elim(v_a, - pminus(ptimes(get_n(2L), trim_g(n1, a, a, b)), trim_g(a, b, b, a)), - pminus(ptimes(get_n(2L), trim_g(d1, a, a, b)), trim_g(a, b, b, a)))); - } else if (n2 == y) - { - return (mk_elim(v_a, - pminus(ptimes(get_n(2L), trim_g(n1, a, a, b)), trim_g(a, b, b, a)), - trim_g(d1, a, d2, b))); - } else if (d2 == y) + if (p2 == 0) { - return (rev_elim(pe_r_incent(v_a, d1, d2, n1, n2, y, i, a, b))); - } else - gerror("pe_r_incenter"); - return (null); + return (get_m(mk_var(4, p1, 0, 0, 0))); + } + if (p1 == p2) return (pzero()); + if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); + return (get_m(mk_var(4, p1, p2, 0, 0))); } } diff --git a/src/main/java/gprover/Full.java b/src/main/java/gprover/Full.java index 27363bc5..5e19b4dc 100644 --- a/src/main/java/gprover/Full.java +++ b/src/main/java/gprover/Full.java @@ -3,6 +3,9 @@ import java.util.Vector; +/** + * Implements full angle proof processes and geometric elimination. + */ public class Full extends Elim { int max_term; @@ -14,11 +17,16 @@ public class Full extends Elim { XTerm conc_p1, conc_p2; boolean print_conc = false; - + /** + * Constructs a new Full object. + */ public Full() { P_STATUS = 0; } + /** + * Proves the geometric configuration using full elimination logic. + */ void prove_full() { GrTerm gr1; DTerm ps1; @@ -35,7 +43,7 @@ void prove_full() { dbase(); fconc(); if (qerror) return; - boolean first = true; + boolean first = true; do { co_db.nx = null; @@ -99,6 +107,9 @@ void prove_full() { print_fend(); } + /** + * Initializes the geometric database by searching for midpoints, lines, circles, and angles. + */ void dbase() { MidPt md; PLine pn; @@ -127,15 +138,27 @@ void dbase() { } } + /** + * Checks if the provided term is non-polynomial. + * + * @param p the term to check. + * @return true if the term has no associated variable; false otherwise. + */ boolean npoly(XTerm p) { return (p.var == null); } + /** + * Prints terminal details based on the print_conc flag. + */ void print_t() { if (print_conc) gprint(Cm.s2300); } + /** + * Prints the final conclusion of the proof. + */ void print_fend() { DTerm ps1; XTerm p1; @@ -148,6 +171,14 @@ else if (print_conc) { } } + /** + * Constructs and links a new geometric term in the proof chain. + * + * @param c1 the first constant. + * @param p1 the first term. + * @param c2 the second constant. + * @param p2 the second term. + */ void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { if (p1 != null && p1.getPV() < 0) p1 = this.neg_poly(p1); @@ -158,10 +189,18 @@ void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { last_pr = gr; } + /** + * Executes the default full angle concatenation process. + */ void fconc() { fconc(conc); } + /** + * Executes the full angle concatenation based on the provided condition. + * + * @param conc the condition with the predicate and associated parameters. + */ void fconc(Cond conc) { switch (conc.pred) { case CO_COLL: @@ -199,13 +238,11 @@ void fconc(Cond conc) { /* constants8 */ conc_gr(1L, pminus(conc_p1, conc_p2), 0L, null); break; - case CO_PBISECT: conc_gr(1L, pminus(trim_f(conc.p[0], conc.p[1], conc.p[1], conc.p[2]), - trim_f(conc.p[1], conc.p[2], conc.p[2], conc.p[0])), + trim_f(conc.p[1], conc.p[2], conc.p[2], conc.p[0])), 0L, null); break; - case CO_CONG: fconc_cong(conc.p[0], conc.p[1], conc.p[2], conc.p[3]); break; @@ -218,10 +255,22 @@ void fconc(Cond conc) { } } + /** + * Returns the error type encountered during proof processing. + * + * @return the error type code. + */ public int getErrorType() { return ertype; } + /** + * Processes the collinearity condition for full angle concatenation. + * + * @param a first geometric parameter. + * @param b second geometric parameter. + * @param c third geometric parameter. + */ public void fconc_coll(int a, int b, int c) { if (a < b) { int k = a; @@ -236,6 +285,15 @@ public void fconc_coll(int a, int b, int c) { conc_gr(1L, trim_f(a, b, a, c), 0L, null); } + /** + * Processes the congruence condition for full angle concatenation. + * + * @param a first geometric parameter. + * @param b second geometric parameter. + * @param c third geometric parameter. + * @param d fourth geometric parameter. + * @return true if the congruence condition was successfully processed; false otherwise. + */ public boolean fconc_cong(int a, int b, int c, int d) { int l, m, n; if (a == c) { @@ -258,13 +316,19 @@ public boolean fconc_cong(int a, int b, int c, int d) { conc_gr(1L, null, 1L, null); return false; } - conc_gr(1L, pminus(trim_f(l, m, m, n), trim_f(m, n, n, l)), 0L, null); return true; } - //////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Constructs an elimination term using a variable and two XTerm operands. + * Reorders the variable if necessary and computes the metric. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @return the constructed elimination term + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2) { ElTerm e1 = new ElTerm(); if (this.var_reOrder(v)) { @@ -279,6 +343,17 @@ ElTerm mk_felim(Var v, XTerm p1, XTerm p2) { return (e1); } + /** + * Constructs an elimination term using a variable and two XTerm operands, + * and scales the resulting term by a factor if necessary. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @param n the scaling factor; if not 1, the term is multiplied by this factor + * @param t the elimination type + * @return the scaled elimination term + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int n, int t) { ElTerm e = mk_felim(v, p1, p2, t); if (n != 1) @@ -286,54 +361,30 @@ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int n, int t) { return e; } - + /** + * Constructs an elimination term using a variable and two XTerm operands, + * and sets its elimination type. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @param t the elimination type to set + * @return the elimination term with the specified type + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int t) { ElTerm el = mk_felim(v, p1, p2); el.etype = t; return el; } - ElTerm mk_feliminator(Var v, XTerm p1, XTerm p2, int t) { - ElTerm e1 = new ElTerm(); - e1.etype = t; - e1.v = v; - e1.p1 = p1; - e1.p2 = p2; - e1.p = get_m(v); - e1.co = co_db.nx; - return (e1); - } - - ElTerm elim_qcs(XTerm p) { // NO USAGE. - Var v1 = p.var; - LLine ln1 = fadd_ln(v1.pt[0], v1.pt[1]); - LLine ln2 = fadd_ln(v1.pt[2], v1.pt[3]); - - co_db.nx = null; - int p1, p2, p3, p4; - p1 = v1.pt[0]; - p2 = v1.pt[1]; - p3 = v1.pt[2]; - p4 = v1.pt[3]; - boolean t = false; - if (ln1.pt[0] < v1.pt[0] && ln1.pt[1] < v1.pt[0]) { - add_codb(CO_COLL, ln1.pt[0], ln1.pt[1], v1.pt[0], v1.pt[1], 0, 0, 0, 0); - p1 = ln1.pt[0]; - p2 = ln1.pt[1]; - t = true; - } - if (ln2.pt[0] < v1.pt[2] && ln2.pt[1] < v1.pt[2]) { - add_codb(CO_COLL, ln2.pt[0], ln2.pt[1], v1.pt[2], v1.pt[3], 0, 0, 0, 0); - p3 = ln2.pt[0]; - p4 = ln2.pt[1]; - t = true; - } - if (t) - return mk_felim(p.var, trim_f(p1, p2, p3, p4), get_n(1), 1); - - return null; - } - + /** + * Attempts the elimination procedure (query type 7) on the provided XTerm. + * Iterates through subterms to identify a valid elimination candidate based on + * geometric relationships. + * + * @param p the XTerm to process + * @return the resulting elimination term if a valid candidate is found; null otherwise + */ ElTerm elim_q7(XTerm p) { LLine ln1, ln2, ln3, ln4; XTerm p1 = p; @@ -352,7 +403,8 @@ ElTerm elim_q7(XTerm p) { while (ps2 != null) { XTerm p2 = ps2.p; - if (npoly(p2)) break;//goto l2; + if (npoly(p2)) + break; Var v2 = p2.var; ln3 = fadd_ln(v2.pt[0], v2.pt[1]); ln4 = fadd_ln(v2.pt[2], v2.pt[3]); @@ -382,7 +434,6 @@ ElTerm elim_q7(XTerm p) { add_codb(CO_COLL, v1.pt[2], v1.pt[3], v2.pt[2], v2.pt[3], 0, 0, 0, 0); return (mk_felim(p1.var, get_m(p2.var), get_n(1L), 1)); } - if (ln2 == ln4 && ln_less(ln3, ln2)) { co_db.nx = null; add_codb(CO_COLL, v1.pt[2], v1.pt[3], v2.pt[2], v2.pt[3], 0, 0, 0, 0); @@ -392,7 +443,6 @@ ElTerm elim_q7(XTerm p) { r = 1; return (mk_felim(p1.var, pplus(get_m(p2.var), xt), get_n(1L), r)); } - if (ln1 == ln3) { co_db.nx = null; add_codb(CO_COLL, v1.pt[0], v1.pt[1], v2.pt[0], v2.pt[1], 0, 0, 0, 0); @@ -401,7 +451,6 @@ ElTerm elim_q7(XTerm p) { if (pzerop(xt)) r = 1; return (mk_felim(p1.var, pplus(get_m(p2.var), xt), get_n(1L), r)); - } } ps2 = p2.ps; @@ -409,35 +458,54 @@ ElTerm elim_q7(XTerm p) { } ps1 = p1.ps; ps1 = ps1.nx; - if (ps1 == null) return (null); + if (ps1 == null) + return (null); p1 = ps1.p; } } + /** + * Attempts the elimination procedure (query type 8) on the provided XTerm. + * Verifies collinearity of the term's sub-elements before processing. + * + * @param p1 the XTerm to process + * @return the resulting elimination term if successful; null otherwise + */ ElTerm elim_q8(XTerm p1) { DTerm ps1; XTerm p2; Var v1, v2; LLine ln1, ln2; - if (p1 == null || npoly(p1)) return (null); + if (p1 == null || npoly(p1)) + return (null); v1 = p1.var; ln1 = fadd_ln(v1.pt[0], v1.pt[1]); ps1 = p1.ps; ps1 = ps1.nx; - if (ps1 == null) return (null); + if (ps1 == null) + return (null); p2 = ps1.p; - if (npoly(p2)) return (null); + if (npoly(p2)) + return (null); v2 = p2.var; ln2 = fadd_ln(v2.pt[0], v2.pt[1]); - if (ln1 != ln2) return (null); + if (ln1 != ln2) + return (null); { co_db.nx = null; add_codb(CO_COLL, v1.pt[0], v1.pt[1], v2.pt[0], v2.pt[1], 0, 0, 0, 0); - return (mk_felim(p1.var, pplus(get_m(p2.var), trim_f(v2.pt[2], v2.pt[3], v1.pt[2], v1.pt[3])), get_n(1L), RF_ADDITION)); //addition. + return (mk_felim(p1.var, pplus(get_m(p2.var), trim_f(v2.pt[2], v2.pt[3], v1.pt[2], v1.pt[3])), get_n(1L), RF_ADDITION)); } } + /** + * Processes an XTerm by applying modulus to its coefficient. + * Traverses subterms until a non-polynomial term is encountered and applies the modulus. + * + * @param p the XTerm to process + * @return the processed XTerm with its coefficient modified + */ XTerm fpoly(XTerm p) { DTerm ps1, ps2; XTerm p1, p2; @@ -450,7 +518,8 @@ XTerm fpoly(XTerm p) { while (true) { ps1 = p1.ps; ps2 = ps1.nx; - if (ps2 == null) return (p); + if (ps2 == null) + return (p); p2 = ps2.p; if (!npoly(p2)) p1 = p2; @@ -467,60 +536,74 @@ XTerm fpoly(XTerm p) { return (p); } - ElTerm mk_felim11(Var v, int a, int b, int c, int d, int o, int p1, int p2, int o1) { // <[ab, cd] = <[o1p1,o1,p2] -// co_db.nx = null; -// -// cond c1 = add_codb(CO_COLL, o, p1, a, b, 0, 0, 0, 0); -// cond c2 = add_codb(CO_COLL, o, p2, c, d, 0, 0, 0, 0); -// el_term e1 = null; -// if (c1.pred != 0 || c2.pred != 0) { -// e1 = mk_felim(v, trim_f(o, p1, o, p2), get_n(1L), 0); -// co_db.nx = null; -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// el_term e2 = mk_felim(new var(10, o, p1, o, p2), trim_f(o1, p1, o1, p2), get_n(1), 9); -// e1.nx = e2; -// co_db.nx = null; -// } else { -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// } -// el_term el = (mk_felim(v, trim_f(o1, p1, o1, p2), get_n(1L), 9)); -// el.et = e1; -// return el; + /** + * Constructs an elimination term for cyclic configurations. + * Sets up conditions based on collinearity and cyclic properties. + * + * @param v the variable associated with the term + * @param a first parameter for collinearity + * @param b second parameter for collinearity + * @param c third parameter for collinearity + * @param d fourth parameter for collinearity + * @param o origin or reference parameter + * @param p1 first point parameter + * @param p2 second point parameter + * @param o1 additional reference parameter + * @return the elimination term constructed for the cyclic case + */ + ElTerm mk_felim11(Var v, int a, int b, int c, int d, int o, int p1, int p2, int o1) { co_db.nx = null; add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); Cond c1 = add_codb(CO_COLL, o, p1, a, b, 0, 0, 0, 0); Cond c2 = add_codb(CO_COLL, o, p2, c, d, 0, 0, 0, 0); -// el_term e1 = null; -// if (c1.pred != 0 || c2.pred != 0) { -// e1 = mk_felim(v, trim_f(o, p1, o, p2), get_n(1L), 0); -// co_db.nx = null; -// el_term e2 = mk_felim(new var(10, o, p1, o, p2), trim_f(o1, p1, o1, p2), get_n(1), 9); -// e1.nx = e2; -// co_db.nx = null; -// } else { -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// } ElTerm el = (mk_felim(v, trim_f(o1, p1, o1, p2), get_n(1L), RF_INSCRIBE)); co_db.nx = null; return el; } - ElTerm mk_felim6(Var v, int a, int b, int c, int d) { // para + /** + * Constructs an elimination term for parallel configurations. + * Registers the parallel condition before creating the elimination term. + * + * @param v the variable associated with the term + * @param a first parameter for the parallel condition + * @param b second parameter for the parallel condition + * @param c third parameter for the parallel condition + * @param d fourth parameter for the parallel condition + * @return the elimination term representing the parallel condition + */ + ElTerm mk_felim6(Var v, int a, int b, int c, int d) { co_db.nx = null; add_codb(CO_PARA, a, b, c, d, 0, 0, 0, 0); ElTerm e1 = mk_felim(v, get_n(0L), get_n(1L), 3); return e1; } + /** + * Constructs an elimination term for a perpendicular configuration. + * + * @param v the variable associated with the term + * @param a first parameter for the perpendicular configuration + * @param b second parameter for the perpendicular configuration + * @param c third parameter for the perpendicular configuration + * @param d fourth parameter for the perpendicular configuration + * @return the elimination term constructed for the perpendicular configuration + */ ElTerm mk_felim7(Var v, int a, int b, int c, int d) { co_db.nx = null; add_codb(CO_PERP, a, b, c, d, 0, 0, 0, 0); return mk_felim(v, get_n(1L), get_n(1L), 4); } + /** + * Attempts to eliminate a geometric term using various strategies. + * + * @param v the variable associated with the term + * @return the resulting elimination term if a strategy succeeds; otherwise, null + */ ElTerm elim_f(Var v) { ElTerm e1 = null; int a, b, c, d; @@ -561,8 +644,17 @@ ElTerm elim_f(Var v) { return (e1); } + /** + * Processes an elimination based on a line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the line configuration; null if not applicable + */ ElTerm elim_f_ln(Var v, int a, int b, int c, int d) { - LLine ln1 = fd_ln(a, b); if (ln1 != null && a > ln1.pt[1]) { co_db.nx = null; @@ -572,8 +664,17 @@ ElTerm elim_f_ln(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a parallel line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the parallel line configuration; null if not found + */ ElTerm elim_f_pn(Var v, int a, int b, int c, int d) { - LLine ln1 = fd_ln(a, b); PLine pn1 = fd_pn(a, b); if (pn1 == null) return (null); @@ -593,13 +694,21 @@ ElTerm elim_f_pn(Var v, int a, int b, int c, int d) { return (null); } - - ElTerm elim_f_tn(Var v, int a, int b, int c, int d) // could be more tn lines. - { + /** + * Performs elimination based on a tn-line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the tn-line configuration; null if not applicable + */ + ElTerm elim_f_tn(Var v, int a, int b, int c, int d) { LLine ln2; LLine ln1 = fd_ln(a, b); TLine tn1 = fd_tn(ln1); -// if (tn1 == null) return (null); + // if (tn1 == null) return (null); if (tn1 != null) { if (tn1.l1 == ln1) ln2 = tn1.l2; @@ -643,7 +752,16 @@ ElTerm elim_f_tn(Var v, int a, int b, int c, int d) // could be more tn lines return (null); } - + /** + * Processes the cyclic configuration for elimination. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration; null if not applicable + */ ElTerm elim_f_cir1(Var v, int a, int b, int c, int d) { int o, p1, p2, p3, p4; LLine ln3, ln4, ln5, ln6; @@ -748,13 +866,23 @@ else if (rel == null) } } } - if (rel != null) return rel; - l1: - cr = cr.nx; + if (rel != null) return rel; + l1: + cr = cr.nx; + } + return (null); } - return (null); - } + /** + * Processes the cyclic configuration (version 2) for elimination. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the second cyclic configuration; null if not applicable + */ ElTerm elim_f_cir2(Var v, int a, int b, int c, int d) { ACir cr1, cr2; int p1, p2, p3, p4; @@ -820,6 +948,19 @@ ElTerm elim_f_cir2(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a cyclic circle configuration (variant 3). + * + * This method searches through cyclic configurations in the circle list and + * attempts to form an elimination term based on inter-line relationships. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration or null if not applicable + */ ElTerm elim_f_cir3(Var v, int a, int b, int c, int d) { ACir cr1; int o, p1, p2, p3, p4; @@ -889,6 +1030,19 @@ ElTerm elim_f_cir3(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a cyclic circle configuration (variant 4). + * + * This method searches through cyclic configurations in the circle list and + * attempts to form an elimination term using midpoint and line intersection strategies. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration or null if not applicable + */ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { ACir cr1; int o, p1, p2, p3, p4; @@ -940,7 +1094,7 @@ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { ln_less((fadd_ln(p2, p3)), ln1)) { co_db.nx = null; add_codb(CO_CYCLIC, o, p1, p2, p3, 0, 0, 0, 0); //r33 - return (mk_felim(v, pplus3(trim_f(p1, o, p1, p3), trim_f(p2, p3, c, d), get_n(1L)), //r28 + return (mk_felim(v, pplus3(trim_f(p1, o, p1, p3), trim_f(p2, p3, c, d), get_n(1L)), get_n(1L), RF_18)); } if (ln_less((fadd_ln(p3, o)), ln1) && @@ -958,6 +1112,19 @@ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on center configurations. + * + * This method iterates through line points and configuration constraints to + * determine centers (such as orthocenters or incenters) for constructing an elimination term. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from center-based elimination or null if not applicable + */ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { LLine ln1, ln2; int p1, p2; @@ -975,7 +1142,7 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { for (k = 1; k <= cons_no; k++) for (l = 1; l <= cons_no; l++) { - //orthocenter k p1 p2 l / + // orthocenter k p1 p2 l if (k < l && p1 < p2 && k != p1 && k != p2 && l != p1 && l != p2 && xperp(p1, k, p2, l) && xperp(p2, k, p1, l) && ln_less((fadd_ln(k, l)), ln1)) { @@ -984,8 +1151,8 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { return (mk_felim(v, pplus(trim_f(k, l, c, d), get_n(1L)), get_n(1L), RF_ORTH)); } - /* incenter (p1) p2 k l */ - /*gprint("cen1: %s %s %s %s\r\n",ANAME(p1),ANAME(p2),ANAME(k),ANAME(l)); */ + /* incenter (p1) p2 k l */ + /* gprint("cen1: %s %s %s %s\r\n",ANAME(p1),ANAME(p2),ANAME(k),ANAME(l)); */ if (k < l && k != p1 && k != p2 && l != p1 && l != p2 && xacong(k, l, p1, p1, l, p2) && xacong(l, k, p1, p1, k, p2) && ln_less((fadd_ln(k, p2)), ln1) && @@ -1007,6 +1174,18 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on angle configurations. + * + * This method processes the angle and congruence relationships to form an elimination term. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from angle-based configurations or null if not applicable + */ ElTerm elim_f_ans(Var v, int a, int b, int c, int d) { LLine l1, l2, ln0, ln1, ln2; Angles as; @@ -1077,6 +1256,22 @@ ElTerm elim_f_ans(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on combined geometric configurations involving circles and lines. + * + *
+ * This method takes a variable containing four geometric points and attempts to construct an elimination
+ * term by evaluating a series of geometric constraints. It uses helper methods such as
+ * inter_lc, ln_less, on_ln, on_cir, xperp,
+ * and xpara to verify perpendicular, parallel, and cyclic conditions among lines and circles.
+ * The method iterates through the circle lists and applies different elimination strategies.
+ * When a valid geometric configuration is detected, it creates and returns the corresponding elimination term.
+ * Otherwise, it returns null.
+ *
null otherwise
+ */
ElTerm elim_d(Var v) {
LLine ln1, ln2;
ACir cr, cr1;
@@ -1273,7 +1468,18 @@ else if (ln_less(fadd_ln(p3, p2), ln1)) {
return (null);
}
- ElTerm elim_t(Var v) {
+/**
+ * Performs elimination based on a t-based strategy.
+ *
+ * This method handles elimination cases that require t-based processing. + * It applies specific geometric transformations and validations to compute + * the corresponding elimination term.
+ * + * @param v the variable containing geometric term data + * @return the computed elimination term using the t-based strategy, or + *null if no appropriate elimination can be performed
+ */
+ElTerm elim_t(Var v) {
LLine ln1, ln2;
ACir cr;
int p1, p2, p3;
@@ -1308,7 +1514,20 @@ ElTerm elim_t(Var v) {
return (null);
}
- ElTerm elim_tri(Var v) {
+/**
+ * Performs triangle elimination.
+ *
+ * + * This method processes elimination based on triangle configurations. + * It evaluates the geometric relationships between triangle vertices to + * compute the corresponding elimination term. + *
+ * + * @param v the variable containing triangle points data + * @return the elimination term constructed from the triangle configuration, + * or null if no appropriate elimination can be performed + */ +ElTerm elim_tri(Var v) { int a = v.pt[0]; int b = v.pt[1]; int c = v.pt[2]; @@ -1338,7 +1557,20 @@ ElTerm elim_tri(Var v) { } /////froem area - XTerm eprem(XTerm p, ElTerm e) { +/** + * Performs pre-elimination computations on an XTerm using the specified elimination term. + * + *This method applies an elimination strategy by processing the given XTerm + * in conjunction with an elimination term. The transformation rules and constraints + * applied within the method lead to a modified XTerm that encapsulates specific geometric + * relationships or configurations. The exact processing is defined by the elimination + * scheme used in the overall geometric computation.
+ * + * @param p the original XTerm input for pre-elimination processing + * @param e the elimination term that guides the computation + * @return the resulting XTerm after processing or null if the computation is not applicable + */ +XTerm eprem(XTerm p, ElTerm e) { XTerm p1, p2, p3; if (e == null) return p; p2 = get_n(1L); @@ -1362,28 +1594,55 @@ XTerm eprem(XTerm p, ElTerm e) { return (p1); } - ////////////////////////////////////////////////////////////////////// - // print - boolean pr_elim = true; - - public boolean canExpressedAsFullAngle() { - return proof.nx != null; - } - - public boolean isProvedTrue() { - if (last_pr != null && last_pr.isZero()) return true; - return false; - } +/** + * Returns true if a full angle proof is expressed. + * + * @return true if the full angle proof head exists, false otherwise. + */ +public boolean canExpressedAsFullAngle() { + return proof.nx != null; +} - public GrTerm getFullAngleProofHead() { +/** + * Determines if the proof has been established as true. + * + * @return true if last_pr is non-null and equals zero, false otherwise. + */ +public boolean isProvedTrue() { + if (last_pr != null && last_pr.isZero()) return true; + return false; +} - GrTerm gt = proof.nx; - if (gt == null) return null; - while (gt != null) { - if (gt.ps1 != null) - myprint_p1(gt.ps1.p, true); - ElTerm el = gt.el; - if (el != null) { +/** + * Retrieves the head of the full angle proof. + * + * This method iterates through the proof elements while printing intermediate + * proof components. It processes both primary and linked elimination terms. + * + * @return the first element in the full angle proof chain, or null if none exists. + */ +public GrTerm getFullAngleProofHead() { + GrTerm gt = proof.nx; + if (gt == null) return null; + while (gt != null) { + if (gt.ps1 != null) + myprint_p1(gt.ps1.p, true); + ElTerm el = gt.el; + if (el != null) { + myprint_p1(el.p1, true); + myprint_p1(el.p2, true); + myprint_p1(el.p, true); + Cond co = el.co; + while (co != null) { + this.show_pred(co); + do_pred(co); + //forw_pred(co); + co = co.nx; + } + } + if (el != null) { + el = el.et; + while (el != null) { myprint_p1(el.p1, true); myprint_p1(el.p2, true); myprint_p1(el.p, true); @@ -1391,158 +1650,96 @@ public GrTerm getFullAngleProofHead() { while (co != null) { this.show_pred(co); do_pred(co); - //forw_pred(co); + // forw_pred(co); co = co.nx; } + el = el.nx; } - if (el != null) { - el = el.et; - while (el != null) { - myprint_p1(el.p1, true); - myprint_p1(el.p2, true); - myprint_p1(el.p, true); - Cond co = el.co; - while (co != null) { - this.show_pred(co); - do_pred(co); - // forw_pred(co); - co = co.nx; - } - el = el.nx; - } - } - - gt = gt.nx; } - - return proof.nx; + gt = gt.nx; } + return proof.nx; +} - public boolean print_prooftext() // added MAY 4th 2006 - { - char mk = 0; - - GrTerm gr1 = proof.nx; - if (gr1 == null) return false; - - while (gr1 != null) { - if (gr1.c == -1) { - this.setPrintToString(); - DTerm dt = gr1.ps; - print_ps(dt, mk); - dt.text = this.getPrintedString(); - } else if (gr1.c == -2) { - } else if (gr1.c == 0) { - } else { - ElTerm el = gr1.el; - print_elims(el, mk); - } - - if (gr1.c == 0) { - } else { - } - +/** + * Prints the proof text. + * + * This method iterates through all proof terms and prints their associated + * elimination information. It assembles the printed proof text by processing + * both display and elimination terms. + * + * @return true if proof text printing succeeds, false otherwise. + */ +public boolean print_prooftext() // added MAY 4th 2006 +{ + char mk = 0; + GrTerm gr1 = proof.nx; + if (gr1 == null) return false; + while (gr1 != null) { + if (gr1.c == -1) { this.setPrintToString(); - print_gr(gr1, mk); - gr1.text = this.getPrintedString(); - gr1 = gr1.nx; - } - return true; - } - - void print_proof(char mk) { - GrTerm gr1 = proof.nx; - - if (gr1 == null) { - gprint(Cm.s2220); - return; - } - gprint(Cm.s2221); - //docc(3); - gprint(Cm.s2222); - gprint(" "); - { // print the gr as an equation - //for area, vector, and full-angle - if (num_zop(gr1.c1)) { - gprint("0"); - } else if (gr1.ps1 == null) { - //sprintf(txt, "%ld", gr1.c1); - gprint("" + gr1.c1); - } else if (num_unit(gr1.c1)) - print_ps(gr1.ps1, mk); - else { - num_show(gr1.c1); - print_ps(gr1.ps1, mk); - } - gprint(" = "); - if (num_zop(gr1.c2)) { - gprint("0"); - } else if (gr1.ps2 == null) { - //sprintf(txt, "%ld", gr1.c2); - gprint("" + gr1.c2); - } else if (num_unit(gr1.c2)) - print_ps(gr1.ps2, mk); - else { - num_show(gr1.c2); - print_ps(gr1.ps2, mk); - } + DTerm dt = gr1.ps; + print_ps(dt, mk); + dt.text = this.getPrintedString(); + } else if (gr1.c == -2) { + } else if (gr1.c == 0) { + } else { + ElTerm el = gr1.el; + print_elims(el, mk); } - - gprint(Cm.s2072); - gprint("\r\n\r\n"); - - gprint("\r\n"); - while (gr1 != null) { - if (pr_elim) { - if (gr1.c == -1) { - gprint(Cm.s2223); - print_ps(gr1.ps, mk); - gprint("\r\n\r\n"); - } else if (gr1.c == -2) { - } else if (gr1.c == 0) { - } else { - print_elims(gr1.el, mk); - gprint("\r\n"); - } - } - if (gr1.c == 0) { - } else { - gprint(" = "); - } - - print_gr(gr1, mk); - gprint("\r\n"); - gr1 = gr1.nx; + if (gr1.c == 0) { + } else { } - gprint("\r\n"); + this.setPrintToString(); + print_gr(gr1, mk); + gr1.text = this.getPrintedString(); + gr1 = gr1.nx; } + return true; +} - - void print_elims(ElTerm el, char mk) { +/** + * Recursively prints elimination terms. + * + * This method prints the elimination term provided and then recursively processes + * any linked elimination terms. It sets the printed text for each elimination element. + * + * @param el the elimination term to print + * @param mk a marker character used during the printing process + */ +void print_elims(ElTerm el, char mk) { // gprint(Cm.s2224); - if (el == null) - return; - + if (el == null) + return; + this.setPrintToString(); + print_elim(el, mk); + el.setText(this.getPrintedString()); + print_elims(el.et, mk); +// gprint("\r\n"); + for (el = el.nx; el != null; el = el.nx) { this.setPrintToString(); print_elim(el, mk); el.setText(this.getPrintedString()); - print_elims(el.et, mk); - -// gprint("\r\n"); - for (el = el.nx; el != null; el = el.nx) { - this.setPrintToString(); - print_elim(el, mk); - el.setText(this.getPrintedString()); - print_elims(el.et, mk); - } } +} static GrTerm el_gr = new GrTerm(); static DTerm el_d1 = new DTerm(); static DTerm el_d2 = new DTerm(); + /** + * Prints the elimination term information. + *+ * If the elimination term is null or its associated variable has a negative index, + * the method returns without printing. Depending on whether the elimination term has + * a first polynomial (p1) or not, the method prints the appropriate representation. + *
+ * + * @param e the elimination term to be printed + * @param mk the marker character used during printing + */ void print_elim(ElTerm e, char mk) { XTerm p1, p2; Var v; @@ -1578,7 +1775,7 @@ void print_elim(ElTerm e, char mk) { p1 = e.p1; p2 = e.p2; // pprint(p1); - // pprint(p2); + // pprint(p2); if (p1.var == null) { el_gr.c1 = p1.c; el_gr.ps1 = null; @@ -1608,22 +1805,27 @@ void print_elim(ElTerm e, char mk) { } } - void print_all_vars() { - Var e1; - - gprint(Cm.s2225); - e1 = all_var.nx; - while (e1 != null) { - print_var(e1, 0); - gprint("\r\n"); - e1 = e1.nx; - } - } - + /** + * Recursively checks whether a geometric term's polynomial parts are regular. + * + * @param gr the geometric term to check + * @return true if both polynomial parts (ps1 and ps2) are regular, false otherwise + */ boolean rgr(GrTerm gr) { return (rps(gr.ps1) && rps(gr.ps2)); } + /** + * Recursively checks whether the given polynomial term is regular. + *+ * A regular term requires that each associated variable has an index of 1, that + * its subsequent term (ps) contains only one element, and that this recursively + * holds for all subsequent terms. + *
+ * + * @param ps1 the polynomial term to check + * @return true if the term is regular, false otherwise + */ boolean rps(DTerm ps1) { DTerm ps2; XTerm p1; @@ -1642,7 +1844,17 @@ boolean rps(DTerm ps1) { return (true); } - + /** + * Prints a geometric term. + *+ * The method prints the term based on its coefficients and polynomial parts. + * Depending on whether the term represents a fraction, an integer, or a combination, + * it formats the output accordingly. + *
+ * + * @param gr the geometric term to print + * @param mk a marker character used during printing + */ void print_gr(GrTerm gr, char mk) { boolean rg; long n; @@ -1710,12 +1922,33 @@ void print_gr(GrTerm gr, char mk) { } } + /** + * Displays a numeric fraction. + *+ * The numerator and denominator are shown separated by a forward slash. + *
+ * + * @param c1 the numerator value + * @param c2 the denominator value + * @param mk a marker character used during printing + */ void show_num2(long c1, long c2, char mk) { num_show(c1); gprint("/"); num_show(c2); } + /** + * Prints a polynomial expression represented by a DTerm. + *+ * If the term has a degree of 1, it is printed normally or with parentheses if the + * expression requires grouping. For higher degree terms, the term is printed with + * an exponent notation. + *
+ * + * @param dp1 the polynomial term to print + * @param mk a marker character used during printing + */ void print_ps(DTerm dp1, char mk) { if (dp1 == null) gprint(""); @@ -1737,7 +1970,6 @@ void print_ps(DTerm dp1, char mk) { } else { gprint("("); print_p(dp1.p, mk); - //sprintf(txt, ")^{%d}", dp1.deg); gprint(")^{" + dp1.deg + "}"); } dp1 = dp1.nx; @@ -1745,28 +1977,17 @@ void print_ps(DTerm dp1, char mk) { } } - boolean chord_p(XTerm p) { - Var v; - if (npoly(p)) return (true); - v = p.var; - return (v.nm == 5); - } - - - /////////////////////////////////// - Vector getAllterms(XTerm p1) { - - Vector list = new Vector(); - if (p1 == null) - return list; - if (p1.var == null) return list; - list.add(p1); - return list; - } - - + /** + * Prints an XTerm (mathematical expression) with its variable and coefficient. + *+ * Constant terms without an associated variable are printed in an angle-signed format. + * For non-constant terms, the method processes the polynomial parts recursively. + *
+ * + * @param p1 the XTerm to be printed + * @param first true if this is the first term (affects sign formatting), false otherwise + */ public void myprint_p1(XTerm p1, boolean first) { - this.setPrintToString(); DTerm dp1, dp2; XTerm xp1; @@ -1809,19 +2030,11 @@ public void myprint_p1(XTerm p1, boolean first) { myprint_p1(dp2.p, false); } - GrTerm mk_el_gr(ElTerm el) { -// gr_term gr1 = mk_gr(mk_num(1L), get_dt(1, p1, null), mk_num(0L), null, 99, null); -// -// el_term e1 = el.et; -// while (e1 != null) { -// xterm p1 = get_m(el.v); -// p1 = eprem(cp_poly(p1), e1); -// fpoly(p1); -// } -// return gr; - return null; - } - + /** + * Counts the number of variable instances. + * + * @return the total number of variables in the linked list starting at all_var.nx + */ int getvarNum() { Var v = all_var.nx; int t = 0; @@ -1832,6 +2045,11 @@ int getvarNum() { return t; } + /** + * Counts the number of line instances. + * + * @return the total number of lines in the linked list starting at all_ln.nx + */ int getlnNum() { LLine ln = all_ln.nx; int t = 0; @@ -1842,6 +2060,16 @@ int getlnNum() { return t; } + /** + * Reorders the points in the given variable. + * + *If the first point is less than the second, they are swapped. + * Similarly, if the third point is less than the fourth, they are swapped. + * Additional reordering is performed if necessary, and the method returns a flag indicating if any reordering took place.
+ * + * @param v the variable whose points are to be reordered + * @return true if reordering occurred; false otherwise + */ boolean var_reOrder(Var v) { int p1, p2, p3, p4, p; boolean sr = false; @@ -1883,6 +2111,19 @@ boolean var_reOrder(Var v) { return sr; } + /** + * Trims the line segments based on the intersection of two lines. + * + *This method retrieves two lines from two pairs of points and checks whether they intersect. + * If an intersection is found, the endpoints are adjusted accordingly. + * Finally, an XTerm is generated using the trimmed endpoints.
+ * + * @param p1 the first coordinate of the first point + * @param p2 the second coordinate of the first point + * @param p3 the first coordinate of the second point + * @param p4 the second coordinate of the second point + * @return the XTerm representing the trimmed line segments + */ XTerm trim_full(int p1, int p2, int p3, int p4) { int t = 0; @@ -1894,29 +2135,46 @@ XTerm trim_full(int p1, int p2, int p3, int p4) { if (p3 != t && p4 != t) p4 = t; } else if (ln1 == null && ln2 != null) { - + // When ln1 is absent and ln2 is present, no adjustment is performed. } return trim_f(p1, p2, p3, p4); } + /** + * Sets the flag to show details. + * + *This static method controls whether detailed information should be displayed.
+ * + * @param d the boolean value to set for showing details + */ public static void set_showdetai(boolean d) { show_detail = d; } - ////////////////////////////////////////////////////////////////////////////////////// - //////////////NDGS /** - * ********************************************** + * Determines if a given type represents a valid construction. + * + *The type is considered valid if it falls within specific ranges and does not require freeCS.
+ * + * @param type the construction type to check + * @return true if the type is a construction type; false otherwise */ - // V1. Constructions. - // V2. Initial NDGS - // V3. Simplified. - // V4 Final NDGS. public boolean isConstructionType(int type) { return (type > 0 && type < 50 || type > 100 && type < 150) && !freeCS(type); } + /** + * Populates the provided vectors with non-degenerate geometry constraints (NDGs) from constructions. + * + *This method iterates through constructions, adds valid constructions to the first vector, + * initializes and filters NDGs, deduces additional constraints, and finally updates the provided vectors.
+ * + * @param v1 a vector for constructions used as NDG constraints + * @param v2 a vector for initial NDGs + * @param v3 a vector for filtered NDGs + * @param v4 a vector for deduced NDGs + */ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg int n = cns_no; @@ -1927,8 +2185,8 @@ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg } vndgs.clear(); - init_ndgs(v2); // Init NDGS. - filter_ndg(v2, v3); // Remove rudundent NDGS. + init_ndgs(v2); // Init NDGs. + filter_ndg(v2, v3); // Remove redundant NDGs. ndg_deduction(v3, v4); filter_ndg(v4); filter_ndg(vndgs); @@ -1938,7 +2196,17 @@ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg v4.addAll(vndgs); } - + /** + * Creates and adds a non-isotropic NDG constraint based on two points. + * + *This method checks that the points are different and valid. + * It creates a new CNdg for non-isotropic constraints and adds it to the provided vector.
+ * + * @param a the first point + * @param b the second point + * @param v1 the vector to which the NDG is added + * @return the created CNdg object, or null if the points are identical or invalid + */ protected CNdg add_n_isotropic(int a, int b, Vector v1) { if (a == b) return null; @@ -1960,6 +2228,20 @@ protected CNdg add_n_isotropic(int a, int b, Vector v1) { return n; } + /** + * Creates and adds an NDG constraint representing parallelism or perpendicularity. + * + *This method reorders four points if needed and creates a corresponding NDG + * depending on the specified type. The resulting constraint is then added to the vector.
+ * + * @param type the type of NDG (e.g. NDG_PARA for parallel or NDG_PERP for perpendicular) + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param v1 the vector to which the NDG is added + * @return the created CNdg object + */ protected CNdg add_n_pt(int type, int a, int b, int c, int d, Vector v1) { if (a > b) { int t = a; @@ -2001,6 +2283,18 @@ protected CNdg add_n_pt(int type, int a, int b, int c, int d, Vector v1) { return n; } + /** + * Creates and adds a collinearity NDG constraint based on three points. + * + *This method reorders the three points to ensure a proper order for establishing collinearity, + * then creates a new CNdg representing the collinearity constraint and adds it to the given vector.
+ * + * @param a the first point + * @param b the second point + * @param c the third point + * @param v1 the vector to which the NDG is added + * @return the created CNdg object + */ protected CNdg add_n_coll(int a, int b, int c, Vector v1) { if (a > b) { int t = a; @@ -2030,6 +2324,14 @@ protected CNdg add_n_coll(int a, int b, int c, Vector v1) { return n; } + /** + * Initializes non-degenerate geometry constraints (NDGs) from existing constructions. + * + *This method iterates through all constructions, creates appropriate NDG constraints based on + * the type of each construction, and associates dependencies with the NDGs when modifications occur.
+ * + * @param v1 the vector to be populated with NDG constraints + */ public void init_ndgs(Vector v1) { CNdg nd; @@ -2057,7 +2359,6 @@ public void init_ndgs(Vector v1) { case C_I_PP: add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[5], c.ps[6], v1); break; - case C_I_TT: add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[5], c.ps[6], v1); break; @@ -2069,7 +2370,7 @@ public void init_ndgs(Vector v1) { case C_O_C: break; case C_CIRCLE: - add_n_coll(c.ps[1], c.ps[2], c.ps[3], v1); ///...../...???? + add_n_coll(c.ps[1], c.ps[2], c.ps[3], v1); break; case C_PARALLELOGRAM: add_coll_para(c, v1); @@ -2083,19 +2384,16 @@ public void init_ndgs(Vector v1) { nd = add_ndg_neq(c.ps[1], c.ps[2]); this.add_ndgs(nd, v1); break; - - /////Special for aline. - case C_I_PA: { CNdg dx = add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[4], c.ps[5], v1); if (dx != null) dx.exists = true; - add_n_neq(c.ps[4], c.ps[5], vndgs); add_n_neq(c.ps[6], c.ps[7], vndgs); add_n_neq(c.ps[8], c.ps[9], vndgs); - XTerm xt = pplus(trim_f(c.ps[2], c.ps[3], c.ps[4], c.ps[5]), trim_f(c.ps[6], c.ps[7], c.ps[7], c.ps[8])); + XTerm xt = pplus(trim_f(c.ps[2], c.ps[3], c.ps[4], c.ps[5]), + trim_f(c.ps[6], c.ps[7], c.ps[7], c.ps[8])); xt = add_deduction(xt); addxtermndg(xt, vndgs); } @@ -2108,7 +2406,8 @@ public void init_ndgs(Vector v1) { add_n_neq(c.ps[3], c.ps[4], vndgs); add_n_neq(c.ps[5], c.ps[6], vndgs); add_n_neq(c.ps[6], c.ps[7], vndgs); - XTerm xt = pplus(trim_f(c.ps[1], c.ps[2], c.ps[3], c.ps[4]), trim_f(c.ps[7], c.ps[6], c.ps[6], c.ps[5])); + XTerm xt = pplus(trim_f(c.ps[1], c.ps[2], c.ps[3], c.ps[4]), + trim_f(c.ps[7], c.ps[6], c.ps[6], c.ps[5])); xt = add_deduction(xt); addxtermndg(xt, vndgs); } @@ -2124,7 +2423,8 @@ public void init_ndgs(Vector v1) { add_n_neq(c.ps[6], c.ps[7], vndgs); add_n_neq(c.ps[8], c.ps[9], vndgs); add_n_neq(c.ps[9], c.ps[10], vndgs); - XTerm xt = pplus(trim_f(c.ps[3], c.ps[4], c.ps[4], c.ps[5]), trim_f(c.ps[1], c.ps[2], c.ps[6], c.ps[7])); + XTerm xt = pplus(trim_f(c.ps[3], c.ps[4], c.ps[4], c.ps[5]), + trim_f(c.ps[1], c.ps[2], c.ps[6], c.ps[7])); xt = pplus(xt, trim_f(c.ps[10], c.ps[9], c.ps[9], c.ps[8])); xt = add_deduction(xt); addxtermndg(xt, vndgs); @@ -2141,11 +2441,30 @@ public void init_ndgs(Vector v1) { } + /** + * Adds a non-equality NDG constraint for the given points. + * + *This method creates an NDG constraint of type NDG_NEQ (or equivalent) for points a and b, + * then adds it to the provided vector.
+ * + * @param a the first point index + * @param b the second point index + * @param v1 the vector to add the NDG constraint + */ public void add_n_neq(int a, int b, Vector v1) { CNdg nd = add_ndg_neq(a, b); this.add_ndgs(nd, v1); } + /** + * Creates and adds a collinearity constraint in parallel form based on a construction. + * + *This method determines the highest point value from the construction's point array, then + * selects the three remaining points to build a collinearity NDG constraint and adds it to vector v1.
+ * + * @param cs the construction containing the points + * @param v1 the vector to add the NDG constraint + */ public void add_coll_para(Cons cs, Vector v1) { int a, b; @@ -2173,6 +2492,16 @@ else if (c3 < 0 && i != b) add_n_coll(c1, c2, c3, v1); } + /** + * Deduces angle-based NDG constraints and processes them. + * + *This method handles a given CNdg constraint by checking if all associated points are free. + * If so, it directly duplicates the constraint into vector v4; otherwise, it computes an XTerm deduction + * based on the NDG type and adds related non-equality constraints.
+ * + * @param c the CNdg constraint to analyze + * @param v4 the vector in which the deduced NDG constraints are stored + */ public void angle_deduction(CNdg c, Vector v4) { if (c == null) return; @@ -2217,18 +2546,16 @@ public void angle_deduction(CNdg c, Vector v4) { } } - - protected void add_deduction(int a, int b, int c, int d, Vector v4) { - XTerm x = trim_f(a, b, c, d); - XTerm x1 = add_deduction(x); - if (pzerop(pminus(cp_poly(x), cp_poly(x1)))) { - - } else { - - } - - } - + /** + * Checks and adds a non-equality constraint between two points if not already present. + * + *This method iterates over the vector v4 to determine if an equivalent NDG constraint exists. + * If none is found, a new NDG constraint (NDG_NEQ) for the pair of points is created and added.
+ * + * @param a the first point index + * @param b the second point index + * @param v4 the vector containing NDG constraints + */ protected void add_neqTo(int a, int b, Vector v4) { for (int i = 0; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); @@ -2252,6 +2579,15 @@ protected void add_neqTo(int a, int b, Vector v4) { add_ndgs(d, v4); } + /** + * Checks whether all points in the given CNdg constraint are free. + * + *This method iterates over the points associated with the constraint and calls freeCSP + * for each one. It returns false as soon as any point is not free.
+ * + * @param d the CNdg constraint to check + * @return true if all points are free; false otherwise + */ protected boolean ck_allFree(CNdg d) { if (d == null) return true; @@ -2262,8 +2598,16 @@ protected boolean ck_allFree(CNdg d) { return true; } + /** + * Performs angle deduction on the given XTerm. + * + *If the XTerm has an associated variable, angle-based deduction is applied followed by + * a final deduction adjustment.
+ * + * @param x the XTerm to deduct + * @return the resulting XTerm after deduction + */ protected XTerm add_deduction(XTerm x) { - if (x.var == null) return x; @@ -2272,6 +2616,14 @@ protected XTerm add_deduction(XTerm x) { return xt; } + /** + * Applies a final deduction adjustment to an XTerm. + * + *If the factor computed by fcc is negative, the XTerm is multiplied by -1.
+ * + * @param p1 the XTerm to adjust + * @return the adjusted XTerm + */ protected XTerm final_deduction(XTerm p1) { if (p1 == null) return p1; @@ -2282,8 +2634,15 @@ protected XTerm final_deduction(XTerm p1) { return p1; } + /** + * Filters out redundant NDG constraints in the given vector. + * + *This method compares each NDG constraint in the vector with the others and removes any + * that are equal or less significant than another constraint.
+ * + * @param v4 the vector containing NDG constraints to filter + */ protected void filter_ndg(Vector v4) { - for (int i = 0; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); for (int j = i + 1; j < v4.size(); j++) { @@ -2301,11 +2660,18 @@ protected void filter_ndg(Vector v4) { } } } - } + /** + * Filters and merges NDG constraints from vector v2 into vector v3. + * + *This method iterates over the constraints in v2 and checks against those in v3. + * If an equivalent or less significant constraint exists, it merges or sets an equivalence link.
+ * + * @param v2 the source vector of NDG constraints + * @param v3 the target vector for filtered NDG constraints + */ protected void filter_ndg(Vector v2, Vector v3) { - for (int i = 0; i < v2.size(); i++) { CNdg d = (CNdg) v2.get(i); boolean added = false; @@ -2333,16 +2699,33 @@ protected void filter_ndg(Vector v2, Vector v3) { } } + /** + * Adds an NDG constraint to the specified vector. + * + *This helper method ensures the NDG constraint is valid (non-null), initializes its string + * representation by calling get_ndgstr, and then adds it to the vector.
+ * + * @param d the NDG constraint to add + * @param vlist the vector where the NDG constraint is stored + */ protected void add_ndgs(CNdg d, Vector vlist) { if (d == null) return; get_ndgstr(d); - - vlist.add(d); } + /** + * Compares two NDG constraints to determine if the first is less significant than the second. + * + *For non-equality NDGs, if the second constraint is of type NDG_COLL and contains both points + * of the first constraint, the first is considered less significant.
+ * + * @param n1 the first NDG constraint + * @param n2 the second NDG constraint + * @return true if n1 is less significant than n2; false otherwise + */ protected boolean ndg_less(CNdg n1, CNdg n2) { if (n1.type == NDG_NEQ || n1.type == NDG_NON_ISOTROPIC) { if (n2.type == NDG_COLL) { @@ -2353,6 +2736,16 @@ protected boolean ndg_less(CNdg n1, CNdg n2) { return false; } + /** + * Checks whether two NDG constraints are equal. + * + *This method first compares their types (allowing for NDG_NEQ and NDG_NON_ISOTROPIC to be equivalent), + * then verifies that the number of points and the point values are identical.
+ * + * @param n1 the first NDG constraint + * @param n2 the second NDG constraint + * @return true if the two constraints are equal; false otherwise + */ protected boolean ndg_eq(CNdg n1, CNdg n2) { if (n1.type != n2.type) { if ((n1.type == NDG_NEQ || n1.type == NDG_NON_ISOTROPIC) @@ -2371,6 +2764,15 @@ protected boolean ndg_eq(CNdg n1, CNdg n2) { return true; } + /** + * Converts an XTerm into an NDG constraint and adds its printed representation. + * + *This method first converts the XTerm into a corresponding NDG constraint via xterm2ndg, + * then updates its string representation using the printing methods.
+ * + * @param x the XTerm to convert and add + * @param v4 the vector where the NDG information is stored + */ protected void addxtermndg(XTerm x, Vector v4) { if (x == null) return; @@ -2382,6 +2784,16 @@ protected void addxtermndg(XTerm x, Vector v4) { } + /** + * Converts an XTerm into NDG constraints and adds them to the provided list. + *+ * Depending on the term number of the XTerm, the method delegates to a helper method + * to generate the appropriate NDG constraints. + *
+ * + * @param x the XTerm to convert + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm2ndg(XTerm x, Vector vlist) { if (x == null || x.var == null) return; @@ -2392,9 +2804,18 @@ protected void xterm2ndg(XTerm x, Vector vlist) { xterm_1term(x, vlist); else if (n == 1) xterm_2term(x, vlist); - } + /** + * Processes an XTerm with one term to generate NDG constraints. + *+ * The method examines the factor computed by {@code fcc(x)} and based on its value, + * creates and adds NDG constraints using parallel, perpendicular, or triple PI rules. + *
+ * + * @param x the XTerm to process + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm_1term(XTerm x, Vector vlist) { long n = fcc(x); @@ -2422,6 +2843,16 @@ protected void xterm_1term(XTerm x, Vector vlist) { } } + /** + * Creates a Triple PI NDG constraint from the specified variable. + *+ * It initializes the NDG using the points from the variable and reorders them, + * setting the number of points to 3. + *
+ * + * @param v the variable containing the points for the NDG constraint + * @return the constructed Triple PI NDG constraint + */ protected CNdg add_ndg_triplePI(Var v) { CNdg n = new CNdg(); n.type = NDG_TRIPLEPI; @@ -2436,7 +2867,16 @@ protected CNdg add_ndg_triplePI(Var v) { return n; } - + /** + * Processes an XTerm with two terms to generate NDG constraints. + *+ * The method examines the second term of the XTerm and creates congruency or collinearity NDGs + * based on the sign of the factor computed by {@code fcc} for the second term. + *
+ * + * @param x the XTerm to process + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm_2term(XTerm x, Vector vlist) { long n = fcc(x); if (x.ps != null) { @@ -2448,7 +2888,7 @@ protected void xterm_2term(XTerm x, Vector vlist) { Var v1 = x.var; Var v2 = x1.var; - if (v2 != null) { // v2 != null 0) { if (v1.pt[2] == v2.pt[2] && v1.pt[3] == v2.pt[3]) { @@ -2478,8 +2916,7 @@ protected void xterm_2term(XTerm x, Vector vlist) { } } } - } else // n.p[1]) { - int d = n.p[0]; - n.p[0] = n.p[1]; - n.p[1] = d; - } } + /** + * Reorders the points in an NDG constraint (with three points) into ascending order. + * + * @param n the NDG constraint whose points are to be reordered + */ protected void reorder3(CNdg n) { for (int i = 0; i < 2; i++) { - int d = n.p[i]; if (d > n.p[i + 1]) { n.p[i] = n.p[i + 1]; @@ -2516,6 +2944,14 @@ protected void reorder3(CNdg n) { } } + /** + * Reorders two pairs of points in an NDG constraint so that each pair is in ascending order. + *+ * In addition, it ensures that the first pair is sorted relative to the second pair. + *
+ * + * @param n the NDG constraint whose points are to be reordered + */ protected void reorder22(CNdg n) { if (n.p[0] > n.p[1]) { int d = n.p[0]; @@ -2539,6 +2975,16 @@ protected void reorder22(CNdg n) { } } + /** + * Creates a non-equality NDG constraint for two points. + *+ * Returns null if both points are identical. + *
+ * + * @param a the first point index + * @param b the second point index + * @return the NDG non-equality constraint, or null if the points are identical + */ protected CNdg add_ndg_neq(int a, int b) { if (a == b) return null; @@ -2557,113 +3003,15 @@ protected CNdg add_ndg_neq(int a, int b) { return n; } - protected void parse_ndg_neq(int a, int b, Vector v4) { - if (a == b) - return; - - if (a > b) { - int c = a; - a = b; - b = c; - } - - if (APT(a) == null && APT(b) == null) return; - - if (freeCSP(a) && freeCSP(b)) { - CNdg n = new CNdg(); - n.type = NDG_NON_ISOTROPIC; - n.p[0] = a; - n.p[1] = b; - n.no = 1; - add_ndgs(n, v4); - } else { - XTerm x = parseNEQ(a, b, v4); - if (x != null) - addxtermndg(x, v4); - } - } - - private XTerm parseNEQ(int a, int b, Vector v2) { - - for (int i = 0; i < v2.size(); i++) { - CNdg n = (CNdg) v2.get(i); - if (n.type == NDG_NEQ || n.type == NDG_NON_ISOTROPIC) { - { - XTerm x1 = parseNEQ(a, b, n.p[0], n.p[1], v2); - if (x1 != null) - return x1; - } - } else if (n.type == NDG_COLL) { - { - XTerm x1 = parseNEQ(a, b, n.p[0], n.p[1], v2); - if (x1 != null) - return x1; - x1 = parseNEQ(a, b, n.p[0], n.p[2], v2); - if (x1 != null) - return x1; - x1 = parseNEQ(a, b, n.p[1], n.p[2], v2); - if (x1 != null) - return x1; - } - } - } - return null; - } - - - private XTerm parseNEQ(int a, int b, int a1, int b1, Vector v2) { - if (a == a1 || a == b1) return null; - if (b == a1 || b == b1) return null; - if (!freeCSP(a1) || !freeCSP(b1)) - return null; - if (check_coll(a1, b1, a) || check_coll(a1, b1, b)) - return null; - - XTerm x1 = pminus(trim_f(a, a1, a1, b1), trim_f(b, a1, a1, b1)); - XTerm x2 = pminus(trim_f(a, b1, a1, b1), trim_f(b, b1, a1, b1)); - this.setPrintToScreen(); - - this.pprint(x1); - this.pprint(x2); - - x1 = angle_deduction(x1); - x2 = angle_deduction(x2); - if (eq_poly(x1, x2)) return x1; - x2 = this.neg_poly(x2); - if (eq_poly(x1, x2)) return x1; - this.pprint(x1); - this.pprint(x2); - return null; - } - - private void addPairsToList(Object o, Object o1, Vector v) { - int n = v.size() / 2; - for (int i = 0; i < n; i++) { - if (o == v.get(2 * i) && o1 == v.get(2 * i + 1)) - return; - if (o1 == v.get(2 * i) && o == v.get(2 * i + 1)) - return; - } - v.add(o); - v.add(o1); - } - - public int getFreeSemiFix(int index) { - ProPoint pt = APT(index); - if (pt == null) - return 0; - - int n = 0; - for (int i = 1; i <= cns_no; i++) { - Cons c = allcns[i]; - if (c.ps[0] == index && !freeCS(c.type)) { - n++; - } - } - - return n; - } - + /** + * Checks whether the point at the given index is free from constraints. + *+ * It retrieves the associated point object and checks its construction type. + *
+ * + * @param index the index of the point to check + * @return true if the point is free; false otherwise + */ public boolean freeCSP(int index) { ProPoint pt = APT(index); if (pt == null) @@ -2681,11 +3029,31 @@ public boolean freeCSP(int index) { return freeCS(type); } + /** + * Determines if the given construction type represents a free state. + *+ * A type is considered free if it matches one of the basic construction types. + *
+ * + * @param t the construction type to check + * @return true if the type is free; false otherwise + */ public boolean freeCS(int t) { return t == 0 || t == C_POINT || t == C_LINE || t == C_TRIANGLE || t == C_QUADRANGLE || t == C_PENTAGON || t == C_POLYGON || t == C_CIRCLE; } + /** + * Creates a collinearity NDG constraint from three points. + *+ * The points are reordered to ensure proper ordering. If redundant, then null is returned. + *
+ * + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @return the NDG collinearity constraint, or null if the points are redundant + */ protected CNdg add_ndg_coll(int a, int b, int c) { CNdg n = new CNdg(); n.type = NDG_COLL; @@ -2700,6 +3068,18 @@ protected CNdg add_ndg_coll(int a, int b, int c) { else return n; } + /** + * Creates a congruency NDG constraint based on four points. + *+ * The points are reordered; if the set of points is redundant, null is returned. + *
+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG congruency constraint, or null if the points are redundant + */ protected CNdg add_ndg_cong(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_CONG; @@ -2715,11 +3095,29 @@ protected CNdg add_ndg_cong(int a, int b, int c, int d) { else return null; } - + /** + * Creates a parallel NDG constraint using the points of a given variable. + * + * @param v the variable containing the points for the constraint + * @return the NDG parallel constraint + */ protected CNdg add_ndg_para(Var v) { return add_ndg_para(v.pt[0], v.pt[1], v.pt[2], v.pt[3]); } + /** + * Creates a parallel NDG constraint based on four point indices. + *+ * The points are reordered to ascending order; if the set is redundant, + * an alternative collinearity constraint is constructed instead. + *
+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG parallel constraint, or an alternative NDG constraint if redundant + */ protected CNdg add_ndg_para(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_PARA; @@ -2748,10 +3146,28 @@ protected CNdg add_ndg_para(int a, int b, int c, int d) { return n; } + /** + * Creates a perpendicular NDG constraint using the points of a given variable. + * + * @param v the variable containing the points for the constraint + * @return the NDG perpendicular constraint + */ protected CNdg add_ndg_perp(Var v) { return add_ndg_perp(v.pt[0], v.pt[1], v.pt[2], v.pt[3]); } + /** + * Creates a perpendicular NDG constraint based on four point indices. + *+ * If the two segments are identical, a non-isotropic NDG constraint is created instead. + *
+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG perpendicular constraint, or a non-isotropic constraint when applicable + */ protected CNdg add_ndg_perp(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_PERP; @@ -2771,6 +3187,12 @@ protected CNdg add_ndg_perp(int a, int b, int c, int d) { } + /** + * Sets the string representation (sd) of the given NDG constraint (d) based on its type + * and associated points. Depending on the type, constructs a descriptive message. + * + * @param d the NDG constraint for which the string representation is set + */ protected void get_ndgstr(CNdg d) { String sd = ""; switch (d.type) { @@ -2804,10 +3226,12 @@ protected void get_ndgstr(CNdg d) { int a, b; if (d.p[0] == n) a = d.p[1]; - else a = d.p[0]; + else + a = d.p[0]; if (d.p[2] == n) b = d.p[3]; - else b = d.p[2]; + else + b = d.p[2]; sd = Cm.ANGLE_SIGN + "[" + ANAME(a) + ANAME(n) + ANAME(b) + "] != (n*PI) / 3 (n = 0, 1, 2, 3 ..)"; @@ -2818,8 +3242,15 @@ protected void get_ndgstr(CNdg d) { d.sd = sd; } + /** + * Performs angle deduction on the given XTerm. This method initializes necessary properties + * and iteratively attempts to eliminate terms using various elimination methods. At the end, + * it optimizes the term based on triangle configurations. + * + * @param p1 the XTerm on which angle deduction is performed + * @return the resulting XTerm after angle deduction + */ protected XTerm angle_deduction(XTerm p1) { - ertype = 0; pro_type = PRO_FULL; max_term = 0; @@ -2827,11 +3258,11 @@ protected XTerm angle_deduction(XTerm p1) { qerror = false; last_pr = proof = new GrTerm(); dbase(); - if (qerror) return null; + if (qerror) + return null; ElTerm e1 = null; do { - if (npoly(p1)) { return p1; } @@ -2857,12 +3288,18 @@ protected XTerm angle_deduction(XTerm p1) { } } while (e1 != null); - p1 = opt_tri(p1); return p1; } - + /** + * Optimizes the given XTerm by detecting and processing triangle configurations. + * It compares factors from the current term and its subterm to determine if any adjustment + * such as scaling or subtraction should be applied. + * + * @param x the XTerm to be optimized + * @return the optimized XTerm + */ public XTerm opt_tri(XTerm x) { long n = fcc(x); if (x.ps != null) { @@ -2880,7 +3317,6 @@ public XTerm opt_tri(XTerm x) { p1 = ptimes(this.get_n(n), p1); return pminus(x, p1); } - } else if (v1.pt[0] == v2.pt[2] && v1.pt[1] == v2.pt[3]) { XTerm p1 = pplus(get_m(v1), get_m(v2)); p1 = pminus(p1, trim_f(v2.pt[0], v2.pt[1], v1.pt[2], v1.pt[3])); @@ -2911,25 +3347,39 @@ public XTerm opt_tri(XTerm x) { return x; } - //////////////////////////////////////////////////////////////////////////////// - //ndg deduction. + /** + * Performs NDG (non-degeneracy) deduction on a set of NDG constraints. + * For each constraint in the source vector v3, if the constraint is marked as existing + * or if all its points are free, it is directly added or duplicated into the target vector v4. + * Otherwise, angle deduction is applied. + * + * @param v3 the source vector of NDG constraints + * @param v4 the target vector to store the deduced NDG constraints + */ public void ndg_deduction(Vector v3, Vector v4) { - for (int i = 0; i < v3.size(); i++) { CNdg d = (CNdg) v3.get(i); if (d.exists) { + // Existing NDG constraints are skipped. } else if (ck_allFree(d)) { CNdg d1 = new CNdg(d); v4.add(d1); - } else + } else { angle_deduction(d, v4); + } } } - + /** + * Compares two NDG constraints based on their maximum integer values. + * + * @param d1 the first NDG constraint + * @param d2 the second NDG constraint + * @return a positive value if d1 > d2, a negative value if d1 < d2, or zero if they are equal + */ public int compare(CNdg d1, CNdg d2) { - if (d1 == d2) return 0; - + if (d1 == d2) + return 0; int n1 = d1.getMaxInt(); int n2 = d2.getMaxInt(); if (n1 > n2) @@ -2939,6 +3389,12 @@ public int compare(CNdg d1, CNdg d2) { return 0; } + /** + * Sorts a vector of NDG constraints in ascending order based on their significance. + * It uses the compare method to insert each constraint into its correct position in the vector. + * + * @param v4 the vector containing NDG constraints to be sorted + */ public void sortVector(Vector v4) { for (int i = 1; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); @@ -2954,6 +3410,17 @@ public void sortVector(Vector v4) { } } + /** + * Parses non-equality and non-isotropic NDG constraints from the given vector. + *+ * This method sorts the input vector of NDG constraints, filters out those + * constraints that are non-equality (NDG_NEQ) or non-isotropic (NDG_NON_ISOTROPIC) + * and have both points free, and then processes the remaining constraints. + * The remaining constraints are added to a global NDG list after being updated. + *
+ * + * @param v4 the vector containing NDG constraints to be parsed + */ public void parse_neq(Vector v4) { sortVector(v4); @@ -2971,7 +3438,7 @@ public void parse_neq(Vector v4) { i--; } -// vndgs.clear(); + // vndgs.clear(); vndgs.addAll(v4); for (int i = 0; i < v5.size(); i++) { @@ -2987,6 +3454,15 @@ public void parse_neq(Vector v4) { return; } + /** + * Recursively updates the string documentation (SD) for the provided NDG constraint structure. + *+ * For each constraint in the structure, the method updates its point string array and resets its text. + * The method also recurses into any child constraint sets. + *
+ * + * @param dd the NDG constraint structure to update + */ private void updateSD(NdgCs dd) { if (dd == null) return; @@ -3003,7 +3479,18 @@ private void updateSD(NdgCs dd) { updateSD(dd.child[i]); } - public NdgCs getCS(CNdg d) {// d : type of neq. + /** + * Constructs and returns an NDG constraint set (NdgCs) associated with the given inequality constraint. + *+ * The method iterates through existing constraints and gathers those related to + * the points of the provided constraint. The collected constraints are then added + * to a new NdgCs structure and updated. + *
+ * + * @param d the NDG inequality constraint used as a basis for gathering related constraints + * @return the constructed NDG constraint set (NdgCs) + */ + public NdgCs getCS(CNdg d) { int n = d.getMaxInt(); NdgCs c = new NdgCs(); @@ -3038,6 +3525,11 @@ public NdgCs getCS(CNdg d) {// d : type of neq. return dd; } + /** + * Updates the point string array (pss) of the specified constraint using the global points array. + * + * @param c the constraint whose point string array is to be updated + */ private void updatePSS(Cons c) { if (c == null) return; @@ -3047,6 +3539,15 @@ private void updatePSS(Cons c) { } } + /** + * Recursively adds all constraints related to the constraint at index nx into the provided NDG constraint set. + *+ * For each point within the constraint, the method checks previous constraints for related ones and adds them. + *
+ * + * @param nx the index of the current constraint in the global constraints array + * @param d the NDG constraint set (NdgCs) where related constraints are added + */ private void add_RelatedCnsToDg(int nx, NdgCs d) { Cons c = allcns[nx]; @@ -3070,6 +3571,15 @@ private void add_RelatedCnsToDg(int nx, NdgCs d) { d.add(nx, c); } + /** + * Adds the provided constraint to the given NDG constraint set. + *+ * Based on the type of the constraint, it may clone the constraint or generate additional constraints. + *
+ * + * @param c the constraint to be added + * @param d the NDG constraint set (NdgCs) that will include the constraint + */ public void addConsToNdgcs(Cons c, NdgCs d) { if (c == null) return; @@ -3124,6 +3634,19 @@ public void addConsToNdgcs(Cons c, NdgCs d) { } } + /** + * Creates a new constraint with 7 points and adds it to the specified NDG constraint set. + * + * @param type the type of the new constraint + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @param d the fourth point index + * @param e the fifth point index + * @param f the sixth point index + * @param g the seventh point index + * @param d1 the NDG constraint set (NdgCs) where the new constraint will be added + */ public void add_cons(int type, int a, int b, int c, int d, int e, int f, int g, NdgCs d1) { Cons c1 = new Cons(type); c1.add_pt(a); @@ -3137,6 +3660,16 @@ public void add_cons(int type, int a, int b, int c, int d, int e, int f, int g, d1.add(c1); } + /** + * Creates a new constraint with 4 points and adds it to the specified NDG constraint set. + * + * @param type the type of the new constraint + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @param d the fourth point index + * @param d1 the NDG constraint set (NdgCs) where the new constraint will be added + */ public void add_cons(int type, int a, int b, int c, int d, NdgCs d1) { Cons c1 = new Cons(type); c1.add_pt(a); @@ -3147,6 +3680,17 @@ public void add_cons(int type, int a, int b, int c, int d, NdgCs d1) { d1.add(c1); } + /** + * Checks whether the specified constraint is recursively valid with respect to the given NDG type. + *+ * Depending on the type of the constraint, it recursively checks if related NDG constraints already exist. + *
+ * + * @param c the constraint to check + * @param cs the NDG constraint set (NdgCs) in which the check is performed + * @param type the NDG type against which the constraint is validated + * @return true if the constraint is valid; false otherwise + */ public boolean ck_right(Cons c, NdgCs cs, int type) { if (c == null || cs == null) return true; @@ -3164,11 +3708,19 @@ public boolean ck_right(Cons c, NdgCs cs, int type) { return true; } + /** + * Removes NDG constraint set nodes that have no constraints from the provided NDG structure. + *+ * This method recursively traverses the child NDG constraint sets and nullifies any reference that + * does not contain constraints. + *
+ * + * @param c the NDG constraint set (NdgCs) from which null nodes will be removed + */ private void rm_null_ndgcs(NdgCs c) { if (c == null) return; - int n = c.getCSindex(); for (int i = 0; i <= n; i++) { NdgCs cc = c.child[i]; @@ -3190,6 +3742,15 @@ private void rm_null_ndgcs(NdgCs c) { } } + /** + * Removes extraneous constraints from the given NDG constraint set. + *+ * At a leaf node, this method nullifies any constraints that are marked as extraneous. + * For non-leaf nodes, the method recurses through each child NDG constraint set. + *
+ * + * @param c the NDG constraint set (NdgCs) from which extraneous constraints will be removed + */ private void rm_excons(NdgCs c) { if (c == null) return; @@ -3211,6 +3772,14 @@ private void rm_excons(NdgCs c) { } } + /** + * Checks if the constraint at the given index in the NDG constraint set is extraneous + * by comparing it with the corresponding constraint at the root of the constraint set. + * + * @param cs the NDG constraint set + * @param index the index of the constraint to check + * @return true if the constraint is considered extraneous; false otherwise + */ private boolean cons_ex(NdgCs cs, int index) { Cons c = cs.allcns[index]; @@ -3225,6 +3794,15 @@ private boolean cons_ex(NdgCs cs, int index) { return c1.isEqual(c); } + /** + * Recursively checks constraints in an NDG constraint set for consistency. + * For leaf nodes, it verifies each constraint against its expected conditions; + * for non-leaf nodes, it cleans up inconsistent child sets. + * + * @param c the NDG constraint set to check + * @param type the type identifier for the check; usage depends on the context + * @return true if the constraint set is consistent; false otherwise + */ public boolean ck_right(NdgCs c, int type) { if (c == null) return true; @@ -3232,7 +3810,6 @@ public boolean ck_right(NdgCs c, int type) { NdgCs[] css = c.child; int a = c.getCSindex(); if (a < 0) { // leaf node. - for (int i = 0; i <= c.no; i++) { if (c.allcns[i] == null) continue; @@ -3255,6 +3832,13 @@ public boolean ck_right(NdgCs c, int type) { return true; } + /** + * Parses non-equality and non-isotropic NDG constraints by replacing point indices, + * reordering constraints, and invoking further parsing, cleanup, and optimization steps. + * + * @param nd the NDG constraint to be parsed + * @return the updated NDG constraint set after parsing + */ public NdgCs parse_neq(CNdg nd) { NdgCs c = getCS(nd); NdgCs cx = new NdgCs(c); @@ -3277,9 +3861,9 @@ public NdgCs parse_neq(CNdg nd) { } parseStep(cx); ck_leaf(c); - rm_excons(c); // remove exists cons - rm_null_ndgcs(c); // remove ndgcs without child. - ck_right(c, 1); // remove cons which is contradict with its parents. + rm_excons(c); // remove existing constraints + rm_null_ndgcs(c); // remove NDG sets without children + ck_right(c, 1); // remove constraints contradicting with parents int n1 = c.getCSindex(); ck_right(c, 0); if (n1 >= 0 && c.getCSindex() < 0) @@ -3289,9 +3873,13 @@ public NdgCs parse_neq(CNdg nd) { return c; } - //////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - + /** + * Compares two constraints based on their last point and type. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @return a positive integer if c1 > c2, a negative integer if c1 < c2, or 0 if they are equal + */ private int compare(Cons c1, Cons c2) { if (c1 == null) { if (c2 == null) @@ -3314,6 +3902,13 @@ private int compare(Cons c1, Cons c2) { return 0; } + /** + * Reorders constraints within an NDG constraint set. + * For leaf nodes, it sorts the constraints in ascending order; + * for non-leaf nodes, it recursively reorders each child set. + * + * @param c the NDG constraint set to reorder + */ private void cons_reorder(NdgCs c) { if (c == null) return; @@ -3325,7 +3920,6 @@ private void cons_reorder(NdgCs c) { c.allcns[i] = c.allcns[j]; c.allcns[j] = null; } - } else { if (c.allcns[j] != null) { if (compare(c.allcns[i], c.allcns[j]) > 0) { @@ -3345,6 +3939,12 @@ private void cons_reorder(NdgCs c) { } } + /** + * Checks whether an NDG constraint set is a leaf node. + * A node is considered a leaf if it has no child NDG constraint sets. + * + * @param c the NDG constraint set to check + */ private void ck_leaf(NdgCs c) { if (c == null) return; @@ -3357,8 +3957,12 @@ private void ck_leaf(NdgCs c) { } } + /** + * Recursively removes non-leaf NDG constraint set nodes that are not required. + * + * @param c the NDG constraint set from which non-leaf nodes will be removed + */ private void rm_nleaf(NdgCs c) { - if (c == null || c.leaf) return; @@ -3375,23 +3979,28 @@ private void rm_nleaf(NdgCs c) { for (int i = 0; i <= n; i++) { rm_nleaf(c.child[i]); } - } } - private boolean parseStep(NdgCs c) { // Main Process of Parsing. + /** + * Main process for parsing constraints within the NDG constraint set. + * This method performs optimization, redundant constraint removal, and processes + * constraints based on their maximum index. + * + * @param c the NDG constraint set to parse + * @return true if parsing completes successfully; otherwise, false + */ + private boolean parseStep(NdgCs c) { if (c == null) return true; - - opt_cons(c); // reorder. P to L + opt_cons(c); // reorder constraints (P to L) rm_redundent(c); if (c.getNotNullNum() <= 1) return true; int max = c.getMaxCnsInt(); - int n = c.no; for (int i = 0; i <= n; i++) { Cons c1 = c.allcns[i]; @@ -3402,7 +4011,6 @@ private boolean parseStep(NdgCs c) { // Main Process of Parsing. for (int j = i + 1; j <= n; j++) { Cons c2 = c.allcns[j]; - if (c2 == null) continue; if (c2.getLastPt() != max) @@ -3432,20 +4040,28 @@ private boolean parseStep(NdgCs c) { // Main Process of Parsing. break; } break; - - case C_CIRCUM: { + case C_CIRCUM: switch (c2.type) { case C_CIRCUM: parse_ndg_circums(c, c1, c2); break; } - } + break; } } } return true; } + /** + * Processes cyclic NDG constraints by identifying collinear points among + * the constraints and generating additional equality constraints as needed. + * + * @param c the NDG constraint set containing the constraints + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return false after processing is complete + */ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { int o = c1.ps[0]; @@ -3475,9 +4091,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { switch (cx.type) { case C_O_L: if (xcoll(pp[i], pp[j], pp[k])) { - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[j], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3487,9 +4102,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc, nc1); parseStep(nc1); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[k], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3499,9 +4113,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc, nc1); parseStep(nc1); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[j], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3519,14 +4132,16 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { } } } - return false; } - private boolean onOneCons(int a, int b, Cons c1) { - return c1.contains(a) && c1.contains(b); - } - + /** + * Adds point p to the array pp if it is not already present. + * The method fills the first available zero slot. + * + * @param p the point index to add + * @param pp the array of point indices + */ private void addPtNoRedunent(int p, int[] pp) { for (int i = 0; i < pp.length; i++) { if (pp[i] == p) @@ -3538,6 +4153,15 @@ private void addPtNoRedunent(int p, int[] pp) { } } + /** + * Parses NDG constraints of type LL by comparing two constraints and creating new NDG constraint sets. + * It creates new equality or collinearity constraints based on the matched point indices. + * + * @param c the NDG constraint set + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return true if parsing takes place; false otherwise + */ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { int n1 = c1.getLastPt(); @@ -3566,9 +4190,8 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { } else return false; - //if (ck_recursive_ndg(c, NDG_COLL, m, a, b, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3581,7 +4204,7 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { } if (!ck_recursive_ndg(1, c, NDG_COLL, m, a, b, 0)) { - NdgCs nc2 = new NdgCs(c); // Collinear M A B; A != B + NdgCs nc2 = new NdgCs(c); // Collinear M A B; A != B nc2.parent = c; c.addChild(nc2); Cons cc = new Cons(C_O_L); @@ -3593,9 +4216,8 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { parseStep(nc2); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, a, b, 0, 0)) { - NdgCs nc3 = new NdgCs(c); // A = B. + NdgCs nc3 = new NdgCs(c); // A = B. nc3.parent = c; c.addChild(nc3); Cons cc = new Cons(C_I_EQ); @@ -3610,7 +4232,20 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { return true; } - + /** + * Recursively checks for an NDG constraint that meets the specified parameters. + * In global mode (type 0) the search is performed in the global NDG list, + * while in recursive mode (type 1) the search goes through the current constraint set's parent chain. + * + * @param type the check mode (0 for global, 1 for recursive search) + * @param cs the NDG constraint set to check within + * @param t the NDG type to check (e.g. NDG_COLL, NDG_NEQ) + * @param a the first point index involved in the constraint + * @param b the second point index involved in the constraint + * @param c the third point index, or 0 if not used + * @param d the fourth point index, or 0 if not used + * @return true if a matching NDG constraint is found; false otherwise + */ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, int d) { if (type == 0) { @@ -3630,7 +4265,6 @@ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, if (dd == null) return false; - while (cs != null) { if (cs.nd != null && ck_ndg(t, a, b, c, d, cs.nd)) return true; @@ -3640,6 +4274,19 @@ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, return false; } + /** + * Checks if the provided NDG constraint (dd) satisfies the condition for the given NDG type. + * For collinearity (NDG_COLL), it checks if the constraint contains the three specified points. + * For inequality types (NDG_NEQ or NDG_NON_ISOTROPIC), it checks if the constraint contains the two specified points. + * + * @param t the NDG type to evaluate (e.g. NDG_COLL, NDG_NEQ) + * @param a the first point index + * @param b the second point index + * @param c the third point index, or 0 if not applicable + * @param d the fourth point index, or 0 if not applicable + * @param dd the NDG constraint to check + * @return true if the NDG constraint meets the criteria; false otherwise + */ private boolean ck_ndg(int t, int a, int b, int c, int d, CNdg dd) { boolean r = false; @@ -3648,28 +4295,29 @@ private boolean ck_ndg(int t, int a, int b, int c, int d, CNdg dd) { if (dd.type == NDG_COLL) { r = dd.contain(a) && dd.contain(b) && dd.contain(c); } else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) { -// int n = 0; -// if (dd.contain(a)) -// n++; -// if (dd.contain(b)) -// n++; -// if (dd.contain(c)) -// n++; -// r = n >= 2; + // Condition for NDG_NEQ or NDG_NON_ISOTROPIC is omitted. } break; case NDG_NEQ: case NDG_NON_ISOTROPIC: if (dd.type == NDG_COLL) r = dd.contain(a) && dd.contain(b); - else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) { + else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) r = dd.contain(a) && dd.contain(b); - } break; } return r; } + /** + * Parses NDG constraints of type LT by comparing two constraints and creating new constraint sets. + * This method adjusts point orders and generates equality constraints when necessary. + * + * @param c the NDG constraint set + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return true if parsing proceeded; false otherwise + */ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { int n1 = c1.getLastPt(); @@ -3711,11 +4359,10 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { int x = a; a = b; b = x; - } // b = n1; - + } { - NdgCs nc2 = new NdgCs(c); // OtherWise. + NdgCs nc2 = new NdgCs(c); // Otherwise. nc2.parent = c; c.addChild(nc2); Cons cc2 = new Cons(C_I_EQ); @@ -3728,7 +4375,7 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { } if (!ck_recursive_ndg(1, c, NDG_NEQ, m, b, 0, 0)) { - NdgCs nc2 = new NdgCs(c); // OtherWise. + NdgCs nc2 = new NdgCs(c); // Otherwise. nc2.parent = c; c.addChild(nc2); Cons cc2 = new Cons(C_I_EQ); @@ -3738,11 +4385,17 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc2, nc2); nc2.nd = null; parseStep(nc2); - } return true; } + /** + * Updates the NDG constraint set by replacing occurrences of one point with another in all constraints. + * This method is used when a new equality constraint is added. + * + * @param c the newly added equality constraint + * @param d the NDG constraint set to update + */ private void ndg_pteq_added(Cons c, NdgCs d) { int m = c.ps[0]; int a = c.ps[1]; @@ -3755,6 +4408,13 @@ private void ndg_pteq_added(Cons c, NdgCs d) { d.add(c); } + /** + * Incorporates a collinearity NDG constraint into the provided NDG constraint set. + * This method updates related constraints by replacing point indices when necessary. + * + * @param c the collinearity constraint to add + * @param d the NDG constraint set to update + */ private void ndg_coll_added(Cons c, NdgCs d) { int m = c.ps[0]; int a = c.ps[1]; @@ -3776,7 +4436,7 @@ private void ndg_coll_added(Cons c, NdgCs d) { } break; case C_O_T: - case C_O_P: { + case C_O_P: if (c2.ps[0] == m) { if (c2.ps[1] == a) c2.ps[0] = b; @@ -3798,150 +4458,23 @@ else if (c2.ps[0] == b) else if (c2.ps[2] == b) c2.ps[3] = a; } - } - break; + break; } c2.reorder(); - } d.add(c); } -// private boolean parseStep(ndgcs c, int i, int j) { -// cons c1 = c.allcns[i]; -// cons c2 = c.allcns[j]; -// -// if (c1 == null || c2 == null) { -// return false; -// } -// -// int n1 = c1.getLastPt(); -// int n2 = c2.getLastPt(); -// -// switch (c1.type) { -// case C_O_L: { -// switch (c2.type) { -// case C_O_L: -// if (n1 == n2) { -// int m, a, b; -// if (c1.ps[1] == c2.ps[1]) { -// m = c1.ps[1]; -// a = c1.ps[2]; -// b = c2.ps[2]; -// } else if (c1.ps[1] == c2.ps[2]) { -// m = c1.ps[1]; -// a = c1.ps[2]; -// b = c2.ps[1]; -// } else if (c1.ps[2] == c2.ps[1]) { -// m = c1.ps[1]; -// a = c1.ps[1]; -// b = c2.ps[2]; -// } else if (c1.ps[2] == c2.ps[2]) { -// m = c1.ps[2]; -// a = c1.ps[1]; -// b = c2.ps[1]; -// } else -// break; -// -// parse_rpt_ndgs(n1, m, c); -// -// if (!ck_diff(a, b)) { -// ndgcs nc1 = new ndgcs(c); -// cndg d = new cndg(); -// d.type = NDG_NEQ; -// d.no = 1; -// d.p[0] = a; -// d.p[1] = b; -// nc1.nd = d; -// c.addChild(nc1); -// parse_neq1(nc1); -// } -// return true; -// } -// -// case C_O_T: -// int m, a, b; -// if (c2.ps[0] == c2.ps[2]) { -// m = c2.ps[0]; -// a = c2.ps[1]; -// b = c2.ps[3]; -// } else if (c2.ps[1] == c2.ps[2]) { -// m = c2.ps[1]; -// a = c2.ps[0]; -// b = c2.ps[3]; -// } else if (c2.ps[1] == c2.ps[3]) { -// m = c2.ps[1]; -// a = c2.ps[0]; -// b = c2.ps[2]; -// } else if (c2.ps[0] == c2.ps[3]) { -// m = c2.ps[0]; -// a = c2.ps[1]; -// b = c2.ps[2]; -// } else -// break; -// if (!(c1.contains(m) && c1.contains(a) && c1.contains(b))) -// break; -// int x = a; -// if (x < b) -// x = b; -// if (x < m) { -// int t = x; -// x = m; -// m = t; -// } -// parse_rpt_ndgs(x, m, c); -// break; -// } -// break; -// } -// } -// return false; -// } - - public void parse_rpt_ndgs(int m, int a, NdgCs c) { - if (m == a) - return; - if (m < a) { - int t = m; - m = a; - a = t; - } - - NdgCs nc1 = new NdgCs(c); - nc1.parent = c; - c.addChild(nc1); - nc1.replace(m, a); - opt_cons(nc1); - rm_redundent(nc1); - nc1.rm_common(); - parseStep(nc1); - } - - - private boolean ck_diff(int a, int b) { - for (int i = 0; i < vndgs.size(); i++) { - CNdg d = (CNdg) vndgs.get(i); - switch (d.type) { - case NDG_COLL: - if (d.contain(a) && d.contain(b)) - return true; - break; - case NDG_NEQ: - case NDG_NON_ISOTROPIC: - if (d.contain(a) && d.contain(b)) - return true; - case NDG_PARA: - case NDG_PERP: - if (d.contain2(a, b)) - return true; - break; - } - } - return false; - } - + /** + * Optimizes constraints within the provided NDG constraint set. + *+ * This method iterates over each constraint, attempts to optimize it using the + * overloaded opt_cons method, and applies equality replacements if modifications occur. + *
+ * + * @param c the NDG constraint set to optimize + */ private void opt_cons(NdgCs c) { - while (true) { boolean r = true; @@ -3974,7 +4507,18 @@ private void opt_cons(NdgCs c) { } } - + /** + * Attempts to optimize a single constraint within the given NDG constraint set. + *+ * The method simplifies or converts the constraint based on its type. + * For instance, certain conditions on C_O_P may result in converting it to C_O_L, + * while a C_O_T constraint may be simplified to an equality constraint. + *
+ * + * @param cs the NDG constraint set containing the constraint + * @param c the constraint to optimize + * @return true if the constraint was modified; false otherwise + */ private boolean opt_cons(NdgCs cs, Cons c) { if (c == null) return false; @@ -4043,6 +4587,18 @@ private boolean opt_cons(NdgCs cs, Cons c) { return false; } + /** + * Adds an equality constraint between two points into the specified NDG constraint set. + *+ * If no existing equality constraint is found for the given non-zero points, + * this method creates a new equality constraint (C_I_EQ) relating the two points. + *
+ * + * @param a the first point index + * @param b the second point index + * @param c the NDG constraint set where the equality constraint will be added + * @return true if a new equality constraint was added; false otherwise + */ private boolean add_eq(int a, int b, NdgCs c) { if (a == b) return false; @@ -4072,6 +4628,15 @@ private boolean add_eq(int a, int b, NdgCs c) { return true; } + /** + * Removes redundant constraints from the provided NDG constraint set. + *+ * This method first removes constraints flagged as redundant based on internal criteria, + * and then eliminates duplicate constraints by comparing existing constraints. + *
+ * + * @param c the NDG constraint set from which redundant constraints will be removed + */ private void rm_redundent(NdgCs c) { for (int i = 0; i <= c.no; i++) { Cons c1 = c.allcns[i]; @@ -4093,6 +4658,16 @@ private void rm_redundent(NdgCs c) { } } + /** + * Checks if a given constraint is redundant. + *+ * The redundancy is determined based on the type of the constraint and comparisons + * of its point indices, such as duplicated points in a collinearity or perpendicular constraint. + *
+ * + * @param c the constraint to evaluate + * @return true if the constraint is considered redundant; false otherwise + */ private boolean cons_redundent(Cons c) { switch (c.type) { case C_O_L: @@ -4108,6 +4683,16 @@ private boolean cons_redundent(Cons c) { return false; } + /** + * Determines whether a constraint type is considered related to construction operations. + *+ * The method returns false for fundamental geometric element types (e.g., point, triangle, etc.) + * and for types within a specific range, indicating that additional construction steps are not required. + *
+ * + * @param t the constraint type identifier + * @return true if the constraint type is construction-related; false otherwise + */ public boolean construct_related(int t) { if (t == C_POINT || t == C_TRIANGLE || t == C_POLYGON || t == C_QUADRANGLE || t == C_PENTAGON || t == C_LINE || t == C_CIRCLE) @@ -4117,9 +4702,18 @@ public boolean construct_related(int t) { return true; } - + /** + * Recursively adds NDG constraints from the provided NDG constraint set. + *+ * For non-leaf nodes, the method traverses each child NDG set to add constraints. + * For leaf nodes, it attempts to add an NDG constraint based on the first non-null constraint encountered. + *
+ * + * @param d the NDG constraint set to process + * @param no the iteration limit based on the number of constraints in the set + * @return true if any NDG constraint was successfully added; false otherwise + */ private boolean addNdg(NdgCs d, int no) { - boolean r = false; int n = d.getCSindex(); @@ -4138,15 +4732,35 @@ private boolean addNdg(NdgCs d, int no) { for (int i = 0; i <= d.no; i++) { Cons c1 = d.allcns[i]; if (c1 != null) { - if (addNdg(c1)) { + if (addNdg(c1)) added = true; - } break; } } return added; } + /** + * Adds NDG constraint(s) for the specified geometric constraint. + * + *+ * This method inspects the type of the provided constraint and adds the corresponding + * NDG constraint as follows: + *
+ *C_O_L: Invokes add_n_coll to add a collinearity NDG constraint.C_O_P: Invokes add_ndg_para to add a parallelism NDG constraint and
+ * then registers it with add_ndgs.C_O_T: Invokes add_ndg_perp to add a perpendicularity NDG constraint and
+ * then registers it with add_ndgs.C_I_EQ: Invokes add_ndg_neq to add an equality NDG constraint and
+ * then registers it with add_ndgs.false without modification.true if the constraint was processed for NDG addition; false otherwise
+ */
private boolean addNdg(Cons c) {
switch (c.type) {
case C_O_L:
@@ -4174,6 +4788,4 @@ private boolean addNdg(Cons c) {
}
private Vector vndgs = new Vector();
-
-
}
diff --git a/src/main/java/gprover/GDD.java b/src/main/java/gprover/GDD.java
index 6305e17e..b2ead55e 100644
--- a/src/main/java/gprover/GDD.java
+++ b/src/main/java/gprover/GDD.java
@@ -8,8 +8,20 @@
package gprover;
+/**
+ * A class representing the geometric deduction system.
+ * + * This class extends GDDBase and implements additional algorithms for + * geometric constructions, predicate validations, and search operations used in + * the deduction process. + *
+ */ public class GDD extends GDDBase { + /** + * Performs the fixed‐point computation for the geometric deduction system. + * Processes all pending conditions, adjusts parameters, and collects results. + */ void fixpoint() { d_base = 0; test_ra = null; @@ -86,7 +98,11 @@ void fixpoint() { } /* Searching */ - + /** + * Searches for parallel line configurations within the specified PLine. + * + * @param pn the PLine in which to search. + */ final void search_pn(PLine pn) { if (pn == null) return; @@ -154,7 +170,11 @@ final void search_pn_coll(PLine pn) { } } - + /** + * Searches for line collisions within the specified PLine. + * + * @param pn the PLine to inspect. + */ final void search_pn_mds(PLine pn) { MidPt md = all_md.nx; @@ -166,6 +186,12 @@ final void search_pn_mds(PLine pn) { } } + /** + * Searches within a PLine for configurations based on the provided midpoint. + * + * @param pn the PLine in which to search. + * @param md the midpoint used for finding connections. + */ final void search_pn_md(PLine pn, MidPt md) { add_codb(CO_MIDP, md.m, md.a, md.b, 0, 0, 0, 0, 0); @@ -219,6 +245,12 @@ final void search_pn_md(PLine pn, MidPt md) { } } + /** + * Searches for additional line intersections and processes parallel connections. + * + * @param ln1 the first line. + * @param ln2 the second line. + */ final void search_pn_1(LLine ln1, LLine ln2) { if (ln1 == null) { // TODO. Handle this. @@ -249,19 +281,11 @@ final void search_pn_1(LLine ln1, LLine ln2) { } - final void search_pn_md(PLine pn1, LLine ln1, LLine ln2) { - MidPt md = all_md.nx; - if (md == null) return; - - add_codb(CO_MIDP, md.m, md.a, md.b, 0, 0, 0, 0, 0); - for (; md != null; md = md.nx) { - if (!ch_dep(md.dep)) break; - lm_md_connection(md, ln1, ln2); - lm_parallelogram(md, ln1, ln2); - } - pop_codb(); - } - + /** + * Searches for configurations in the given PLine based on TLine intersections. + * + * @param pn the PLine to search within. + */ final void search_pn_tns(PLine pn) { TLine tn = all_tn.nx; while (tn != null) { @@ -272,6 +296,12 @@ final void search_pn_tns(PLine pn) { } } +/** + * Searches for circle intersections within the provided PLine. + * Finds intersection points between each line in the PLine and the given circle. + * + * @param pn the PLine to search for circle intersections + */ public void search_pn_cr(PLine pn) { LLine l1, l2; ACir cr; @@ -299,6 +329,12 @@ public void search_pn_cr(PLine pn) { } + /** + * Processes a TLine for potential geometric relations. + * Checks intersections between the two lines forming the TLine and performs several searches. + * + * @param tn the TLine to process + */ final void search_tn(TLine tn) { co_db.nx = null; @@ -321,6 +357,12 @@ final void search_tn(TLine tn) { search_tn0(tn); } + /** + * Refines a TLine by attempting to adjust its defining lines. + * Replaces any degenerate line with a valid one if necessary, then adds a perpendicular condition. + * + * @param tn the TLine to adjust + */ final void search_tn0(TLine tn) { LLine ln1, ln2; if (tn.type == 0) return; @@ -341,6 +383,12 @@ final void search_tn0(TLine tn) { } } + /** + * Initiates the search for isosceles configurations in a TLine. + * Utilizes the intersection of the lines to search for isosceles triangle–like conditions. + * + * @param tn the TLine to search for isosceles configurations in + */ final void search_tn_iso(TLine tn) { int p = inter_lls(tn.l1, tn.l2); if (p == 0) return; @@ -348,6 +396,13 @@ final void search_tn_iso(TLine tn) { search_tn_iso1(p, tn.l2, tn.l1); } + /** + * Searches for isosceles or congruent configurations in a pair of lines with a shared intersection. + * + * @param p the common intersection point from the first line pair + * @param l1 the first line to check + * @param l2 the second line to check + */ final void search_tn_iso1(int p, LLine l1, LLine l2) { int p1, p2, p3; for (int i = 0; i <= l1.no; i++) @@ -391,6 +446,15 @@ final void search_tn_iso1(int p, LLine l1, LLine l2) { } + /** + * Processes circle-related configurations for a TLine. + * Searches for tangent conditions and square formations with respect to a circle. + * + * @param ln1 the first line of the TLine + * @param ln2 the second line of the TLine + * @param m the intersection point of ln1 and ln2 + * @param tn the source TLine being processed + */ final void search_tn_crs(LLine ln1, LLine ln2, int m, TLine tn) { int p2, p3, m2, m3; ACir cr = all_cir.nx; @@ -417,29 +481,37 @@ final void search_tn_crs(LLine ln1, LLine ln2, int m, TLine tn) { } } - - final private void search_tn_dim(TLine tn, int m, ACir cr) { - if (m == 0 || !on_cir(m, cr)) return; - LLine l1 = tn.l1; - LLine l2 = tn.l2; - int p1 = inter_lc1(l1, cr, m); - if (p1 == 0) return; - int p2 = inter_lc1(l2, cr, m); - if (p2 == 0) return; - - } - + /** + * Searches for midpoint configurations associated with a TLine. + * Iterates over all midpoints to find relevant relations with the given TLine. + * + * @param tn the TLine to search for midpoint relations + */ final void search_tn_mds(TLine tn) { for (MidPt md = all_md.nx; md != null && ch_dep(md.dep); md = md.nx) search_tn_md(tn, md); } + /** + * Searches through all TLine entries and, for each valid TLine, + * invokes search_tn_md with the given midpoint. + * + * @param md the midpoint used to relate TLine configurations + */ final void search_md_tns(MidPt md) { for (TLine tn = all_tn.nx; tn != null && tn.nx != null && ch_dep(tn.dep); tn = tn.nx) if (tn.type != 0) search_tn_md(tn, md); } + /** + * Processes a TLine with respect to a given midpoint. + * Determines the intersection of the TLine's defining lines and, + * if appropriate, adds midpoint-related constructions. + * + * @param tn the TLine to process + * @param md the midpoint used for validation and configuration + */ final void search_tn_md(TLine tn, MidPt md) { LLine ln1 = tn.l1; LLine ln2 = tn.l2; @@ -465,6 +537,12 @@ final void search_tn_md(TLine tn, MidPt md) { } } + /** + * Iterates through all available PLine entries and searches for + * TLine intersections within each PLine that meet the dependency criteria. + * + * @param tn the TLine serving as search criteria for parallel configurations + */ final void search_tn_pns(TLine tn) { PLine pn; pn = all_pn.nx; @@ -475,6 +553,14 @@ final void search_tn_pns(TLine tn) { } } + /** + * Searches for angle relationships between two TLine entities. + * Iterates over all angle configurations to determine additional + * angle-related constructions. + * + * @param tn1 the first TLine + * @param tn2 the second TLine + */ final void serach_tn2_as(TLine tn1, TLine tn2) { Angles as = all_as.nx; if (tn1.type == 0) return; @@ -486,6 +572,16 @@ final void serach_tn2_as(TLine tn1, TLine tn2) { } } + /** + * Processes interactions between a TLine and all other TLine entries. + * Evaluates perpendicular and cyclic configurations based on the + * intersections of the defining lines and applies necessary constructions. + * + * @param tn the source TLine to compare + * @param ln1 one of the lines defining the source TLine + * @param ln2 the other line defining the source TLine + * @param p1 the intersection point of ln1 and ln2 + */ final void search_tn_tn(TLine tn, LLine ln1, LLine ln2, int p1) { TLine tn1; PLine pn; @@ -563,6 +659,13 @@ final void search_tn_tn(TLine tn, LLine ln1, LLine ln2, int p1) { } } + /** + * Searches for various circle configurations within the specified circle. + * Evaluates diameter conditions, inscribed angle relationships, + * and parallel intersections related to the circle. + * + * @param cr1 the circle to process + */ final void search_cr(ACir cr1) { int p1, p2, p3, p4, i, j, k; co_db.nx = null; @@ -623,6 +726,13 @@ final void search_cr(ACir cr1) { adj_cir1(cr1); } + /** + * Searches for midpoint configurations related to the given circle. + * If the circle's center coincides with a midpoint, constructs the appropriate + * cyclic configurations based on the circle and the midpoint's endpoints. + * + * @param cr the circle to process for midpoint relationships + */ final void search_cr_md(ACir cr) { MidPt md = all_md.nx; if (cr.pt[1] == 0) return; @@ -649,6 +759,13 @@ final void search_cr_md(ACir cr) { } } + /** + * Searches for additional circle‐line intersections within a PLine. + * + * @param cr1 the circle to search intersections with + * @param p1 the first point index defining the line + * @param p2 the second point index defining the line + */ final void search_cr_pn(ACir cr1, int p1, int p2) { int i, p3, p4; LLine l1, l2; @@ -666,7 +783,12 @@ final void search_cr_pn(ACir cr1, int p1, int p2) { } } - + /** + * Searches for tangent configurations between the given circle and a TLine. + * + * @param cr1 the circle to check for tangency conditions + * @param tn the TLine used for searching tangent intersections + */ final void search_cr_tan(ACir cr1, TLine tn) { if (cr1.o == 0 || cr1.no < 1) return; @@ -709,6 +831,11 @@ final void search_cr_tan(ACir cr1, TLine tn) { } } + /** + * Searches for circle‐circle intersections between the provided circle and all other circles. + * + * @param cr1 the circle to search for intersections with other circles + */ final void search_cr_cr(ACir cr1) { ACir cr2; int p1, p2; @@ -746,6 +873,13 @@ final void search_cr_cr(ACir cr1) { } } + /** + * Searches for isosceles configurations related to a circle using a line segment defined by two points. + * + * @param cr1 the circle to process + * @param p1 the first point index defining the segment + * @param p2 the second point index defining the segment + */ final void search_cr_iso(ACir cr1, int p1, int p2) { int p3 = fd_pt_md(p1, p2); if (p3 != 0) { @@ -755,6 +889,12 @@ final void search_cr_iso(ACir cr1, int p1, int p2) { } } + /** + * Searches and constructs midpoint‐related cyclic configurations for the given circle. + * + * @param cr the circle to process + * @param md the midpoint data structure containing endpoints and the midpoint + */ final void search_cr_md(ACir cr, MidPt md) { int o = cr.o; if (o == 0) return; @@ -776,6 +916,11 @@ final void search_cr_md(ACir cr, MidPt md) { } } + /** + * Searches for congruent configurations by evaluating circle properties. + * + * @param cr1 the circle used to search congruence conditions between its intersection points + */ final void search_cr_cg(ACir cr1) { if (cr1.o != 0) { for (int i = 0; i <= cr1.no; i++) @@ -790,6 +935,11 @@ final void search_cr_cg(ACir cr1) { } + /** + * Processes all midpoint‐related configurations including congruence, parallel, and cyclic conditions. + * + * @param md the midpoint to process + */ final void search_md(MidPt md) { co_db.nx = null; @@ -839,6 +989,11 @@ final void search_md(MidPt md) { } } + /** + * Searches for additional midpoint configurations and connections between different midpoints. + * + * @param md the midpoint from which to search connected midpoint configurations + */ final void search_md_mds(MidPt md) { MidPt md1; @@ -903,6 +1058,11 @@ final void search_md_mds(MidPt md) { } } + /** + * Searches for midpoint-related parallel segment configurations. + * + * @param md the midpoint object containing endpoints for the search + */ final void search_md_pns(MidPt md) { if (!valid(R_PARALLELOGRAM)) return; LLine l0 = fd_ln(md.a, md.b); @@ -914,6 +1074,11 @@ final void search_md_pns(MidPt md) { } } + /** + * Processes an angle object by adjusting and verifying its associated lines. + * + * @param as1 the angle object to process + */ final void search_as(Angles as1) { LLine l1 = as1.l1; LLine l2 = as1.l2; @@ -998,6 +1163,15 @@ final void search_as(Angles as1) { } + /** + * Adjusts the angle based on parallel or perpendicular relationships between provided lines. + * + * @param as the angle object to adjust + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_0(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { if (ln_para(l1, l2) && l3 != l4) { as.type = 0; @@ -1030,6 +1204,15 @@ final void search_as_0(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for specific angle relations given intersecting lines. + * + * @param p1 the first intersection point + * @param p2 the second intersection point, expected as the intersection of l1 and l3 + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + */ final void search_as_1(int p1, int p2, LLine l1, LLine l2, LLine l3) { if (p1 == 0 || p2 == 0) return; int o = inter_ll(l1, l3); @@ -1093,6 +1276,16 @@ final void search_as_1(int p1, int p2, LLine l1, LLine l2, LLine l3) { } } + /** + * Identifies and processes angle relationships using the inscribed angle theorem and tangency conditions. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_2(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int o, p3, p4; o = 0; @@ -1129,6 +1322,16 @@ final void search_as_2(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for cyclic angle configurations based on line and circle intersections. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_3(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, m; if ((p3 = inter_ll(l1, l3)) != 0 && xcir2(p2, p1, p3) && @@ -1153,6 +1356,16 @@ final void search_as_3(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Adjusts angle configurations based on alignment and concurrency of lines. + * + * @param p1 the first reference point from an intersection + * @param p2 the second reference point from an intersection + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void lm_43(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, o; @@ -1177,6 +1390,16 @@ final void lm_43(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for similar angle configurations and triggers operations to construct congruences. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_sim(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { // if (!valid(R_STRI)) return; int p3, p4, p5, p6; @@ -1237,6 +1460,17 @@ final void search_as_sim(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) } } + /** + * Determines if two triangles are similar based on their vertices. + * + * @param p1 the first vertex of the first triangle + * @param p2 the second vertex of the first triangle + * @param p3 the third vertex of the first triangle + * @param p4 the first vertex of the second triangle + * @param p5 the second vertex of the second triangle + * @param p6 the third vertex of the second triangle + * @return true if the triangles are similar, false otherwise + */ boolean tri_sim(int p1, int p2, int p3, int p4, int p5, int p6) { int p; if (ind_3(p1, p4, p5, p6) != 0 && ind_3(p2, p4, p5, p6) != 0 && ind_3(p3, p4, p5, p6) != 0)//??? @@ -1276,6 +1510,9 @@ boolean tri_sim(int p1, int p2, int p3, int p4, int p5, int p6) { return (false); } + /** + * Iterates through angle objects to perform angle search operations. + */ final void search_as_pt() { Angles as; as = all_as.nx; @@ -1290,6 +1527,18 @@ final void search_as_pt() { } } + /** + * Searches and processes string-based congruency conditions for the provided points. + * + * @param dr a direction flag for processing + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + * @return true if a congruency condition is met, false otherwise + */ boolean search_st_ct(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { int oldt = tri_type; boolean mk = false; @@ -1314,6 +1563,17 @@ boolean search_st_ct(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { return mk; } + /** + * Searches for congruent segment configurations and processes string congruency scenarios. + * + * @param dr a direction flag for processing + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + */ void search_st_rg(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { CongSeg rg = fo_rg1(p1, p2, p4, p5); int t1, t2; @@ -1366,6 +1626,11 @@ void search_st_rg(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { } } + /** + * Searches and processes a SimTri structure. + * + * @param st the SimTri instance representing the similar triangle to search + */ final void search_st(SimTri st) { int dr, p1, p2, p3, p4, p5, p6; RatioSeg ra1, ra = null; @@ -1408,6 +1673,11 @@ final void search_st(SimTri st) { pop_codb(); } + /** + * Searches and processes a congruent triangle based on the given SimTri. + * + * @param st the SimTri instance containing triangle data + */ final void search_ct(SimTri st) { tri_type = 1; adj_ct(st); @@ -1441,6 +1711,11 @@ final void search_ct(SimTri st) { pop_codb(); } + /** + * Searches and processes a CongSeg object. + * + * @param cg the CongSeg instance to process + */ final void search_cg(CongSeg cg) { int o, p1, p2, p3, p4; if (cg.t1 == 0 || cg.t2 == 0) { @@ -1508,6 +1783,13 @@ final void search_cg(CongSeg cg) { } + /** + * Searches for an isosceles configuration based on the given points. + * + * @param o the origin point + * @param a the first point defining the base + * @param b the second point defining the base + */ final void search_cg_iso(int o, int a, int b) { MidPt m = fo_md(a, b); if (m != null && m.m != o) { // mid @@ -1547,6 +1829,14 @@ final void search_cg_iso(int o, int a, int b) { } + /** + * Searches for a triangle structure within congruent segments. + * + * @param p1 the first point of the congruency + * @param p2 the second point of the congruency + * @param p3 the third point of the congruency + * @param p4 the fourth point of the congruency + */ final void search_cg_st(int p1, int p2, int p3, int p4) { SimTri st; @@ -1599,7 +1889,11 @@ final void search_cg_st(int p1, int p2, int p3, int p4) { } } - + /** + * Searches for a ratio segment configuration and processes it accordingly. + * + * @param ra the RatioSeg instance containing ratio and segment data + */ final void search_ra(RatioSeg ra) { int n, a1, b1, a2, b2, a3, b3, a4, b4; if (ra.type == 0) return; @@ -1653,45 +1947,11 @@ final void search_ra(RatioSeg ra) { } } - - final void adj_ras(RatioSeg ra) { - if (ra.type == 0) return; - CongSeg cg; - int p1, p2; - int[] p; - test_ra1.cp_ratio(ra); - p = test_ra1.r; - cg = null; - - for (int n = 0; n < 4; n++) { - p1 = p[n * 2 + 1]; - p2 = p[n * 2 + 2]; - - cg = fd_cg2(p1, p2, cg); - while (cg != null) { - if (p1 == cg.p1 && p2 == cg.p2 || p1 == cg.p2 && p2 == cg.p1) { - p[n * 2 + 1] = cg.p3; - p[n * 2 + 2] = cg.p4; - } else { - p[n * 2 + 1] = cg.p1; - p[n * 2 + 2] = cg.p2; - } - - if (!xeq_ratio(p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8])) { // mod here. - - add_codb(CO_CONG, cg.p1, cg.p2, cg.p3, cg.p4, 0, 0, 0, 0); - add_codb(CO_PROD, ra.r[1], ra.r[2], ra.r[3], ra.r[4], ra.r[5], ra.r[6], ra.r[7], ra.r[8]); - add_ra(0, 0, p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]); - pop_codb(); - pop_codb(); - } - cg = cg.nx; - } - p[n * 2 + 1] = p1; - p[n * 2 + 2] = p2; - } - } - + /** + * Searches and processes the ratio segment for state-specific actions. + * + * @param ra the RatioSeg instance to process + */ final void serach_ra_st(RatioSeg ra) { int a, a1, a2, b, b1, b2; int[] p = ra.r; @@ -1808,6 +2068,9 @@ final void serach_ra_st(RatioSeg ra) { } } + /** + * Searches and processes ratio segments for congruency operations. + */ final void search_ra_cg() { RatioSeg ra; @@ -1851,23 +2114,40 @@ final void search_ra_cg() { } } - /////////////////////////////////////////////////////////////// + /** + * Checks if three points are collinear. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the points are collinear; false otherwise + */ public boolean mcoll(int p1, int p2, int p3) { return xcoll(p1, p2, p3); } + /** + * Checks if the line formed by p1 and p2 is perpendicular to the line formed by p3 and p4. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are perpendicular; false otherwise + */ public boolean mperp(int p1, int p2, int p3, int p4) { return xperp(p1, p2, p3, p4); } - public boolean mpara(int p1, int p2, int p3, int p4) { - return xpara(p1, p2, p3, p4); - } - - //////////////////////////////////////////////////////////////////// - // added by yezheng 2006.9.26 - - + /** + * Adds an isosceles configuration when three lines concur. + * + * @param lm the identifier to be used for the configuration + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param m the midpoint to be used in the configuration + */ final void add_iso_3lines_concur(int lm, int p1, int p2, int p3, int m) { if (p1 == m) return; if (check_coll(p1, p2, p3)) { @@ -1883,11 +2163,27 @@ final void add_iso_3lines_concur(int lm, int p1, int p2, int p3, int m) { add_tline(lm, p1, m, p2, p3); } + /** + * Searches for congruent triangle configurations via side‑side‑side relationships. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ public final void search_cg_ct(int p1, int p2, int p3, int p4) { search_cg_ct0(p1, p2, p3, p4); //SSS search_cg_ct0(p3, p4, p1, p2); //SSS } + /** + * Searches for congruent triangle configurations using angle‑angle‑side conditions. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ public final void search_cg_aas(int p1, int p2, int p3, int p4) { for (int i = 1; i <= pts_no; i++) for (int j = 1; j <= pts_no; j++) { @@ -1915,6 +2211,14 @@ public final void search_cg_aas(int p1, int p2, int p3, int p4) { } } + /** + * Searches for congruent triangle configurations with trimmed conditions using SSS. + * + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param p4 the fourth reference point + */ public final void search_cg_ct0(int p1, int p2, int p3, int p4) { // if (!valid(R_SSS)) return; @@ -2031,6 +2335,16 @@ public final void search_cg_ct0(int p1, int p2, int p3, int p4) { } } + /** + * Searches for similar triangle configurations using corresponding line segments. + * + * @param p1 the reference point from the first triangle + * @param p2 the reference point from the second triangle + * @param ln1 the line data for the first triangle side + * @param ln2 the line data for the second triangle side + * @param ln3 the line data for the third triangle side + * @param ln4 the line data for the alternative configuration side + */ final public void search_as_ct(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { // if (!valid(R_SAS)) return; if (p1 == 0 || p2 == 0) return; @@ -2101,7 +2415,14 @@ final public void search_as_ct(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, } } - + /** + * Searches for T-line structures by testing intersections and perpendicular conditions. + * + * @param p1 the first reference point index + * @param ln1 the first line of the primary structure + * @param ln2 the second line of the primary structure + * @param tn1 the candidate T-line structure + */ final public void search_tn_st(int p1, LLine ln1, LLine ln2, TLine tn1) { @@ -2170,6 +2491,14 @@ else if (xcong(p1, t1, p2, t4)) { } + /** + * Searches for congruent triangle configurations by finding midpoints and establishing congruency. + * + * @param p1 the first point index of the first segment + * @param p2 the second point index of the first segment + * @param p3 the first point index of the second segment + * @param p4 the second point index of the second segment + */ final public void search_cg_md(int p1, int p2, int p3, int p4) { int t1 = fd_pt_md(p1, p2); int t2 = fd_pt_md(p3, p4); @@ -2187,14 +2516,11 @@ final public void search_cg_md(int p1, int p2, int p3, int p4) { } } - final public void search_cg_mds(int p1, int p2, int p3, int p4) { - MidPt md = all_md.nx; - while (md != null) { - - md = md.nx; - } - } - + /** + * Searches for congruent segment configurations within the current geometric construction. + * + * @param cg the congruent segment configuration to be evaluated + */ public void search_cgs(CongSeg cg) { CongSeg cg1 = all_cg.nx; while (cg1 != null) { @@ -2210,6 +2536,12 @@ public void search_cgs(CongSeg cg) { search_2cong1(cg); } + /** + * Searches for congruent configurations between two congruent segment structures. + * + * @param cg the first congruent segment configuration + * @param cg1 the second congruent segment configuration + */ public void search_cg_cg(CongSeg cg, CongSeg cg1) { int p1, p2, p3, p4, t1, t2, t3, t4; if (cg == cg1) return; @@ -2275,6 +2607,22 @@ public void search_cg_cg(CongSeg cg, CongSeg cg1) { pop_codb(); } + /** + * Searches for congruent configurations using plus or minus criteria for segment measures. + * + * @param a first point of the first segment + * @param b second point of the first segment + * @param c first point of the second segment + * @param d second point of the second segment + * @param t1 first measure associated with the first segment + * @param t2 second measure associated with the first segment + * @param a1 first point of the alternative segment configuration + * @param b1 second point of the alternative segment configuration + * @param c1 first point of the alternative segment configuration + * @param d1 second point of the alternative segment configuration + * @param t11 first measure associated with the alternative configuration + * @param t22 second measure associated with the alternative configuration + */ public void search_cg__plus_or_minus(int a, int b, int c, int d, int t1, int t2, int a1, int b1, int c1, int d1, int t11, int t22) { int m1, m2, m3, m4, m5, m6; @@ -2329,7 +2677,11 @@ public void search_cg__plus_or_minus(int a, int b, int c, int d, int t1, int t2, pop_codb(); } - + /** + * Searches for configurations where two congruent segments share a common intersection. + * + * @param cg the congruent segment configuration to analyze + */ public void search_2cong1(CongSeg cg) { if (!xcoll4(cg.p1, cg.p2, cg.p3, cg.p4)) return; int p1, p2, p3; @@ -2371,6 +2723,11 @@ public void search_2cong1(CongSeg cg) { } } + /** + * Searches for congruent configurations based on midpoint relationships. + * + * @param md the midpoint structure used for establishing congruence + */ final public void search_md_cong(MidPt md) { MidPt md1 = all_md.nx; while (md1 != null && ch_dep(md1.dep)) { @@ -2390,6 +2747,11 @@ final public void search_md_cong(MidPt md) { } } + /** + * Searches for parallelogram configurations among point-line relationships. + * + * @param pn the candidate point-line configuration + */ public void search_pn_pn(PLine pn) { if (!valid(R_PARALLELOGRAM)) return; if (pn.type == 0 || pn.no <= 0) return; @@ -2448,7 +2810,16 @@ public void search_pn_pn(PLine pn) { } } - + /** + * Searches for SAS (Side-Angle-Side) triangle configurations using the specified points and line segments. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param ln1 the first line segment container + * @param ln2 the second line segment container + * @param ln3 the third line segment container + * @param ln4 the fourth line segment container + */ final public void search_as_st(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { //sas for st if (!valid(R_SAS)) return; if (p1 == 0 || p2 == 0) return; @@ -2525,6 +2896,16 @@ final public void search_as_st(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, } } + /** + * Searches for congruent segment triangle states based on the given points and ratio parameters. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param p3 the third point identifier + * @param p4 the fourth point identifier + * @param r1 the first ratio value + * @param r2 the second ratio value + */ public final void search_cg_st0(int p1, int p2, int p3, int p4, int r1, int r2) { // if (!valid(R_SSS) || !valid(R_STRI)) return; @@ -2615,6 +2996,18 @@ public final void search_cg_st0(int p1, int p2, int p3, int p4, int r1, int r2) } } + /** + * Searches for congruent triangles by validating angle equality and congruence conditions. + * + * @param t1 the first triangle base point identifier + * @param t2 the second triangle base point identifier + * @param t3 the third triangle base point identifier + * @param t4 the first point of the second triangle + * @param t5 the second point of the second triangle + * @param t6 the third point of the second triangle + * @param r1 the first ratio value associated with congruence + * @param r2 the second ratio value associated with congruence + */ public void search_cong_st(int t1, int t2, int t3, int t4, int t5, int t6, int r1, int r2) { if (!check_eqangle_t(t2, t1, t1, t3, t5, t4, t4, t6)) return; @@ -2641,6 +3034,17 @@ public void search_cong_st(int t1, int t2, int t3, int t4, int t5, int t6, int r } + /** + * Searches for triangle configurations based on segment congruence and structural properties. + * + * @param dr the directional factor for the configuration + * @param p1 the first point identifier of the triangle + * @param p2 the second point identifier of the triangle + * @param p3 the third point identifier of the triangle + * @param p4 the first point identifier of the second triangle + * @param p5 the second point identifier of the second triangle + * @param p6 the third point identifier of the second triangle + */ public void search_st1(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { if (xcong(p1, p2, p2, p3) && !xcong(p4, p5, p5, p6)) { add_codb(CO_CONG, p1, p2, p2, p3, 0, 0, 0, 0); @@ -2681,12 +3085,17 @@ public void search_st1(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { pop_codb(); } - - public boolean get_at_dr(AngleT at, int p1, int p2) { - if (on_ln(p1, at.l1) && on_ln(p2, at.l2)) return true; - return false; - } - + /** + * Adds structural angle congruency information by comparing two complementary angles from the given points. + * + * @param dr the directional factor for angle assignment + * @param p1 the vertex point of the first angle + * @param p2 a point defining the first angle side + * @param p3 a point defining the other side of the first angle + * @param p4 the vertex point of the second angle + * @param p5 a point defining the second angle side + * @param p6 a point defining the other side of the second angle + */ public void add_stct_at(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { AngleT at1 = fd_at(p2, p1, p3); @@ -2710,6 +3119,11 @@ public void add_stct_at(int dr, int p1, int p2, int p3, int p4, int p5, int p6) } } + /** + * Adjusts similar triangles by checking and adding structural relationships with adjacent triangles. + * + * @param st the simulated triangle whose adjacent configurations are to be adjusted + */ public void adj_st(SimTri st) { SimTri st1 = all_st.nx; tri_type = 0; @@ -2766,6 +3180,11 @@ public void adj_st(SimTri st) { } + /** + * Adjusts complementary triangles by checking and generating new configurations for triangle relationships. + * + * @param st the simulated triangle whose complementary relationships are being adjusted + */ public void adj_ct(SimTri st) { SimTri st1 = all_ct.nx; tri_type = 1; @@ -2822,6 +3241,11 @@ public void adj_ct(SimTri st) { } + /** + * Searches for perpendicular congruent segments in a given congruent segment configuration. + * + * @param cg the congruent segment configuration to be analyzed + */ public void search_tn_cg(CongSeg cg) { int o = 0; int p1 = cg.p1; @@ -2868,7 +3292,11 @@ public void search_tn_cg(CongSeg cg) { } } - + /** + * Searches the given line for valid configurations among congruent segments. + * + * @param ln the line to search through + */ final void search_ln(LLine ln) { if (ln != null && ln.type != 0) { @@ -2919,6 +3347,15 @@ final void search_ln(LLine ln) { } } + /** + * Adjusts the angle subtraction configuration for the given point using four lines. + * + * @param p the reference point identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ public void adj_as0(int p, LLine l1, LLine l2, LLine l3, LLine l4) { if (p == 0) return; @@ -2948,6 +3385,16 @@ public void adj_as0(int p, LLine l1, LLine l2, LLine l3, LLine l4) { } + /** + * Searches and verifies tangent-based angle relationships between two points using four lines. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ protected void search_as_tn_as(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { if (this.isPFull() && d_base == 0) return; @@ -3020,7 +3467,11 @@ protected void search_as_tn_as(int p1, int p2, LLine l1, LLine l2, LLine l3, LLi } } - + /** + * Initiates a comprehensive search for angle congruence relationships. + * + * @param at the angle to be processed + */ public void search_at(AngleT at) { search_at0(at); search_at1(at); @@ -3029,6 +3480,11 @@ public void search_at(AngleT at) { adj_at(at); } + /** + * Searches for tangent-based angle configurations related to the specified angle. + * + * @param at the angle to be evaluated + */ public void search_at_tn(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3056,6 +3512,11 @@ public void search_at_tn(AngleT at) { } } + /** + * Searches for angle relationships within a tangent line configuration. + * + * @param tn the tangent line configuration + */ public void search_tn_at(TLine tn) { LLine l1 = tn.l1; LLine l2 = tn.l2; @@ -3066,6 +3527,14 @@ public void search_tn_at(TLine tn) { search_tn_ats(l2, l1, p, tn); } + /** + * Searches for tangent angles across two lines with respect to a common intersection point and a tangent line. + * + * @param l1 the first line + * @param l2 the second line + * @param p the intersection point identifier + * @param tn the tangent line configuration + */ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { if (p == 0) return; AngleT at1; @@ -3086,6 +3555,14 @@ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { } + /** + * Adds a triangle configuration based on tangent angle values. + * + * @param p the vertex point identifier + * @param p1 the first adjacent point identifier + * @param p2 the second adjacent point identifier + * @param v the angle value between points p1 and p2 + */ public void add_tri_tn_at(int p, int p1, int p2, int v) // pp1p2 = v; { int lm; @@ -3125,6 +3602,11 @@ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { } } + /** + * Searches for direct angle congruence relationships starting from the provided angle. + * + * @param at the angle to be searched + */ public void search_at0(AngleT at) { AngleT at1 = all_at.nx; while (at1 != null && ch_dep(at1.dep)) { @@ -3134,7 +3616,11 @@ public void search_at0(AngleT at) { } } - + /** + * Searches for alternative angle configurations based on the given angle. + * + * @param at the angle instance to process + */ public void search_at1(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3161,6 +3647,12 @@ public void search_at1(AngleT at) { } } + /** + * Searches for angle relationships between two angle instances and creates corresponding configurations. + * + * @param at the first angle instance + * @param at1 the second angle instance to compare + */ public void search_at_at(AngleT at, AngleT at1) { if (at == at1) return; LLine l1 = at.l1; @@ -3235,6 +3727,11 @@ public void search_at_at(AngleT at, AngleT at1) { } } + /** + * Searches for angle configurations derived from a congruent segment. + * + * @param cg the congruent segment instance used for calculating angle relationships + */ public void search_rg_at(CongSeg cg) { int t1 = cg.p1; int t2 = cg.p2; @@ -3329,6 +3826,12 @@ public void search_rg_at(CongSeg cg) { } } + /** + * Searches for angle configurations by comparing the given angle with an angle structure. + * + * @param at the base angle instance + * @param as the angle structure to compare against + */ public void search_at_as(AngleT at, Angles as) { LLine l1, l2, l3, l4; l1 = at.l1; @@ -3367,6 +3870,11 @@ public void search_at_as(AngleT at, Angles as) { } } + /** + * Searches for associated angle structures related to the given angle. + * + * @param at the angle instance for which to search related angle associations + */ public void search_at_ass(AngleT at) { Angles as = all_as.nx; @@ -3380,43 +3888,11 @@ public void search_at_ass(AngleT at) { } } - public void add_as_at(Angles as) { - LLine l1 = as.l1; - LLine l2 = as.l2; - LLine l3 = as.l3; - LLine l4 = as.l4; - if (l1 == l2 || xcoll_ln(l1, l2)) return; - if (l3 == l4 || xcoll_ln(l3, l4)) return; - AngleT at1 = fd_at(l1, l2); - AngleT at2 = fd_at(l3, l4); - if (at1 == at2) return; - - AngleT at = null; - if (at1 != null && at2 == null && ch_dep(at1.dep)) { - if (at1.l1 == l1 && at1.l2 == l2) - at = add_at(0, l3, l4, at1.v); - else - at = add_at(0, l4, l3, at1.v); - } else if (at1 == null && at2 != null && ch_dep(at2.dep)) { - if (at2.l1 == l3 && at2.l2 == l4) - at = add_at(0, l1, l2, at2.v); - else - at = add_at(0, l2, l1, at2.v); - } - if (at != null) { - co_xy.nx = null; - Cond co = add_coxy(CO_TANG); - if (at1 != null) - co.u.at = at1; - else if (at2 != null) - co.u.at = at2; - co = add_coxy(CO_ACONG); - co.u.as = as; - at.co = co; - } - } - - + /** + * Adjusts the angle configuration using its defining lines. + * + * @param at the angle instance to adjust + */ public void adj_at(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3439,12 +3915,11 @@ public void adj_at(AngleT at) { } } - public boolean ck_ateq(int a, int b) { - return a == b || Math.abs(a - b) == A_180; - } - -////////////////////////////////////////////////////// - + /** + * Searches for tangent-based angle configurations associated with the given tangent line. + * + * @param tn the tangent line configuration instance to search within + */ public void search_tn_atn(TLine tn) { if (tn.type == 0) return; @@ -3486,6 +3961,11 @@ public void search_tn_atn(TLine tn) { } } + /** + * Searches for angle configurations based on the provided tangent angle instance. + * + * @param atn the tangent angle instance to process + */ public void search_atn(AngTn atn) { if (atn.type == 0) return; @@ -3496,7 +3976,12 @@ public void search_atn(AngTn atn) { search_atn_at(atn); } - + /** + * Searches for equivalent tangent angle configurations by comparing the provided instance + * with existing tangent angle configurations. + * + * @param atn the tangent angle instance to compare + */ public void search_atn_atn(AngTn atn) { AngTn a1 = all_atn.nx; LLine ln1, ln2, ln3, ln4; @@ -3545,6 +4030,11 @@ public void search_atn_atn(AngTn atn) { } } + /** + * Searches for angle structures associated with the given tangent angle configuration. + * + * @param atn the tangent angle instance for which to search associated angle structures + */ public void search_atn_as(AngTn atn) { Angles as = all_as.nx; while (as != null && ch_dep(as.dep)) { @@ -3558,21 +4048,12 @@ public void search_atn_as(AngTn atn) { } } - public void search_as_atn(Angles as) { - AngTn a1 = all_atn.nx; - - while (a1 != null && ch_dep(a1.dep)) { - if (a1.type == 0) { - a1 = a1.nx; - continue; - } - search_atnas(a1, as.l1, as.l2, as.l3, as.l4, as); - search_atnas(a1, as.l3, as.l4, as.l1, as.l2, as); - a1 = a1.nx; - } - } - - + /** + * Searches through all angle instances and applies tangent angle evaluation with the given tangent angle instance. + * Continues until there are no more dependent angle instances. + * + * @param atn the tangent angle instance used for comparison + */ public void search_atn_at(AngTn atn) { AngleT at = all_at.nx; while (at != null && ch_dep(at.dep)) { @@ -3586,19 +4067,17 @@ public void search_atn_at(AngTn atn) { } - public void search_at_atn(AngleT at) { - AngTn a1 = all_atn.nx; - while (a1 != null && ch_dep(a1.dep)) { - if (a1.type == 0) { - a1 = a1.nx; - continue; - } - search_atatn(at, a1); - a1 = a1.nx; - } - - } - + /** + * Searches for associated tangent angle configurations by comparing the specified tangent angle instance with provided lines and an angles structure. + * Creates new tangent angle associations if the configuration meets criteria. + * + * @param atn the reference tangent angle instance + * @param l1 the first line of the primary configuration + * @param l2 the second line of the primary configuration + * @param l3 the first line of the secondary configuration + * @param l4 the second line of the secondary configuration + * @param as the angles structure used in association comparison + */ public void search_atnas(AngTn atn, LLine l1, LLine l2, LLine l3, LLine l4, Angles as) { LLine ln1, ln2, ln3, ln4, s1, s2, s3, s4; @@ -3665,6 +4144,13 @@ public void search_atnas(AngTn atn, LLine l1, LLine l2, LLine l3, LLine l4, Angl } + /** + * Searches for tangent angle configurations that are complementary to the given angle instance. + * If a valid configuration is found, creates and associates a new angle instance with an adjusted value. + * + * @param at the base angle instance + * @param a1 the tangent angle configuration to compare against + */ public void search_atatn(AngleT at, AngTn a1) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3701,10 +4187,26 @@ public void search_atatn(AngleT at, AngTn a1) { } } + /** + * Determines if the point p lies within the range defined by points o and o1. + * + * @param p the point to check + * @param o the first endpoint of the range + * @param o1 the second endpoint of the range + * @return true if p lies between o and o1, otherwise false + */ public boolean ptdr(int p, int o, int o1) { return (x_inside(p, o, o1) || x_inside(o1, p, o)); } + /** + * Splits the given line into segments based on the position of point p. + * Returns an array of line segments that are part of the original line and include point p. + * + * @param p the point used to split the line + * @param ln the line to be split + * @return an array of resulting line segments, or null if no valid segments exist + */ LLine[] split_ln(int p, LLine ln) { int o1 = get_lpt1(ln, p); int o2 = get_anti_pt(ln, p, o1); @@ -3751,7 +4253,18 @@ else if (lx2 != null) return ls; } - + /** + * Checks if the combined angles formed by the specified line segments at points p1 and p2 are approximately complementary. + * The method evaluates whether the sum of the absolute angles is close to 90 degrees. + * + * @param p1 the vertex point for the first pair of lines + * @param p2 the vertex point for the second pair of lines + * @param l1 the first line from p1 + * @param l2 the second line from p1 + * @param l3 the first line from p2 + * @param l4 the second line from p2 + * @return true if the summed angle values are approximately 90 degrees, otherwise false + */ public boolean check_llatn(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int n1 = get_lpt1(l1, p1); int n2 = get_lpt1(l2, p1); @@ -3765,19 +4278,33 @@ public boolean check_llatn(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l return false; } -/////////////////////////////////////////////////////////////////////////// -///// nodes; - - + /** + * Initiates the search for non-solved structures within the specified list. + * Skips the search if the last element has already been solved. + * + * @param ns the list of structures to search + */ public void search_ns(LList ns) { if (last_ns.solved) return; search_bk(ns); } + /** + * Initiates a backup search process. + * + * @param ls the list of structures to search + */ public void search_bk(LList ls) { search_bk_as(ls); } + /** + * Searches through the backup structures contained in the specified list. + * + * Iterates over each element in the list and applies transformation based on angle structures. + * + * @param ls the list of structures to process + */ public void search_bk_as(LList ls) { LList last; LLine[] ln1, ln2; @@ -3816,6 +4343,17 @@ public void search_bk_as(LList ls) { } } + /** + * Adds a new angle transformation node to the given list. + * + * Evaluates if the current transformation in the node matches the provided lines, + * and if not, creates a new node with the updated angle transformation. + * + * @param ls the current list of nodes + * @param l1 the first line segment for comparison + * @param l2 the second line segment for comparison + * @param n the index position used for the transformation + */ public void add_ls_et(LList ls, LLine l1, LLine l2, int n) { AngTr tr = ls.md[n].tr; if (tr.l1 == l1 && tr.l2 == l2) return; @@ -3836,6 +4374,15 @@ public void add_ls_et(LList ls, LLine l1, LLine l2, int n) { } } + /** + * Creates and returns a rule representing an equal angle configuration. + * + * Constructs a new rule using the provided angle transformations. + * + * @param t1 the first angle transformation + * @param t2 the second angle transformation + * @return the constructed Rule object representing equal angles + */ public Rule add_rule_eqag(AngTr t1, AngTr t2) { Rule r = new Rule(Rule.EQ_ANGLE); Mnde m1 = new Mnde(); @@ -3848,6 +4395,18 @@ public Rule add_rule_eqag(AngTr t1, AngTr t2) { return r; } + /** + * Creates a new list node as a sub-structure of the existing list. + * + * Copies the given list, updates the angle transformation at the specified index, + * and links the new node to the backup chain. + * + * @param ls the original list of nodes + * @param t1 the original angle transformation + * @param t2 the new angle transformation to be applied + * @param n the index at which the transformation is updated + * @return the newly created list node with the updated transformation + */ public LList add_ls_node_sub(LList ls, AngTr t1, AngTr t2, int n) { LList ls1 = new LList(); ls1.cp(ls); @@ -3857,12 +4416,14 @@ public LList add_ls_node_sub(LList ls, AngTr t1, AngTr t2, int n) { return ls1; } - public LList cp_l_list(LList ls) { - LList ls1 = new LList(); - ls1.type = LList.ANGLE; - return ls1; - } - + /** + * Displays the angle transformation information. + * + * Depending on the available transformation details, prints the angle + * using the corresponding representation. + * + * @param tr the angle transformation to display + */ void show_tr(AngTr tr) { if (tr == null) return; if (tr.t1 != 0 && tr.t2 != 0) diff --git a/src/main/java/gprover/GDDAux.java b/src/main/java/gprover/GDDAux.java index 67758de1..b3ca8e6c 100644 --- a/src/main/java/gprover/GDDAux.java +++ b/src/main/java/gprover/GDDAux.java @@ -1,17 +1,17 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Jan 10, 2007 - * Time: 2:27:35 PM - * To change this template use File | Settings | File Templates. + * GDDAux extends GDD to provide auxiliary processing methods for geometric constructions. */ public class GDDAux extends GDD { /* main entry */ static long time; - + /** + * Initiates auxiliary processing steps. + * + * @return true if the auxiliary processing is successfully initiated. + */ boolean add_aux() { gno = cons_no; ax_backward(); @@ -28,13 +28,23 @@ boolean add_aux() { return true; } - + /** + * Adds an auxiliary point if it does not already exist. + * + * @param ax the auxiliary point to add. + */ public void add_aux(AuxPt ax) { if (aux_exists(ax)) return; vauxpts.add(ax); } + /** + * Checks if the given auxiliary point already exists in the list. + * + * @param ax the auxiliary point to check. + * @return true if the auxiliary point exists, false otherwise. + */ private boolean aux_exists(AuxPt ax) { int n = ax.getPtsNo(); if (n > 1) return false; @@ -49,6 +59,13 @@ private boolean aux_exists(AuxPt ax) { return false; } + /** + * Determines if the auxiliary point contains the specified point. + * + * @param ax the auxiliary point. + * @param pt the point to check. + * @return true if the point is contained within the auxiliary point, false otherwise. + */ private boolean isaux_contpt(AuxPt ax, ProPoint pt) { int n = ax.getPtsNo(); for (int i = 0; i < n; i++) { @@ -59,33 +76,56 @@ private boolean isaux_contpt(AuxPt ax, ProPoint pt) { return false; } + /** + * Compares two points to determine if they are the same. + * + * @param p1 the first point. + * @param p2 the second point. + * @return true if the points are considered the same, false otherwise. + */ private boolean isSamePt(ProPoint p1, ProPoint p2) { if (p1.type != p2.type) return false; return Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY() - p2.getY(), 2) < ZERO * ZERO; } - + /** + * Checks if the elapsed time since start exceeds the defined limit. + * + * @return true if the time is over the limit, false otherwise. + */ public boolean time_over() { long t = System.currentTimeMillis() - time; if (t > 200000) return true; return false; } - + /** + * Records the current system time as the start time for timing. + */ public void time_start() { time = System.currentTimeMillis(); } + /** + * Creates a new auxiliary point of the specified type. + * + * @param aux the auxiliary identifier. + * @param type the type of the point. + * @return the created auxiliary point. + */ ProPoint aux_pt(int aux, int type) { ProPoint p = new ProPoint(type); p.aux = aux; return p; } - - //****************************************************************** - + /** + * Adds the given point as an auxiliary point after generating its descriptive string. + * + * @param t the auxiliary identifier. + * @param pt the point to be added. + */ private void add_as_aux(int t, ProPoint pt) { if (pt == null) return; @@ -97,6 +137,15 @@ private void add_as_aux(int t, ProPoint pt) { return; } + /** + * Creates an auxiliary point based on a tangent line configuration. + * + * @param aux the auxiliary identifier. + * @param p1 the first defining point. + * @param p2 the second defining point. + * @param p3 the third defining point. + * @return the created auxiliary point for the tangent line. + */ ProPoint aux_tline(int aux, int p1, int p2, int p3) { ProPoint pt = aux_pt(aux, C_O_T); pt.ps[0] = 0; @@ -107,6 +156,15 @@ ProPoint aux_tline(int aux, int p1, int p2, int p3) { return (pt); } + /** + * Creates an auxiliary tangent line point and adds it to the auxiliary list. + * + * @param aux the auxiliary identifier. + * @param p1 the first defining point. + * @param p2 the second defining point. + * @param p3 the third defining point. + * @return the created auxiliary tangent line point. + */ ProPoint auxpt_tline(int aux, int p1, int p2, int p3) { ProPoint pt = aux_tline(aux, p1, p2, p3); if (pt != null) @@ -114,6 +172,14 @@ ProPoint auxpt_tline(int aux, int p1, int p2, int p3) { return pt; } + /** + * Creates an auxiliary midpoint between two points. + * + * @param aux the auxiliary identifier. + * @param p1 the first point. + * @param p2 the second point. + * @return the created auxiliary midpoint. + */ ProPoint aux_mid(int aux, int p1, int p2) { ProPoint pt = aux_pt(aux, C_MIDPOINT); pt.ps[0] = cons_no; @@ -123,6 +189,14 @@ ProPoint aux_mid(int aux, int p1, int p2) { return (pt); } + /** + * Creates an auxiliary midpoint and adds it to the auxiliary list. + * + * @param aux the auxiliary identifier. + * @param p1 the first point. + * @param p2 the second point. + * @return the created auxiliary midpoint after adding it. + */ ProPoint auxpt_mid(int aux, int p1, int p2) { ProPoint pt = aux_mid(aux, p1, p2); if (pt != null) @@ -130,7 +204,17 @@ ProPoint auxpt_mid(int aux, int p1, int p2) { return pt; } - + /** + * Creates an intersection point for two lines using the provided points. + * The point is computed and validated by cal_ax_ill. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @return the constructed intersection point if valid; otherwise, null. + */ ProPoint aux_ill(int aux, int p1, int p2, int p3, int p4) { ProPoint pt = aux_pt(aux, C_I_LL); pt.ps[0] = cons_no; @@ -143,6 +227,17 @@ ProPoint aux_ill(int aux, int p1, int p2, int p3, int p4) { return null; } + /** + * Creates and adds an intersection point for two lines. + * Computes the point using aux_ill and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ill(int aux, int p1, int p2, int p3, int p4) { ProPoint pt = aux_ill(aux, p1, p2, p3, p4); if (pt != null) @@ -150,6 +245,18 @@ ProPoint auxpt_ill(int aux, int p1, int p2, int p3, int p4) { return pt; } + /** + * Creates an intersection point for a line configuration using five points. + * The point is computed and validated by cal_ax_ilp. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @param p5 fifth point identifier. + * @return the constructed intersection point if valid; otherwise, null. + */ ProPoint aux_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { ProPoint pt = aux_pt(aux, C_I_LP); pt.ps[0] = cons_no; @@ -163,6 +270,18 @@ ProPoint aux_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { return null; } + /** + * Creates and adds an intersection point for a line configuration. + * Computes the point using aux_ilp and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @param p5 fifth point identifier. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { ProPoint pt = aux_ilp(aux, p1, p2, p3, p4, p5); if (pt != null) @@ -170,26 +289,16 @@ ProPoint auxpt_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { return pt; } - ProPoint aux_ilt(int aux, int p1, int p2, int p3, int p4, int p5) { - ProPoint pt = aux_pt(aux, C_I_LT); - pt.ps[0] = cons_no; - pt.ps[1] = p1; - pt.ps[2] = p2; - pt.ps[3] = p3; - pt.ps[4] = p4; - pt.ps[5] = p5; - cal_ax_ilt(pt, p1, p2, p3, p4, p5); - - return (pt); - } - - ProPoint auxpt_ilt(int aux, int p1, int p2, int p3, int p4, int p5) { - ProPoint pt = aux_ilt(aux, p1, p2, p3, p4, p5); - if (pt != null) - add_as_aux(aux, pt); - return pt; - } - + /** + * Calculates the foot of the perpendicular from a point onto a line. + * The foot is computed using points p1, p2, and p3 via cal_ax_foot. + * + * @param aux auxiliary identifier. + * @param p1 the point from which the perpendicular is drawn. + * @param p2 the first point defining the line. + * @param p3 the second point defining the line. + * @return the point representing the foot of the perpendicular. + */ ProPoint aux_foot(int aux, int p1, int p2, int p3) { ProPoint pt = aux_pt(aux, C_FOOT); pt.ps[0] = cons_no; @@ -200,6 +309,16 @@ ProPoint aux_foot(int aux, int p1, int p2, int p3) { return (pt); } + /** + * Creates and adds the foot of the perpendicular from a point onto a line. + * Computes the foot using aux_foot and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 the point from which the perpendicular is drawn. + * @param p2 the first point defining the line. + * @param p3 the second point defining the line. + * @return the added perpendicular foot point. + */ ProPoint auxpt_foot(int aux, int p1, int p2, int p3) { ProPoint pt = aux_foot(aux, p1, p2, p3); if (pt != null) @@ -207,6 +326,16 @@ ProPoint auxpt_foot(int aux, int p1, int p2, int p3) { return pt; } + /** + * Creates an intersection point between a line and a circle. + * Uses points p1 and p2 along with the circle's center and first point to compute the intersection. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param cr the circle used for the intersection. + * @return the intersection point if successfully computed; otherwise, null. + */ ProPoint aux_ilc(int aux, int p1, int p2, ACir cr) { ProPoint p = aux_pt(aux, C_I_LC); p.ps[0] = cons_no; @@ -220,6 +349,16 @@ ProPoint aux_ilc(int aux, int p1, int p2, ACir cr) { return null; } + /** + * Creates and adds an intersection point between a line and a circle. + * Computes the point using aux_ilc and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param cr the circle used for the intersection. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ilc(int aux, int p1, int p2, ACir cr) { ProPoint pt = aux_ilc(aux, p1, p2, cr); if (pt != null) @@ -227,6 +366,17 @@ ProPoint auxpt_ilc(int aux, int p1, int p2, ACir cr) { return pt; } + /** + * Calculates the intersection point between a line and a circle using a translation approach. + * The point is computed using p1, p2, and p3 along with the circle’s properties via cal_ax_ipc. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param cr the circle used for the intersection. + * @return the calculated intersection point if successful; otherwise, null. + */ ProPoint aux_ipc(int aux, int p1, int p2, int p3, ACir cr) { ProPoint pt = aux_pt(aux, C_I_PC); pt.ps[0] = cons_no; @@ -240,6 +390,17 @@ ProPoint aux_ipc(int aux, int p1, int p2, int p3, ACir cr) { return (null); } + /** + * Creates and adds an intersection point between a line and a circle. + * Computes the point using aux_ipc and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param cr the circle used for the intersection. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ipc(int aux, int p1, int p2, int p3, ACir cr) { ProPoint pt = aux_ipc(aux, p1, p2, p3, cr); if (pt != null) @@ -247,6 +408,14 @@ ProPoint auxpt_ipc(int aux, int p1, int p2, int p3, ACir cr) { return pt; } + /** + * Computes the circumcenter point of a circle. + * The circumcenter is calculated from the circle's defining points via cal_ax_co. + * + * @param aux auxiliary identifier. + * @param cr the circle for which the circumcenter is computed. + * @return the computed circumcenter point. + */ ProPoint aux_co(int aux, ACir cr) { ProPoint pt = aux_pt(aux, C_CIRCUM); //62 pt.ps[0] = 0; @@ -257,6 +426,14 @@ ProPoint aux_co(int aux, ACir cr) { return (pt); } + /** + * Creates and adds the circumcenter point of a circle. + * Computes the point using aux_co and adds it if valid. + * + * @param aux auxiliary identifier. + * @param cr the circle for which the circumcenter is computed. + * @return the added circumcenter point. + */ ProPoint auxpt_co(int aux, ACir cr) { ProPoint pt = aux_co(aux, cr); if (pt != null) @@ -264,34 +441,18 @@ ProPoint auxpt_co(int aux, ACir cr) { return pt; } - - void ax_predicate() { - int[] p = conc.p; - switch (conc.pred) { - case 0: - return; - case CO_PERP: - { - LLine l1 = fd_ln(p[0], p[1]); - LLine l2 = fd_ln(p[2], p[3]); - if (l1 != null && l2 != null && inter_lls(l1, l2) == 0) { - ProPoint pt = auxpt_ill(1, p[0], p[1], p[2], p[3]); - } - } - break; - default: - break; - } - } - + /** + * Initiates the processing of auxiliary rules. + * This method serves as a placeholder for additional auxiliary rule implementations. + */ void aux_rules() { } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Iterates through all midpoint structures and processes them by checking for common line conditions + * and applying appropriate auxiliary transformations. + */ void ax_md() { MidPt md = all_md.nx; while (md != null) { @@ -311,6 +472,12 @@ void ax_md() { } } + /** + * Processes point network intersections for the given midpoint. + * It finds relevant lines forming the point network structure and calls further processing methods. + * + * @param md the midpoint structure to process + */ void ax_mdpn(MidPt md) { PLine pn = all_pn.nx; while (pn != null) { @@ -338,6 +505,18 @@ void ax_mdpn(MidPt md) { } } + /** + * Examines global lines and determines if auxiliary intersections should be created based on the + * provided network lines. + * + * @param pn the point network segment being examined + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param ln1 the first line corresponding to p1 + * @param ln2 the second line corresponding to p2 + * @param ln3 the third line corresponding to p3 + */ void ax_p3m(PLine pn, int p1, int p2, int p3, LLine ln1, LLine ln2, LLine ln3) { int m1, m2, m3; LLine ln; @@ -358,6 +537,15 @@ void ax_p3m(PLine pn, int p1, int p2, int p3, LLine ln1, LLine ln2, LLine ln3) { } } + /** + * Processes overlapping midpoint configurations between two midpoint structures. + * It identifies a common point from the first structure and iterates over global lines to trigger + * auxiliary midpoint creation when needed. + * + * @param md the first midpoint structure + * @param md1 the second midpoint structure for comparison + * @param l1 the line determined by the current configuration + */ void ax_mml(MidPt md, MidPt md1, LLine l1) { int p1, p2; @@ -382,6 +570,13 @@ void ax_mml(MidPt md, MidPt md1, LLine l1) { } } + /** + * Handles mismatched midpoint configurations by evaluating parallel conditions and generating + * auxiliary intersections when specific criteria are met. + * + * @param md the first midpoint structure + * @param md1 the second midpoint structure + */ void ax_mm(MidPt md, MidPt md1) { int m1, m2, p1, p2, p3, p4; p1 = md.a; @@ -423,7 +618,10 @@ void ax_mm(MidPt md, MidPt md1) { } } - + /** + * Iterates through all tangent lines and applies orthogonal transformations + * by processing each non-zero type tangent line. + */ void ax_orth() { TLine tn = all_tn.nx; @@ -437,6 +635,14 @@ void ax_orth() { } } + /** + * Processes orthogonal configurations for a given tangent line and its associated lines. + * If the lines meet the required intersection conditions, auxiliary intersection points are generated. + * + * @param tn1 the primary tangent line to process + * @param ln1 the first line associated with the tangent + * @param ln2 the second line associated with the tangent + */ void ax_orth1(TLine tn1, LLine ln1, LLine ln2) { int a, b, c, h; @@ -468,7 +674,11 @@ void ax_orth1(TLine tn1, LLine ln1, LLine ln2) { } } - + /** + * Processes all TLine elements in the list and applies geometric constructions + * including circle intersections, angle adjustments, midpoint validations, + * and constructing auxiliary points based on line intersections. + */ void ax_tn() { TLine tn = all_tn.nx; while (tn != null) { @@ -488,7 +698,13 @@ void ax_tn() { } } - + /** + * Processes circle intersections for the given TLine. + * Evaluates intersections between the circles and the two lines of the TLine, + * and constructs auxiliary points if the intersection conditions are met. + * + * @param tn the TLine whose circle intersections are to be processed + */ void ax_tn_cr(TLine tn) { int p2, p3, m; LLine ln; @@ -543,7 +759,13 @@ void ax_tn_cr(TLine tn) { } } - + /** + * Processes angle-related transformations for the given TLine. + * Iterates over angle configuration objects and, based on the positional + * relationships of the TLine's segments, constructs auxiliary intersection points. + * + * @param tn the TLine for which angle transformations are evaluated + */ void ax_tn_as(TLine tn) { int p1, p2, p3; LLine ln, n1, n2, l1, l2, l3, l4; @@ -600,6 +822,13 @@ void ax_tn_as(TLine tn) { } } + /** + * Processes midpoint constructions associated with the given TLine. + * Searches through midpoint objects and, if the conditions are met, + * constructs an auxiliary foot point. + * + * @param tn the TLine used for evaluating midpoint intersections + */ void ax_tn_md(TLine tn) { int p1, p2; @@ -641,7 +870,10 @@ void ax_tn_md(TLine tn) { } } - + /** + * Processes all TLine elements to construct perpendicular line intersections. + * Delegates to ax_tn_ln for each TLine's pair of lines. + */ void ax_tn_1() { TLine tn = all_tn.nx; while (tn != null) { @@ -654,6 +886,14 @@ void ax_tn_1() { } } + /** + * Evaluates intersections and geometric relationships between two lines. + * Constructs auxiliary foot points if the specified conditions and + * intersection criteria are satisfied. + * + * @param ln1 the first line used in the intersection check + * @param ln2 the second line used in the intersection check + */ void ax_tn_ln(LLine ln1, LLine ln2) { int p1, p2, p3; @@ -696,6 +936,15 @@ void ax_tn_ln(LLine ln1, LLine ln2) { } } + /** + * Processes candidate intersections between lines within a TLine context. + * Iterates through candidate line groups to construct auxiliary points based + * on midpoint validations and line intersections. + * + * @param tn the TLine context for the operation + * @param ln1 the first line segment involved in the intersection check + * @param ln2 the second line segment involved in the intersection check + */ void ax_tn_21(TLine tn, LLine ln1, LLine ln2) { int p2, p3, p4, p5; int p1 = inter_ll(ln1, ln2); @@ -738,6 +987,11 @@ void ax_tn_21(TLine tn, LLine ln1, LLine ln2) { } } + /** + * Processes all angle transformation objects. + * Iterates through the list of angles and delegates processing + * to specific configuration methods based on the angle type. + */ void ax_as() { Angles as1; LLine l1, l2, l3, l4; @@ -760,6 +1014,16 @@ void ax_as() { } } + /** + * Evaluates the angle transformation for a specific configuration. + * Constructs auxiliary points by verifying intersection points and circle + * conditions for the configuration defined by the provided lines. + * + * @param as the angle transformation object to process + * @param l1 the first line defining the angle + * @param l2 the second line defining the angle + * @param l3 the auxiliary line used for comparative intersection analysis + */ void ax_as_1(Angles as, LLine l1, LLine l2, LLine l3) { int p1, p2, p3, p4; @@ -817,8 +1081,18 @@ void ax_as_1(Angles as, LLine l1, LLine l2, LLine l3) { } -/* [op1,l2]=[l2,op3] */ - + /** + * Processes angle transformations by iterating through candidate points on the given line. + * If the line between p1 and p3 intersects l2, no transformation is applied. + * Otherwise, for each point p2 on l2 (excluding o and midpoints between p1 and p3), + * an auxiliary intersection is recorded. + * + * @param as the current Angles instance + * @param o the reference point to exclude from processing + * @param p1 the first defining point of the line segment + * @param p3 the second defining point of the line segment + * @param l2 the line containing candidate points + */ void ax_at(Angles as, int o, int p1, int p3, LLine l2) { if (inter_ll(l2, fd_ln(p1, p3)) != 0) return; @@ -830,6 +1104,17 @@ void ax_at(Angles as, int o, int p1, int p3, LLine l2) { } } + /** + * Processes paired angle structures by determining intersections between two pairs of lines. + * If valid intersection points exist between l1/l2 and l3/l4 respectively, this method + * initiates further angle processing using ax_as_21. + * + * @param as the current Angles instance + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + */ void ax_as_2(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { int p1, p2; if (((p1 = inter_ll(l1, l2)) == 0) || ((p2 = inter_ll(l3, l4)) == 0)) return; @@ -838,6 +1123,20 @@ void ax_as_2(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { ax_as_21(as, p2, p1, l3, l4, l1, l2); } + /** + * Processes detailed angle transformations based on intersections and circle conditions. + * This method evaluates intersections between l1 and l3 (or l2 and l4) along with additional + * geometric constraints. If the conditions are met and no conflicting line exists, an auxiliary + * intersection is recorded. + * + * @param as the current Angles instance + * @param p1 the intersection point from the first pair of lines + * @param p2 the intersection point from the second pair of lines + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + */ void ax_as_21(Angles as, int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, m; @@ -867,6 +1166,12 @@ void ax_as_21(Angles as, int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) } } + /** + * Iterates over all circles and applies various circle-related transformations. + * For each circle that is active (non-zero type), this method triggers a sequence of + * operations including center determination, chord and arc processing, tangent and + * diameter handling. + */ void ax_cr() { ACir cr = all_cir.nx; while (cr != null) { @@ -882,6 +1187,13 @@ void ax_cr() { } } + /** + * Processes the diameter of a circle by evaluating candidate lines from the circle's center + * to its boundary points. If a candidate line exists and does not yield an intersection via + * circle-line logic, an auxiliary intersection is registered. + * + * @param cr the circle to be processed + */ void ax_diameter(ACir cr) { for (int i = 0; i <= cr.no; i++) { LLine ln = fd_ln(cr.o, cr.pt[i]); @@ -891,6 +1203,14 @@ void ax_diameter(ACir cr) { } } + /** + * Processes tangent line generation for a circle. + * If the circle's center is valid and the circle contains concave points, + * the method iterates over the circle's points to determine if a tangent line is missing. + * When a point qualifies, a tangent is created. + * + * @param cr1 the circle to be processed for tangency + */ void ax_tan(ACir cr1) { int i; if (cr1.o == 0 || cr1.no <= 1) return; @@ -902,6 +1222,12 @@ void ax_tan(ACir cr1) { } } + /** + * Checks if a given point is part of a predefined concave point set. + * + * @param p the point to check + * @return true if the point is in the concave set, false otherwise + */ boolean in_conc(int p) { for (int i = 0; i <= 7; i++) if (conc.p[i] == p) return (true); return (false); @@ -937,6 +1263,14 @@ void ax_cr_cr(ACir cr1) { } } + /** + * Processes detailed intersection actions between two circles at specified points. + * + * @param cr1 the first circle involved in the intersection + * @param cr2 the second circle involved in the intersection + * @param p1 the first intersection point from circle calculations + * @param p2 the second intersection point from circle calculations + */ void ax_cr_cr1(ACir cr1, ACir cr2, int p1, int p2) { int p3, p4, p5, p6; ProPoint pt1, pt2, pt3, pt4; @@ -969,6 +1303,11 @@ void ax_cr_cr1(ACir cr1, ACir cr2, int p1, int p2) { } } + /** + * Processes circle intersections by evaluating tangent constructions and auxiliary points. + * + * @param cr the circle for which intersections are processed + */ void ax_cr1(ACir cr) { int p1, p2, p3, p4; LLine l1; @@ -997,6 +1336,11 @@ void ax_cr1(ACir cr) { } } + /** + * Verifies and processes tangent intersections for the provided circle. + * + * @param cr the circle used for tangent intersection checking + */ void ax_cr2(ACir cr) { LLine l1; int o = cr.o; @@ -1012,6 +1356,11 @@ void ax_cr2(ACir cr) { } } + /** + * Determines and processes the center of a circle based on intersecting lines and points. + * + * @param cr the circle for which the center is being determined + */ void ax_center(ACir cr) { LLine l1, l2; PLine pn; @@ -1059,7 +1408,9 @@ void ax_center(ACir cr) { } } - + /** + * Processes point network intersections and applies auxiliary transformations. + */ void ax_pn() { int p1, p2, p3, p4; @@ -1116,20 +1467,9 @@ void ax_pn() { } } - public void add_ax_t1() { - CongSeg cg = all_cg.nx; - while (cg != null) { - if (cg.p1 != cg.p3 && cg.p1 != cg.p4 && cg.p2 != cg.p3 && cg.p2 != cg.p4) { - if (!xpara(cg.p1, cg.p2, cg.p3, cg.p4) && !xcong(cg.p1, cg.p3, cg.p2, cg.p4) - && !xcong(cg.p1, cg.p4, cg.p2, cg.p3)) { -// auxpt_ill(0,) - - } - } - cg = cg.nx; - } - } - + /** + * Processes congruence segments within the point network. + */ public void ax_cg() { CongSeg cg = all_cg.nx; while (cg != null) { @@ -1137,11 +1477,9 @@ public void ax_cg() { } } - - - ////////////////////////////////////////////////////////////////////// - //backward; - + /** + * Initiates the backward process based on current configuration in the point network. + */ public void ax_backward() { int[] p = conc.p; @@ -1164,7 +1502,13 @@ public void ax_backward() { } } - + /** + * Processes backward midpoint transformations for the given points. + * + * @param m the midpoint involved in the transformation + * @param p1 the first point component of the midpoint + * @param p2 the second point component of the midpoint + */ public void ax_bk_mid(int m, int p1, int p2) { //1: rotat. @@ -1175,7 +1519,15 @@ public void ax_bk_mid(int m, int p1, int p2) { -//////////////////////////////////////////////////////////////// + /** + * Calculates the Y coordinate on the tangent line for point p1 using p2 and p3. + * Sets the point pt with an X coordinate of 0 and the computed Y coordinate. + * + * @param pt the point to update with the computed coordinate + * @param p1 the reference point for the tangent calculation + * @param p2 the second point used in the calculation + * @param p3 the third point used in the calculation + */ public void cal_ax_tn(ProPoint pt, int p1, int p2, int p3) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1188,6 +1540,14 @@ public void cal_ax_tn(ProPoint pt, int p1, int p2, int p3) { pt.setXY(0, y); } + /** + * Calculates the midpoint of points p1 and p2. + * Updates pt with the computed midpoint coordinates. + * + * @param pt the point to update with the midpoint coordinates + * @param p1 the first point + * @param p2 the second point + */ public void cal_ax_md(ProPoint pt, int p1, int p2) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1196,6 +1556,17 @@ public void cal_ax_md(ProPoint pt, int p1, int p2) { pt.setXY((x1 + x2) / 2, (y1 + y2) / 2); } + /** + * Calculates the intersection point between the lines defined by (p1, p2) and (p3, p4). + * Updates pt with the computed intersection coordinates if valid. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if an intersection point is successfully computed, false otherwise + */ public boolean cal_ax_ill(ProPoint pt, int p1, int p2, int p3, int p4) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1225,6 +1596,15 @@ public boolean cal_ax_ill(ProPoint pt, int p1, int p2, int p3, int p4) { return true; } + /** + * Calculates the foot of the perpendicular from point p1 to the line defined by p2 and p3. + * Updates pt with the computed foot coordinates. + * + * @param pt the point to update with the foot coordinates + * @param p1 the point from which the perpendicular is drawn + * @param p2 the first point defining the line + * @param p3 the second point defining the line + */ public void cal_ax_foot(ProPoint pt, int p1, int p2, int p3) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1240,6 +1620,18 @@ public void cal_ax_foot(ProPoint pt, int p1, int p2, int p3) { pt.setXY(x, y); } + /** + * Calculates the intersection point for a line configuration using points p1, p2, p3, p4, and p5. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param p4 the fourth reference point + * @param p5 the fifth reference point + * @return true if the intersection is successfully computed, false otherwise + */ public boolean cal_ax_ilp(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1271,33 +1663,15 @@ public boolean cal_ax_ilp(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { return true; } - public void cal_ax_ilt(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { - double x1 = VPTX(p1); - double y1 = VPTY(p1); - double x2 = VPTX(p2); - double y2 = VPTY(p2); - double x3 = VPTX(p3); - double y3 = VPTY(p3); - double x4 = VPTX(p4); - double y4 = VPTY(p4); - double x5 = VPTX(p5); - double y5 = VPTY(p5); - - double xt1 = x2 - x1; - double xt2 = -(y5 - y4); - double yt1 = y2 - y1; - double yt2 = x5 - x4; - if (Math.abs(xt1) > ZERO) { - double x = (xt1 * xt2 * (y3 - y1) + yt1 * x1 * xt2 - yt2 * x3 * xt1) / (yt1 * xt2 - yt2 * xt1); - double y = y1 + (x - x1) * yt1 / xt1; - pt.setXY(x, y); - } else { - double x = x1; - double y = y3 + yt2 * (x - x3) / xt2; - pt.setXY(x, y); - } - } - + /** + * Calculates the center based on the configuration of points p1, p2, and p3. + * Updates pt with the computed center coordinates. + * + * @param pt the point to update with the center coordinates + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + */ public void cal_ax_co(ProPoint pt, int p1, int p2, int p3) { double x_1 = VPTX(p1); double x_2 = VPTY(p1); @@ -1318,6 +1692,19 @@ public void cal_ax_co(ProPoint pt, int p1, int p2, int p3) { pt.setXY(x, y); } + /** + * Calculates the intersection point between a translated line and a circle. + * The translation is based on the vector from p1 to p2 applied to p3. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first reference point for the translation vector + * @param p2 the second reference point for the translation vector + * @param p3 the base point for translation + * @param p4 the first point defining the circle + * @param p5 the second point defining the circle + * @return true if the intersection is successfully computed, false otherwise + */ public boolean cal_ax_ipc(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1342,6 +1729,18 @@ public boolean cal_ax_ipc(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { return true; } + /** + * Calculates the intersection point between the line defined by p1 and p2 + * and the circle defined by p3 and p4. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first point defining the line + * @param p2 the second point defining the line + * @param p3 the first point defining the circle + * @param p4 the second point defining the circle + * @return true if an intersection point is successfully computed, false otherwise + */ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1360,6 +1759,21 @@ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { return true; } + /** + * Computes the intersection points between the line defined by (x1, y1) and (x2, y2) + * and the circle defined by center (x3, y3) with a radius derived from (x4, y4). + * Returns an array containing two intersection points formatted as [t1, m1, t2, m2]. + * + * @param x1 the x-coordinate of the first point on the line + * @param y1 the y-coordinate of the first point on the line + * @param x2 the x-coordinate of the second point on the line + * @param y2 the y-coordinate of the second point on the line + * @param x3 the x-coordinate used as a reference for the circle + * @param y3 the y-coordinate used as a reference for the circle + * @param x4 the x-coordinate used to derive the circle's radius + * @param y4 the y-coordinate used to derive the circle's radius + * @return an array containing the intersection points [t1, m1, t2, m2], or an empty array if there are none + */ double[] cal_inter_lc(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double r2 = (y4 - y3) * (y4 - y3) + (x4 - x3) * (x4 - x3); @@ -1399,6 +1813,12 @@ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { } } + /** + * Generates a descriptive string for the given point based on its type. + * Updates the text attribute of pt with the generated description. + * + * @param pt the point for which the description is generated + */ void auxpt_string(ProPoint pt) { String s = pt.toString(); if (s == null || s.length() == 0) { @@ -1432,6 +1852,12 @@ void auxpt_string(ProPoint pt) { } } + /** + * Generates and returns an auxiliary name for a new point. + * The name is determined based on existing constraint names. + * + * @return the generated auxiliary name + */ protected String fd_aux_name() { char c[] = new char[1];//= new char[3]; int len = 1; diff --git a/src/main/java/gprover/GDDBase.java b/src/main/java/gprover/GDDBase.java index e4019670..69ba0a30 100644 --- a/src/main/java/gprover/GDDBase.java +++ b/src/main/java/gprover/GDDBase.java @@ -6,9 +6,20 @@ * To change this template use File | Settings | File Templates. */ package gprover; - +/** + * Base class for geometric deduction database operations. + */ public class GDDBase extends Gib { + /** + * Returns an index corresponding to the occurrence of a value among three candidates. + * + * @param p the value to match + * @param p1 the first candidate value + * @param p2 the second candidate value + * @param p3 the third candidate value + * @return 1 if p equals p1, 2 if p equals p2, 3 if p equals p3, otherwise 0 + */ final int ind_3(int p, int p1, int p2, int p3) { if (p == p1) return (1); if (p == p2) return (2); @@ -16,6 +27,13 @@ final int ind_3(int p, int p1, int p2, int p3) { return (0); } + /** + * Returns an index corresponding to the occurrence of a value among the first three elements of an array. + * + * @param p the value to match + * @param pp an array of candidate values (must contain at least three elements) + * @return 1 if p equals pp[0], 2 if p equals pp[1], 3 if p equals pp[2], otherwise 0 + */ final int ind_3(int p, int[] pp) { if (p == pp[0]) return (1); if (p == pp[1]) return (2); @@ -23,7 +41,14 @@ final int ind_3(int p, int[] pp) { return (0); } - + /** + * Determines whether the points identified by a, b, and c are collinear and registers the condition if true. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @return true if the points are collinear, false otherwise + */ final boolean ycoll(int a, int b, int c) { boolean i = xcoll(a, b, c); if (i) { @@ -32,14 +57,15 @@ final boolean ycoll(int a, int b, int c) { return (i); } - final boolean ypara(int a, int b, int p, int q) { - boolean i = xpara(a, b, p, q); - if (i) { - add_codb(CO_PARA, a, b, p, q, 0, 0, 0, 0); - } - return (i); - } - + /** + * Determines whether the lines defined by points (a, b) and (p, q) are perpendicular and records the condition if so. + * + * @param a the first point on the first line + * @param b the second point on the first line + * @param p the first point on the second line + * @param q the second point on the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean yperp(int a, int b, int p, int q) { boolean i = xperp(a, b, p, q); if (i) { @@ -48,6 +74,15 @@ final boolean yperp(int a, int b, int p, int q) { return (i); } + /** + * Checks whether the segments defined by (a, b) and (p, q) are congruent and registers the condition if they are. + * + * @param a the first point of the first segment + * @param b the second point of the first segment + * @param p the first point of the second segment + * @param q the second point of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean ycong(int a, int b, int p, int q) { boolean i = xcong(a, b, p, q); if (i) { @@ -56,26 +91,25 @@ final boolean ycong(int a, int b, int p, int q) { return (i); } - final boolean yacong(int a, int b, int c, int p, int q, int r) { - boolean i = xacong(a, b, c, p, q, r); - if (i) { - add_codb(CO_ACONG, a, b, b, c, p, q, q, r); - } - return (i); - } - - final boolean ycir2(int o, int a, int b) { - boolean i = xcir2(o, a, b); - if (i) { - add_codb(CO_CYCLIC, o, a, b, 0, 0, 0, 0, 0); - } - return (i); - } - + /** + * Checks if the given identifier is below the current depth or if the point registry is full. + * + * @param id the identifier to check + * @return true if id is less than depth or the point registry is full, false otherwise + */ final boolean ch_dep(long id) { return id < depth || isPFull(); } + /** + * Processes the provided circular arc by adding corresponding conditions for parallelism, cyclicity, and congruence. + * + * @param cr the circular arc used to derive conditions + * @param m1 the first marker or identifier related to the arc + * @param m2 the second marker or identifier related to the arc + * @param p1 the first point used for condition registration + * @param p2 the second point used for condition registration + */ final void add_cr_pn_as(ACir cr, int m1, int m2, int p1, int p2) { int lm = R_CR_P_EQARC; @@ -106,6 +140,15 @@ final void add_cr_pn_as(ACir cr, int m1, int m2, int p1, int p2) { pop_codb(); } + /** + * Applies type 3 processing by adding cyclic, midpoint, and angle conditions based on the given markers and points. + * + * @param m the primary marker + * @param m2 the marker for the first midpoint condition + * @param p2 the point used in cyclic and midpoint conditions + * @param m3 the marker for the second midpoint condition + * @param p3 the point used in cyclic and midpoint conditions + */ final void add_type3(int m, int m2, int p2, int m3, int p3) { int p1; add_codb(CO_CYCLIC, m, p2, p3, 0, 0, 0, 0, 0); @@ -127,22 +170,15 @@ final void add_type3(int m, int m2, int p2, int m3, int p3) { pop_codb(); } - final void add_type4(int m, int m1, int p1, int m2, int p2) { - add_codb(CO_PARA, m1, m2, p1, p2, 0, 0, 0, 0); - add_codb(CO_CYCLIC, m, p1, p2, 0, 0, 0, 0, 0); - add_codb(CO_MIDP, m, m1, m2, 0, 0, 0, 0, 0); - add_cir4(64, 0, m1, m2, p1, p2); - add_ea_pt_t(64, m1, m, p1, p2, m, m2); - add_ea_pt_t(64, m1, p1, m, m, p2, m2); - add_ea_pt_t(64, m2, m, p1, p2, m, m1); - add_ea_pt_t(64, m2, p1, m, m, p2, m1); - pop_codb(); - pop_codb(); - pop_codb(); - } - /* Lemmas */ + /** + * Searches for perpendicular and parallel relationships between a point-based + * line and a t-line, and adds corresponding conditions. + * + * @param pn the point-based line + * @param tn the t-line to be analyzed + */ final void search_pn_tn(PLine pn, TLine tn) { LLine ln, l1, l2; int i; @@ -175,6 +211,14 @@ final void search_pn_tn(PLine pn, TLine tn) { } } + /** + * Establishes a midpoint connection based on a midpoint object and two lines, + * adding necessary conditions if valid. + * + * @param md the midpoint instance containing connection data + * @param l1 the first line for connection + * @param l2 the second line for connection + */ final void lm_md_connection(MidPt md, LLine l1, LLine l2) { int lm = R_MID_CONNECTION; if (!valid(lm)) return; @@ -207,11 +251,25 @@ final void lm_md_connection(MidPt md, LLine l1, LLine l2) { } } + /** + * Checks if the given integer meets connection criteria based on internal state. + * + * @param n the value to be checked + * @return true if the condition is met, false otherwise + */ boolean ch_it(int n) { return ((d_base != 0) ? (n != 0) : ((n) == 1)); } + /** + * Constructs a parallelogram configuration based on a midpoint and two lines, + * adding conditions and lines if the configuration is valid. + * + * @param md the midpoint used for establishing the parallelogram + * @param l1 the first line of the configuration + * @param l2 the second line of the configuration + */ final void lm_parallelogram(MidPt md, LLine l1, LLine l2) { if (!valid(R_PARALLELOGRAM)) return; @@ -261,7 +319,15 @@ final void lm_parallelogram(MidPt md, LLine l1, LLine l2) { } } - + /** + * Establishes a ratio condition based on intersections of lines defined by points. + * + * @param lm the lemma identifier for the ratio condition + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + */ final void lm_RATIO(int lm, int p1, int p2, int p3, int p4) { if (!valid(R_RATIO)) return; @@ -280,19 +346,23 @@ final void lm_RATIO(int lm, int p1, int p2, int p3, int p4) { } } - /////////////////////////////////////////////////////////////////////////// - /// this frome pred.cpp - - final void copy_pred(Cond p1, Cond p2) { - p2.pred = p1.pred; - p2.u.cpv(p1.u); - for (int i = 0; i <= 7; i++) p2.p[i] = p1.p[i]; - } - + /** + * Determines whether two condition nodes are equivalent. + * + * @param n1 the first condition node + * @param n2 the second condition node + * @return true if both nodes are equivalent, false otherwise + */ boolean new_eq(Cond n1, Cond n2) { return (n1.pred == n2.pred && n1.u.equal(n2.u)); } + /** + * Creates a new condition node with a given predicate value. + * + * @param pred the predicate identifier for the condition + * @return a new condition node instance + */ final Cond new_pr(int pred) { Cond nd = new Cond(); nd.pred = pred; @@ -309,6 +379,9 @@ final Cond new_pr(int pred) { return nd; } + /** + * Adjusts the condition list by updating the last condition based on equivalence. + */ final void new_ot() { int i = 0; Cond nd1, nd = all_nd.nx; @@ -324,6 +397,20 @@ final void new_ot() { } } + /** + * Creates and adds a new condition node with specified properties. + * + * @param n the predicate or condition type + * @param p1 the first parameter + * @param p2 the second parameter + * @param p3 the third parameter + * @param p4 the fourth parameter + * @param p5 the fifth parameter + * @param p6 the sixth parameter + * @param p7 the seventh parameter + * @param p8 the eighth parameter + * @return the newly created condition node + */ Cond add_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { // if(p1 == 1 && p2 ==4 && p3 == 1 && p4 == 9) @@ -381,6 +468,9 @@ Cond add_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int } + /** + * Removes the last added condition node from the condition database. + */ final void pop_codb() { Cond co = co_db.nx; if (co != null) { @@ -388,6 +478,12 @@ final void pop_codb() { } /* free((cond *)co); */ } + /** + * Creates and adds a new coordinate condition node with the specified predicate. + * + * @param n the predicate for the coordinate condition + * @return the newly created coordinate condition node + */ Cond add_coxy(int n) { Cond co = new Cond(); co.pred = n; @@ -404,16 +500,11 @@ Cond add_coxy(int n) { return (co); } - final void add_codx(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - Cond co = add_codb(n, p1, p2, p3, p4, p5, p6, p7, p8); - if (co.pred != 0) { - co_db.nx = co.nx; - co.nx = co_xy.nx; - co_xy.nx = co; - } - } - - + /** + * Creates and adds a new parallel condition node associated with the given predicted line. + * + * @param pn the predicted line to be associated with the parallel condition + */ final void new_para(PLine pn) { Cond nd = new Cond(); nd.pred = CO_PARA; @@ -426,10 +517,14 @@ final void new_para(PLine pn) { } } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - /* geometry predictaes */ - + /** + * Checks if the three specified points are collinear. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the points are collinear, false otherwise + */ final boolean xcoll(int p1, int p2, int p3) { LLine ln; @@ -440,7 +535,14 @@ final boolean xcoll(int p1, int p2, int p3) { return (ln != null); } - + /** + * Finds and returns the line that contains the three specified points, if such a line exists. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the line (LLine) containing the points, or null if none exists + */ final LLine fo_ln3(int p1, int p2, int p3) { LLine ln; ln = all_ln.nx; @@ -453,6 +555,13 @@ final LLine fo_ln3(int p1, int p2, int p3) { return (null); } + /** + * Finds and returns a line that passes through all specified non-zero points in the array. + * + * @param ps an array of points + * @param n the number of indices to check in the array + * @return the line (LLine) if found, or null otherwise + */ final LLine fo_ln(int ps[], int n) ///xxxxx { LLine ln; @@ -474,17 +583,44 @@ final LLine fo_ln(int ps[], int n) ///xxxxx return (null); } + /** + * Checks if the four points satisfy collinearity conditions. + * If the first two points are equal, it delegates to xcoll; otherwise, it ensures collinearity for both + * subsets. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if the relevant points are collinear, false otherwise + */ final boolean xcoll4(int p1, int p2, int p3, int p4) { if (p1 == p2) return (xcoll(p2, p3, p4)); return (xcoll(p1, p2, p3) && xcoll(p1, p2, p4)); } + /** + * Determines whether the two lines defined by the point pairs (p1, p2) and (p3, p4) are parallel. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are parallel, false otherwise + */ final boolean xpara(int p1, int p2, int p3, int p4) { if (p1 == p2 || p3 == p4 || xcoll4(p1, p2, p3, p4)) return (true); return (fo_pn1(p1, p2, p3, p4) != null); } + /** + * Determines whether the two specified lines are parallel. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are parallel, false otherwise + */ final boolean ln_para(LLine l1, LLine l2) { PLine pn; if (l1 == l2) return (true); @@ -512,35 +648,27 @@ final boolean ln_para(LLine l1, LLine l2) { return (false); } - final PLine fo_pn(int p1, int p2, int p3, int p4) { - PLine pn = all_pn.nx; - while (pn != null) { - if (pn.no == 0) { - pn = pn.nx; - continue; - } - for (int i = 0; i <= pn.no; i++) { - if (on_ln(p1, pn.ln[i]) && on_ln(p2, pn.ln[i])) { - for (int j = i + 1; j <= pn.no; j++) - if (on_ln(p3, pn.ln[j]) && on_ln(p4, pn.ln[j])) return (pn); - if (pn.type != 0) return (null); //?? - } else if (on_ln(p3, pn.ln[i]) && on_ln(p4, pn.ln[i])) { - for (int j = i + 1; j <= pn.no; j++) - if (on_ln(p1, pn.ln[j]) && on_ln(p2, pn.ln[j])) return (pn); - if (pn.type != 0) return (null);//?? - } - } - pn = pn.nx; - } - return (null); - } - + /** + * Checks if the two lines defined by the points (p1, p2) and (p3, p4) are perpendicular. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean xperp(int p1, int p2, int p3, int p4) { if (p1 == p2 || p3 == p4) return (true); return fo_tn1(p1, p2, p3, p4) != null; } - + /** + * Determines whether the two specified lines are perpendicular. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean ln_perp(LLine l1, LLine l2) { if (l1 == l2) return false; if (l1 == null) { @@ -567,23 +695,12 @@ final boolean ln_perp(LLine l1, LLine l2) { return (false); } - final TLine fo_tn(int p1, int p2, int p3, int p4) { - LLine ln1, ln2; - TLine tn; - if (p1 == p2 || p3 == p4) return (null); - ln1 = fd_ln(p1, p2); - if (ln1 == null) return (null); - ln2 = fd_ln(p3, p4); - if (ln2 == null) return (null); - tn = all_tn.nx; - while (tn != null) { - if ((tn.l1 == ln1 && tn.l2 == ln2) || (tn.l1 == ln2 && tn.l2 == ln1)) return (tn); - tn = tn.nx; - } - return (null); - } - - + /** + * Searches for an existing circle that is a sub-circle of the given circle. + * + * @param c1 the reference circle (ACir) to compare against + * @return an existing circle that matches, or null if none is found + */ final ACir xcir(ACir c1) { ACir c2; c2 = all_cir.nx; @@ -594,6 +711,16 @@ final ACir xcir(ACir c1) { return (null); } + /** + * Finds and returns a circle based on a specified property and four points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the found circle (ACir) or null if none exists + */ final ACir fo_cr(int o, int p1, int p2, int p3, int p4) { test_c.o = o; test_c.no = 3; @@ -604,6 +731,14 @@ final ACir fo_cr(int o, int p1, int p2, int p3, int p4) { return (xcir(test_c)); } + /** + * Checks for the existence of a circle defined by the given property and two points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @return true if such a circle exists, false otherwise + */ final boolean xcir2(int o, int p1, int p2) { test_c.o = o; test_c.no = 1; @@ -612,6 +747,15 @@ final boolean xcir2(int o, int p1, int p2) { return (xcir(test_c) != null); } + /** + * Checks for the existence of a circle defined by the given property and three points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if such a circle exists, false otherwise + */ final boolean xcir3(int o, int p1, int p2, int p3) { test_c.o = o; test_c.no = 2; @@ -621,6 +765,16 @@ final boolean xcir3(int o, int p1, int p2, int p3) { return (xcir(test_c) != null); } + /** + * Checks for the existence of a circle defined by the given property and four points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if such a circle exists, false otherwise + */ final boolean xcir4(int o, int p1, int p2, int p3, int p4) { test_c.o = o; test_c.no = 3; @@ -631,21 +785,26 @@ final boolean xcir4(int o, int p1, int p2, int p3, int p4) { return (xcir(test_c) != null); } - final boolean xcir5(int o, int p1, int p2, int p3, int p4, int p5) { - test_c.o = o; - test_c.no = 4; - test_c.pt[0] = p1; - test_c.pt[1] = p2; - test_c.pt[2] = p3; - test_c.pt[3] = p4; - test_c.pt[4] = p5; - return (xcir(test_c) != null); - } - + /** + * Checks if a midpoint exists for the specified segment within the given model. + * + * @param m the model identifier + * @param a the first endpoint of the segment + * @param b the second endpoint of the segment + * @return true if a midpoint exists for the segment, false otherwise + */ final boolean xmid(int m, int a, int b) { return (fo_md(m, a, b) != null); } + /** + * Searches for and returns a midpoint corresponding to the specified model and endpoints. + * + * @param m the model identifier + * @param a the first endpoint + * @param b the second endpoint + * @return the midpoint (MidPt) if found, or null otherwise + */ final MidPt fo_md(int m, int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -658,6 +817,13 @@ final MidPt fo_md(int m, int a, int b) { return (null); } + /** + * Searches for and returns a midpoint defined by the two specified endpoints. + * + * @param a the first endpoint + * @param b the second endpoint + * @return the midpoint (MidPt) if one exists, or null otherwise + */ final MidPt fo_md(int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -669,6 +835,17 @@ final MidPt fo_md(int a, int b) { return (null); } + /** + * Determines if the angles defined by points (a, b, c) and (p, q, r) are congruent. + * + * @param a the first point of the first angle + * @param b the vertex of the first angle + * @param c the third point of the first angle + * @param p the first point of the second angle + * @param q the vertex of the second angle + * @param r the third point of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean xacong(int a, int b, int c, int p, int q, int r) { if (!check_eqangle(a, b, c, p, q, r)) { return false; @@ -683,6 +860,19 @@ final boolean xacong(int a, int b, int c, int p, int q, int r) { return (ln_acong(l1, l2, l3, l4)); } + /** + * Determines if the angles defined by points (a, b, c, d) and (p, q, r, s) are congruent. + * + * @param a the first point of the first angle + * @param b the second point of the first angle + * @param c the third point of the first angle + * @param d the fourth point of the first angle + * @param p the first point of the second angle + * @param q the second point of the second angle + * @param r the third point of the second angle + * @param s the fourth point of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean xacong(int a, int b, int c, int d, int p, int q, int r, int s) { if (!check_eqangle(a, b, c, d, p, q, r, s)) return false; @@ -695,7 +885,13 @@ final boolean xacong(int a, int b, int c, int d, int p, int q, int r, int s) { return (ln_acong(l1, l2, l3, l4)); } - + /** + * Compares two lines based on their unique identifiers. + * + * @param l1 the first line to compare + * @param l2 the second line to compare + * @return 1 if l1 has a greater id than l2, 0 if they are equal, -1 if l1 has a smaller id than l2 + */ final int line_compare(LLine l1, LLine l2) { if (l1 == null) { // TODO. Handle this. @@ -713,6 +909,16 @@ final int line_compare(LLine l1, LLine l2) { return 0; } + /** + * Retrieves the angle set associated with the given four lines. + * Depending on the current state, a different method is used to generate the angle set. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the set of angles (Angles) if found, or null otherwise + */ final Angles fo_las(LLine l1, LLine l2, LLine l3, LLine l4) { Angles as; if (isPFull()) @@ -722,7 +928,16 @@ final Angles fo_las(LLine l1, LLine l2, LLine l3, LLine l4) { return as; } - final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) //???? + /** + * Determines the angle set for the provided four lines based on available line ordering and comparisons. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the angle set (Angles) if found, or null otherwise + */ + final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) { LLine n1, n2; Angles as; @@ -795,17 +1010,15 @@ final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) //???? return (null); } - final Angles fo_as(int a, int b, int c, int d, int p, int q, int r, int s) { - LLine l1, l2, l3, l4; - l1 = fd_ln(a, b); - l2 = fd_ln(c, d); - l3 = fd_ln(p, q); - l4 = fd_ln(r, s); - if (l1 == null || l2 == null || l3 == null || l4 == null) return (null); - return (fo_las(l1, l2, l3, l4)); - } - - + /** + * Determines if the angles defined by (l1, l2) and (l3, l4) are congruent. + * + * @param l1 first line of the first angle + * @param l2 second line of the first angle + * @param l3 first line of the second angle + * @param l4 second line of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean ln_acong(LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == null || l2 == null || l3 == null || l4 == null) { int k = 0; @@ -828,7 +1041,15 @@ final boolean ln_acong(LLine l1, LLine l2, LLine l3, LLine l4) { return (fo_las(l1, l2, l3, l4) != null); } - + /** + * Checks whether the segments defined by endpoints a, b and p, q are congruent. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean xcong(int a, int b, int p, int q) { if (!check_eqdistance(a, b, p, q)) return false; @@ -864,6 +1085,17 @@ final boolean xcong(int a, int b, int p, int q) { return (false); } + /** + * Determines if the segments (a, b) and (p, q) are congruent using specific angle values. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @param t1 first angle factor for congruency check + * @param t2 second angle factor for congruency check + * @return true if the segments are congruent based on the provided ratios, false otherwise + */ final boolean xcong1(int a, int b, int p, int q, int t1, int t2) { CongSeg cg; int o; @@ -903,10 +1135,28 @@ final boolean xcong1(int a, int b, int p, int q, int t1, int t2) { return cg.t1 * t1 == cg.t2 * t2; } + /** + * Checks if the segments (a, b) and (c, d) are congruent using both default and extended methods. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @return true if the segments are congruent by any method, false otherwise + */ final boolean xcong_all(int a, int b, int c, int d) { return xcong(a, b, c, d) || xcong1(a, b, c, d); } + /** + * Checks whether the segments defined by endpoints a, b and p, q are congruent using an alternative ratio approach. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean xcong1(int a, int b, int p, int q) { CongSeg cg; int o; @@ -939,6 +1189,15 @@ final boolean xcong1(int a, int b, int p, int q) { return (false); } + /** + * Searches for a congruent segment in the ratio group for segments (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if found, null otherwise + */ final CongSeg fo_rg1(int a, int b, int p, int q) { CongSeg cg = all_rg.nx; while (cg != null) { @@ -948,6 +1207,15 @@ final CongSeg fo_rg1(int a, int b, int p, int q) { return null; } + /** + * Returns the first matching congruent segment from the ratio list based on endpoints (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if present; null otherwise + */ final CongSeg fo_cg1(int a, int b, int p, int q) { CongSeg cg; int o; @@ -970,6 +1238,15 @@ final CongSeg fo_cg1(int a, int b, int p, int q) { return (null); } + /** + * Retrieves a congruent segment from the common group based on endpoints (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if found, null otherwise + */ final CongSeg fo_cg(int a, int b, int p, int q) { CongSeg cg; int o; @@ -992,17 +1269,52 @@ final CongSeg fo_cg(int a, int b, int p, int q) { return (null); } + /** + * Determines whether the triangles defined by points (a, b, c) and (p, q, r) are similar. + * + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return true if the triangles are similar, false otherwise + */ boolean xsim_tri(int a, int b, int c, int p, int q, int r) { if (!check_simtri(a, b, c, p, q, r)) return false; return (fo_st(1, 0, a, b, c, p, q, r) != null); } + /** + * Determines whether the triangles defined by points (a, b, c) and (p, q, r) are congruent. + * + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return true if the triangles are congruent, false otherwise + */ boolean xcon_tri(int a, int b, int c, int p, int q, int r) { if (!this.check_simtri(a, b, c, p, q, r)) return false; return (fo_st(0, 0, a, b, c, p, q, r) != null); } + /** + * Finds a similar or congruent triangle structure based on the provided vertices. + * + * @param xsim_2 flag to indicate extended similarity testing + * @param xsim_1 flag to optionally bypass congruency type check + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return the triangle structure if found, null otherwise + */ SimTri fo_st(int xsim_2, int xsim_1, int a, int b, int c, int p, int q, int r) { SimTri st = (xsim_2 != 0) ? all_st.nx : all_ct.nx; //??? while (st != null) { @@ -1014,6 +1326,19 @@ SimTri fo_st(int xsim_2, int xsim_1, int a, int b, int c, int p, int q, int r) { return (null); } + /** + * Checks if the ratio of lengths between segments (a, b) and (c, d) equals that between (p, q) and (r, s). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @param p first endpoint of the third segment + * @param q second endpoint of the third segment + * @param r first endpoint of the fourth segment + * @param s second endpoint of the fourth segment + * @return true if the ratios are equal, false otherwise + */ boolean xeq_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { if ((xcong(a, b, p, q) && xcong(c, d, r, s)) || (xcong(a, b, c, d) && xcong(p, q, r, s)) || @@ -1022,6 +1347,19 @@ boolean xeq_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { return (fo_ra(a, b, c, d, p, q, r, s) != null); } + /** + * Finds and returns the ratio segment structure that matches the given endpoints. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @param p first endpoint of the third segment + * @param q second endpoint of the third segment + * @param r first endpoint of the fourth segment + * @param s second endpoint of the fourth segment + * @return the matching ratio segment structure if found, null otherwise + */ RatioSeg fo_ra(int a, int b, int c, int d, int p, int q, int r, int s) { RatioSeg ra = all_ra.nx; for (; ra != null; ra = ra.nx) { @@ -1038,7 +1376,13 @@ RatioSeg fo_ra(int a, int b, int c, int d, int p, int q, int r, int s) { return (null); } - + /** + * Compares two lines based on their primary endpoints. + * + * @param l1 the first line to compare + * @param l2 the second line to compare + * @return true if l1 is considered less than l2, false otherwise + */ boolean ln_less(LLine l1, LLine l2) { if (l1 == l2) return (false); if (l1.pt[1] < l2.pt[1]) return (true); @@ -1047,6 +1391,15 @@ boolean ln_less(LLine l1, LLine l2) { return (false); } + /** + * Compares two pairs of lines to determine order. + * + * @param l1 first line of the first pair + * @param l2 second line of the first pair + * @param l3 first line of the second pair + * @param l4 second line of the second pair + * @return true if the second pair is considered less than the first pair, false otherwise + */ boolean l2_less(LLine l1, LLine l2, LLine l3, LLine l4) { LLine ln; if (ln_less(l2, l1)) { @@ -1064,16 +1417,15 @@ boolean l2_less(LLine l1, LLine l2, LLine l3, LLine l4) { return (false); } - - int get_cpt2(ACir c1, int p1, int p2) { - char j; - if (c1 == null) return 0; /// 2006.7.10 - for (j = 0; j <= c1.no; j++) { - if (c1.pt[j] != p1 && c1.pt[j] != p2) return (c1.pt[j]); - } - return (0); - } - + /** + * Returns the third point of circle c1 that is not equal to p1, p2, or p3. + * + * @param c1 the circle to examine + * @param p1 the first point to exclude + * @param p2 the second point to exclude + * @param p3 the third point to exclude + * @return the point number that is different from p1, p2, and p3, or 0 if not found + */ int get_cpt3(ACir c1, int p1, int p2, int p3) { char j; for (j = 0; j <= c1.no; j++) { @@ -1083,6 +1435,13 @@ int get_cpt3(ACir c1, int p1, int p2, int p3) { return (0); } + /** + * Finds the intersection point of two lines if one exists. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point number if found, 0 otherwise + */ int inter_ll(LLine l1, LLine l2) { if (l1 == null || l2 == null || l1 == l2) return (0); LLine ln1, ln2; @@ -1105,6 +1464,14 @@ int inter_ll(LLine l1, LLine l2) { return (0); } + /** + * Finds the intersection of two lines that is different from a given point. + * + * @param l1 the first line + * @param l2 the second line + * @param p1 the point to exclude from the intersection result + * @return the intersection point number if found and not equal to p1, 0 otherwise + */ int inter_ll1(LLine l1, LLine l2, int p1) { char i, j; if (l1 == l2) return (0); @@ -1117,6 +1484,13 @@ int inter_ll1(LLine l1, LLine l2, int p1) { return (0); } + /** + * Finds the intersection point between a line and a circle. + * + * @param l1 the line to check for intersection + * @param c1 the circle to check for intersection + * @return the intersection point number if found, 0 otherwise + */ int inter_lc(LLine l1, ACir c1) { char i, j; if (l1 == null || c1 == null) return (0); @@ -1127,6 +1501,14 @@ int inter_lc(LLine l1, ACir c1) { return (0); } + /** + * Returns the intersection point between a line and a circle, excluding a given point. + * + * @param l1 the line to check + * @param c1 the circle to check + * @param p1 the point to exclude + * @return the intersection point or 0 if none + */ int inter_lc1(LLine l1, ACir c1, int p1) { if (l1 == null || c1 == null) return (0); @@ -1137,6 +1519,13 @@ int inter_lc1(LLine l1, ACir c1, int p1) { return (0); } + /** + * Returns the intersection point between two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return the intersection point or 0 if none + */ int inter_cc(ACir c1, ACir c2) { char i, j; for (i = 0; i <= c1.no; i++) @@ -1146,6 +1535,14 @@ int inter_cc(ACir c1, ACir c2) { return (0); } + /** + * Returns the intersection point between two circles, excluding a given point. + * + * @param c1 the first circle + * @param c2 the second circle + * @param p1 the point to exclude + * @return the intersection point or 0 if none + */ int inter_cc1(ACir c1, ACir c2, int p1) { char i, j; for (i = 0; i <= c1.no; i++) @@ -1155,28 +1552,13 @@ int inter_cc1(ACir c1, ACir c2, int p1) { return (0); } - int fd_pt_la(int o, int p1, int p2) { - int i, p3; - LLine ln; - ln = fd_ln(p1, p2); - if (ln == null || ln.no <= 1) return (0); - for (i = 0; i <= ln.no; i++) { - p3 = ln.pt[i]; - if (!meq_pt(p3, p1) && !meq_pt(p3, p2) && xacong(p1, o, p3, p3, o, p2)) return (p3); - } - return (0); - } - - int common_pp(PLine pl1, PLine pl2) { - char i, j; - for (i = 0; i <= pl1.no; i++) - for (j = 0; j <= pl2.no; j++) { - if (pl1.ln[i] == pl2.ln[j]) return (1); - } - return (0); - } - - + /** + * Finds the midpoint index for the segment defined by two points. + * + * @param a the first point + * @param b the second point + * @return the midpoint index or 0 if not found + */ int fd_pt_md(int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -1186,26 +1568,14 @@ int fd_pt_md(int a, int b) { return (0); } - int fd_pt_ref(int a, int o) { - MidPt md = all_md.nx; - while (md != null) { - if (md.m == o && a == md.a) return (md.b); - if (md.m == o && a == md.b) return (md.a); - md = md.nx; - } - return (0); - } - - - MidPt fd_md_ml(int m, LLine l) { - MidPt md = all_md.nx; - while (md != null) { - if (md.m == m && on_ln(md.a, l)) return (md); - md = md.nx; - } - return (null); - } - + /** + * Adds a midpoint for the segment between two points if valid. + * + * @param lm the midpoint lemma or marker + * @param pt the new midpoint + * @param p1 the first endpoint + * @param p2 the second endpoint + */ final void add_mid(int lm, int pt, int p1, int p2) { MidPt md; if (p1 == p2 || !check_mid(pt, p1, p2)) { @@ -1229,6 +1599,13 @@ final void add_mid(int lm, int pt, int p1, int p2) { } } + /** + * Checks if a point is on the given line. + * + * @param p the point to check + * @param ln the line to inspect + * @return true if the point exists on the line; false otherwise + */ boolean on_ln(int p, LLine ln) { int i; if (ln == null) return (false); @@ -1236,6 +1613,13 @@ boolean on_ln(int p, LLine ln) { return (false); } + /** + * Determines if all points of one line are contained within another line. + * + * @param l1 the line to check if it is a subline + * @param l2 the line to be checked against + * @return true if l1 is a subline of l2; false otherwise + */ boolean sub_ln(LLine l1, LLine l2) { int i; if (l1 == null) { @@ -1247,6 +1631,12 @@ boolean sub_ln(LLine l1, LLine l2) { return (true); } + /** + * Adds a point to the line in sorted order. + * + * @param p the point to add + * @param ln the line to which the point is added + */ final void add_pt2l(int p, LLine ln) { int j, i = 0; while (i <= ln.no && ln.pt[i] < p) i++; @@ -1263,6 +1653,13 @@ final void add_pt2l(int p, LLine ln) { } } + /** + * Finds a finite line that contains the two specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return the line containing both points or null if not found + */ LLine fd_ln(int p1, int p2) { LLine ln = all_ln.nx; while (ln != null && !(ln.type != 0 && on_ln(p1, ln) && on_ln(p2, ln))) { @@ -1271,6 +1668,14 @@ LLine fd_ln(int p1, int p2) { return (ln); } + /** + * Finds a finite line that contains the three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the line containing the three points or null if not found + */ LLine fd_ln3(int p1, int p2, int p3) { LLine ln = all_ln.nx; while (ln != null) { @@ -1283,6 +1688,14 @@ LLine fd_ln3(int p1, int p2, int p3) { return (null); } + /** + * Retrieves a line from a parallel structure that contains the specified point. + * + * @param p1 the point to check + * @param p2 the first reference point for the parallel line search + * @param p3 the second reference point for the parallel line search + * @return the line that contains the point or null if not found + */ LLine fd_pline(int p1, int p2, int p3) { int i; PLine pn; @@ -1293,6 +1706,14 @@ LLine fd_pline(int p1, int p2, int p3) { return (null); } + /** + * Retrieves a transversal line associated with the given points. + * + * @param p1 the point to check + * @param p2 the first reference point for the transversal search + * @param p3 the second reference point for the transversal search + * @return the transversal line containing the point or null if not found + */ LLine fd_tline(int p1, int p2, int p3) { LLine ln; TLine tn; @@ -1310,6 +1731,13 @@ LLine fd_tline(int p1, int p2, int p3) { return (null); } + /** + * Searches for a line within a parallel structure that contains the given point. + * + * @param pn the parallel line structure + * @param p the point to check + * @return the line containing the point or null if not found + */ LLine fd_ln_pn1(PLine pn, int p) { int i; if (pn == null) return (null); @@ -1317,15 +1745,12 @@ LLine fd_ln_pn1(PLine pn, int p) { return (null); } - LLine fd_ln1(int p1) { - LLine ln = all_ln.nx; - while (ln != null) { - if (on_ln(p1, ln) && ln.type != 0 && ln.no > 1) return (ln); - ln = ln.nx; - } - return (null); - } - + /** + * Finds a finite line associated with the given line by checking for shared intersection points. + * + * @param l1 the reference line + * @return the associated finite line or null if not found + */ LLine fd_lnl(LLine l1) { LLine ln = all_ln.nx; int p1, p2; @@ -1340,6 +1765,13 @@ LLine fd_lnl(LLine l1) { return (null); } + /** + * Retrieves or constructs a refined line related to the given line based on an exclusion point. + * + * @param l1 the original line + * @param p the exclusion point for refining the line + * @return the refined line or the original line if no refinement is needed + */ LLine fd_ln_rl(LLine l1, int p) { if (l1.type != 0) return l1; @@ -1370,7 +1802,13 @@ LLine fd_ln_rl(LLine l1, int p) { } - + /** + * Creates a new line with the two specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return the newly created line or null if the points are identical + */ LLine add_ln(int p1, int p2) { if (p1 == p2) { @@ -1395,6 +1833,13 @@ LLine add_ln(int p1, int p2) { return (ln); } + /** + * Combines two lines to create a new line that contains points from both. + * + * @param l1 the first line + * @param l2 the second line + * @return the new combined line or null if the combined line is a subline of an existing line + */ LLine add_ln2l(LLine l1, LLine l2) { test_ln.cp_ln(l1); LLine ln = test_ln; @@ -1413,6 +1858,13 @@ LLine add_ln2l(LLine l1, LLine l2) { return ln; } + /** + * Finds an existing line containing the two points or creates a new one if not found. + * + * @param p1 the first point + * @param p2 the second point + * @return the found or newly created line + */ LLine fadd_ln(int p1, int p2) { LLine ln; ln = fd_ln(p1, p2); @@ -1420,7 +1872,13 @@ LLine fadd_ln(int p1, int p2) { return (add_ln(p1, p2)); } - + /** + * Creates a copy of the given line by duplicating its point data. + * The new copy is linked as the last line. + * + * @param ln the line to copy + * @return a new line object that is a copy of ln + */ LLine cp_ln(LLine ln) { LLine ln1; ln1 = new LLine(); @@ -1433,6 +1891,13 @@ LLine cp_ln(LLine ln) { return (ln1); } + /** + * Replaces occurrences of ln1 with ln2 in parallel, perpendicular, and angle relations. + * Updates related structures accordingly. + * + * @param ln1 the original line to be replaced + * @param ln2 the new line to substitute for ln1 + */ final void ch_ln(LLine ln1, LLine ln2) { LLine l1, l2, l3, l4; @@ -1558,6 +2023,15 @@ final void ch_ln(LLine ln1, LLine ln2) { } } + /** + * Adds a line based on three given point identifiers. + * Validates collinearity and either creates a new line or updates an existing one. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @param p3 identifier for the third point + */ final void add_line(int lm, int p1, int p2, int p3) { LLine ln1; if (xcoll(p1, p2, p3)) return; @@ -1586,6 +2060,15 @@ final void add_line(int lm, int p1, int p2, int p3) { ch_lns(ln1); } + /** + * Adds a line for hypothesis purposes, defined by three point identifiers. + * If the line exists, it updates the structure; otherwise, it creates a new one. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @param p3 identifier for the third point + */ final void add_line1(int lm, int p1, int p2, int p3) { // for hypothesis only. if (!check_coll(p1, p2, p3)) { add_checkError(); @@ -1600,6 +2083,12 @@ final void add_line1(int lm, int p1, int p2, int p3) { // for hypothesis on add_line(lm, p1, p2, p3); } + /** + * Processes and adjusts collections of lines. + * Iterates through sub-line relationships to update and merge lines as needed. + * + * @param ln1 the initial line to process and potentially replace with merged data + */ public void ch_lns(LLine ln1) { LLine ln2, ln3, ln4; ln2 = ln1; @@ -1641,12 +2130,25 @@ public void ch_lns(LLine ln1) { last_nd.u.ln = ln2; } + /** + * Checks if the given line is contained within the specified parallel line container. + * + * @param ln the line to check for membership + * @param pn the parallel line container to search + * @return true if ln is part of pn; otherwise, false + */ boolean on_pn(LLine ln, PLine pn) { int i; for (i = 0; i <= pn.no; i++) if (pn.ln[i] == ln) return (true); return (false); } + /** + * Finds the parallel line container associated with the specified line. + * + * @param ln the line for which to locate its parallel container + * @return the parallel line container if found; otherwise, null + */ PLine fd_pnl(LLine ln) { PLine pn; pn = all_pn.nx; @@ -1656,6 +2158,13 @@ PLine fd_pnl(LLine ln) { return (pn); } + /** + * Searches within the parallel line container for a line that contains the specified point. + * + * @param p the point identifier to look for + * @param ln the parallel line container in which to search + * @return the line containing the point if found; otherwise, null + */ LLine fd_lpp2(int p, LLine ln) { PLine pn; pn = all_pn.nx; @@ -1669,12 +2178,26 @@ LLine fd_lpp2(int p, LLine ln) { return (null); } + /** + * Retrieves the parallel line container corresponding to the line defined by two points. + * + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @return the associated parallel line container if it exists; otherwise, null + */ PLine fd_pn(int p1, int p2) { LLine ln = fd_ln(p1, p2); if (ln == null) return (null); return (fd_pnl(ln)); } + /** + * Finds an alternative parallel line container (different from the given one) that includes the specified line. + * + * @param pn the current parallel line container + * @param ln the line to search for in other containers + * @return another parallel line container if found; otherwise, null + */ PLine fd_pnp(PLine pn, LLine ln) { PLine pn1; pn1 = all_pn.nx; @@ -1684,6 +2207,13 @@ PLine fd_pnp(PLine pn, LLine ln) { return (null); } + /** + * Creates a copy of the given parallel line container. + * Duplicates its type, line array, and other associated properties. + * + * @param pn the parallel line container to copy + * @return a new parallel line container that is a copy of pn + */ PLine cp_pn(PLine pn) { PLine pn1; char i; @@ -1700,6 +2230,12 @@ PLine cp_pn(PLine pn) { return (pn1); } + /** + * Merges two parallel line containers by uniting the lines from pn2 into pn1. + * + * @param pn1 the primary parallel line container to update + * @param pn2 the source container whose lines will be merged into pn1 + */ final void pn_un(PLine pn1, PLine pn2) { for (int i = 0; i <= pn2.no; i++) if (!on_pn(pn2.ln[i], pn1)) { @@ -1716,18 +2252,16 @@ final void pn_un(PLine pn1, PLine pn2) { } } - - final PLine fd_pn(LLine ln1, LLine ln2) { - PLine pn1 = all_pn.nx; - while (pn1 != null) - if (pn1.type != 0 && on_pn(ln1, pn1) && on_pn(ln2, pn1)) - return (pn1); - else - pn1 = pn1.nx; - return null; - } - - + /** + * Adds a parallel line structure using four point identifiers. + * Validates the input and creates a new parallel line container to represent the relation. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point of the first line + * @param p2 identifier for the second point of the first line + * @param p3 identifier for the first point of the second line + * @param p4 identifier for the second point of the second line + */ final void add_pline(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1766,7 +2300,15 @@ final void add_pline(int lm, int p1, int p2, int p3, int p4) { //adj_pn(pn); } - + /** + * Adds a parallel connection between two lines. + * Creates a new parallel line container if the given lines are not already parallel. + * + * @param lm the lemma identifier used for processing + * @param ln1 the first line in the connection + * @param ln2 the second line in the connection + * @return the newly created parallel line container if the connection is established; otherwise, null + */ PLine add_px(int lm, LLine ln1, LLine ln2) { if (!valid(lm)) return null; @@ -1789,12 +2331,24 @@ PLine add_px(int lm, LLine ln1, LLine ln2) { return (pn); } - + /** + * Checks if the given LLine is one of the defining lines of the specified TLine. + * + * @param ln the line to check + * @param tn the TLine whose defining lines are examined + * @return true if ln equals tn.l1 or tn.l2, false otherwise + */ boolean on_tn(LLine ln, TLine tn) { if ((ln == tn.l1) || (ln == tn.l2)) return (true); return (false); } + /** + * Finds and returns the first non-zero type TLine that uses the given LLine. + * + * @param ln the LLine to search for in TLines + * @return the found TLine, or null if none exists + */ TLine fd_tn(LLine ln) { TLine tn; tn = all_tn.nx; @@ -1808,6 +2362,13 @@ TLine fd_tn(LLine ln) { return (tn); } + /** + * Creates a new TLine from two given LLines. + * + * @param ln1 the first LLine component + * @param ln2 the second LLine component + * @return the newly created TLine + */ TLine add_tn(LLine ln1, LLine ln2) { TLine tn = new TLine(); tn.l1 = ln1; @@ -1820,6 +2381,14 @@ TLine add_tn(LLine ln1, LLine ln2) { return (tn); } + /** + * Adds a TLine based on two LLines if they are valid and not perpendicular. + * + * @param lm the lemma (identifier) associated with the TLine + * @param l1 the first LLine component + * @param l2 the second LLine component + * @return the added TLine, or null if invalid conditions are met + */ final TLine add_tline(int lm, LLine l1, LLine l2) { if (!valid(lm)) return null; @@ -1837,6 +2406,15 @@ final TLine add_tline(int lm, LLine l1, LLine l2) { return tn1; } + /** + * Adds a TLine using point indices by converting them to LLines. + * + * @param lm the lemma (identifier) for the TLine + * @param p1 the first point of the first LLine + * @param p2 the second point of the first LLine + * @param p3 the first point of the second LLine + * @param p4 the second point of the second LLine + */ final void add_tline(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1860,6 +2438,14 @@ final void add_tline(int lm, int p1, int p2, int p3, int p4) { last_nd.u.tn = tn1; } + /** + * Adds a TLine from two LLines with a different coordinate source. + * + * @param lm the lemma (identifier) for the TLine + * @param l1 the first LLine component + * @param l2 the second LLine component + * @return the newly added TLine, or null if preconditions fail + */ final TLine add_tx(int lm, LLine l1, LLine l2) { if (!valid(lm)) return null; @@ -1877,7 +2463,15 @@ final TLine add_tx(int lm, LLine l1, LLine l2) { return tn1; } - + /** + * Adds a TLine in test mode using input point indices. + * + * @param lm the lemma (identifier) for the TLine + * @param p1 the first point of the first LLine + * @param p2 the second point of the first LLine + * @param p3 the first point of the second LLine + * @param p4 the second point of the second LLine + */ public void add_tline_t(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1904,7 +2498,13 @@ public void add_tline_t(int lm, int p1, int p2, int p3, int p4) { last_nd.u.tn = tn1; } - + /** + * Checks if a given point is contained in the specified circle. + * + * @param a the point to check; zero is always considered valid + * @param cr the circle in which to check for the point + * @return true if the point is found in the circle, or if a is zero; false otherwise + */ boolean on_cir(int a, ACir cr) { char i; if (a == 0) return (true); @@ -1912,13 +2512,13 @@ boolean on_cir(int a, ACir cr) { return (false); } - int eq_cir(int o, int a, ACir cr) { - char i; - if (cr.o != o) return (0); - for (i = 0; i <= cr.no; i++) if (cr.pt[i] == a) return (1); - return (0); - } - + /** + * Determines whether all points of the first circle are contained in the second circle. + * + * @param c1 the circle whose points are to be checked + * @param c2 the circle to check against + * @return true if c1 is a subset of c2, false otherwise + */ boolean sub_cir(ACir c1, ACir c2) { char i; if (c1.o == c2.o || c1.o == 0) { @@ -1930,32 +2530,14 @@ boolean sub_cir(ACir c1, ACir c2) { return (false); } - boolean circle_p(int ptn) { - char i; - ACir c1 = all_cir.nx; - if (ptn < 3) return (false); - - if (ptn == 3 && ATYPE(3) == C_POINT && ATYPE(2) == C_POINT - && ATYPE(1) == C_POINT) - return (false); - for (i = 1; i <= ptn; i++) - if (!(ATYPE(i) == C_POINT || ATYPE(i) == C_O_C || ATYPE(i) == C_CIRCLE || ATYPE(i) == C_CIRCUM)) - return (false); - - while (c1 != null) { - for (i = 1; i <= ptn; i++) - if (i != c1.o && !(on_cir(i, c1))) { - break; - } else - return true; - l1: - c1 = c1.nx; - } - - Cm.print("function : circle_p. careful! "); - return (false); - } - + /** + * Searches for a circle that contains all three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the identifier of the found circle if all points belong to it; otherwise, zero + */ int fd_co(int p1, int p2, int p3) { ACir c2; c2 = all_cir.nx; @@ -1966,6 +2548,13 @@ int fd_co(int p1, int p2, int p3) { return (0); } + /** + * Finds a circle with the specified center identifier that contains a given point. + * + * @param o the center identifier to match + * @param p the point to check for within the circle + * @return the found circle, or null if none match + */ ACir fd_cr_op(int o, int p) { ACir c2 = all_cir.nx; while (c2 != null) { @@ -1975,6 +2564,14 @@ ACir fd_cr_op(int o, int p) { return (null); } + /** + * Retrieves a circle that contains three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found circle containing all three points, or null if none exists + */ ACir fd_cr_p3(int p1, int p2, int p3) { ACir c2 = all_cir.nx; while (c2 != null) { @@ -1984,6 +2581,12 @@ ACir fd_cr_p3(int p1, int p2, int p3) { return (null); } + /** + * Finds and returns a circle that is similar to the given circle by matching common points. + * + * @param c1 the circle to compare + * @return a matching circle based on shared center or common points, or null if none is found + */ ACir fd_cir(ACir c1) { ACir c2; char i, j; @@ -2002,21 +2605,12 @@ ACir fd_cir(ACir c1) { return (null); } - ACir fd_cir(int o, int a) { - if (o == 0 || a == 0) return null; - - ACir cr = all_cir.nx; - while (cr != null) { - if (cr.type != 0 && cr.o == o) { - for (int i = 0; i <= cr.no; i++) - if (cr.pt[i] == a) return cr; - } - cr = cr.nx; - } - return null; - - } - + /** + * Adds a point to the specified circle in sorted order if it does not already exist. + * + * @param p the point to add + * @param cr the circle to which the point will be added + */ final void add_pt2c(int p, ACir cr) { int j, i = 0; if (p <= 0) return; @@ -2036,6 +2630,15 @@ final void add_pt2c(int p, ACir cr) { } } + /** + * Creates and adds a new circle with the given lemma, center, and initial two points. + * + * @param lm the lemma (identifier) associated with the circle + * @param o the center identifier of the circle + * @param a the first point defining the circle's boundary + * @param b the second point defining the circle's boundary + * @return the newly created circle, or null if the lemma is invalid + */ ACir add_c2(int lm, int o, int a, int b) { if (!valid(lm)) return null; @@ -2058,6 +2661,12 @@ ACir add_c2(int lm, int o, int a, int b) { return (cr); } + /** + * Creates a copy of the specified circle with the same properties and points. + * + * @param cir the circle to copy + * @return a new circle object that is a copy of cir + */ ACir cp_cr(ACir cir) { ACir cir1; char i; @@ -2074,40 +2683,14 @@ ACir cp_cr(ACir cir) { return (cir1); } - final void adj_cir(ACir cr) { - ACir cr1, cr2, cr3; - Cond co; - char i; - cr1 = cr; - while ((cr2 = fd_cir(cr1)) != null) { - if (sub_cir(cr2, cr1)) { - cr2.type = 0; - } else if (sub_cir(cr1, cr2)) { - cr1.type = 0; - cr1 = cr2; - } else { - cr3 = cp_cr(cr1); - cr1.type = 0; - cr2.type = 0; - if (cr3.o == 0) cr3.o = cr2.o; - for (i = 0; i <= cr2.no; i++) add_pt2c(cr2.pt[i], cr3); - if (cr1.co == null && cr2.co == null) - cr3.co = null; - else { - co_xy.nx = null; - co = add_coxy(CO_CYCLIC); - co.u.cr = cr1; - co = add_coxy(CO_CYCLIC); - co.u.cr = cr2; - cr3.co = co_xy.nx; - } - cr1 = cr3; - } - } - new_pr(CO_CYCLIC); - last_nd.u.cr = cr1; - } - + /** + * Adds a cyclic circle using the specified lemma, origin and two point identifiers. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + */ final void add_cir2(int lm, int o, int a, int b) { if (!valid(lm)) return; @@ -2118,6 +2701,15 @@ final void add_cir2(int lm, int o, int a, int b) { last_nd.u.cr = cr; } + /** + * Adds a cyclic circle using the specified lemma, origin, two point identifiers and an additional point. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + * @param c the additional point identifier to be added to the circle + */ final void add_cir3(int lm, int o, int a, int b, int c) { if (!valid(lm)) return; @@ -2132,6 +2724,16 @@ final void add_cir3(int lm, int o, int a, int b, int c) { last_nd.u.cr = cr; } + /** + * Adds a cyclic circle using the specified lemma, origin, two point identifiers and two additional points. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + * @param c the first additional point identifier to be added to the circle + * @param d the second additional point identifier to be added to the circle + */ final void add_cir4(int lm, int o, int a, int b, int c, int d) { if (!valid(lm)) return; @@ -2149,26 +2751,31 @@ final void add_cir4(int lm, int o, int a, int b, int c, int d) { last_nd.u.cr = cr; } - + /** + * Checks if the given pair of lines match the sides defined in the specified angles structure. + * + * @param l1 the first line + * @param l2 the second line + * @param as the angles structure to compare against + * @return true if the lines match either the first or second half of the angles structure; false otherwise + */ boolean onl_as(LLine l1, LLine l2, Angles as) { if (l1 == as.l1 && l2 == as.l2) return (true); if (l1 == as.l3 && l2 == as.l4) return (true); return (false); } - Angles fd_as(LLine l1, LLine l2) { - Angles as; - for (as = all_as.nx; as != null; as = as.nx) { - if ( - (l1 == as.l1 && l2 == as.l2) || (l1 == as.l2 && l2 == as.l1) || - (l1 == as.l3 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l3) || - (l1 == as.l1 && l2 == as.l3) || (l1 == as.l3 && l2 == as.l1) || - (l1 == as.l2 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l2)) - return (as); - } - return (null); - } - + /** + * Creates a new angles object from the given lemma and four lines representing two pairs of corresponding sides. + * Performs necessary comparisons and adjustments between the lines. + * + * @param lm the lemma identifier + * @param l1 the first line of the first angle pair + * @param l2 the second line of the first angle pair + * @param l3 the first line of the second angle pair + * @param l4 the second line of the second angle pair + * @return the created angles object, or null if the parameters are invalid + */ Angles add_as0(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (!valid(lm)) return null; @@ -2266,50 +2873,16 @@ Angles add_as0(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return (as); } - final void add_co_as(LLine l1, LLine l2, LLine l3, LLine l4) { - int p1, p2, p3, p4, p5, p6, p7, p8; - int a = inter_ll(l1, l2); - int b = inter_ll(l3, l4); - // a = b = 0; - if (a != 0) { - p2 = a; - p3 = a; - if (l1.pt[0] == a) - p1 = l1.pt[1]; - else - p1 = l1.pt[0]; - - if (l2.pt[0] == a) - p4 = l2.pt[1]; - else - p4 = l2.pt[0]; - } else { - p1 = l1.pt[0]; - p2 = l1.pt[1]; - p3 = l2.pt[0]; - p4 = l2.pt[1]; - } - if (b != 0) { - p6 = b; - p7 = b; - if (l3.pt[0] == b) - p5 = l3.pt[1]; - else - p5 = l3.pt[0]; - - if (l4.pt[0] == b) - p8 = l4.pt[1]; - else - p8 = l4.pt[0]; - } else { - p5 = l3.pt[0]; - p6 = l3.pt[1]; - p7 = l4.pt[0]; - p8 = l4.pt[1]; - } - add_codx(CO_ACONG, p1, p2, p3, p4, p5, p6, p7, p8); - } - + /** + * Checks and adjusts the given angles structure based on the provided four lines. + * Modifies the angles type and associates new conditions if necessary. + * + * @param as the angles structure to check and adjust + * @param l1 the first line of the first angle pair + * @param l2 the second line of the first angle pair + * @param l3 the first line of the second angle pair + * @param l4 the second line of the second angle pair + */ final void ck_as(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { co_xy.nx = null; if (ln_para(l1, l2) && l3 != l4) { @@ -2338,6 +2911,12 @@ final void ck_as(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { co_xy.nx = null; } + /** + * Creates and returns a new condition object associated with the given angles structure. + * + * @param as the angles structure for which the condition is created + * @return the newly created condition object + */ final Cond add_acoxy(Angles as) { co_xy.nx = null; Cond c = add_coxy(CO_ACONG); @@ -2345,6 +2924,13 @@ final Cond add_acoxy(Angles as) { return c; } + /** + * Adjusts the specified angles structure based on the provided type flag. + * Iterates over existing angles objects and applies necessary adjustments. + * + * @param t the type flag indicating the adjustment mode + * @param as the angles structure to adjust + */ final void adj_as(int t, Angles as) { if (as == null) return; if (as.type == 0) return; @@ -2378,6 +2964,14 @@ else if (t == 0) { } } + /** + * Adjusts tangency relationships for the specified angles structure by comparing + * the tangency lines associated with its component lines using the given markers. + * + * @param m1 a marker or point identifier used for tangency adjustment + * @param m2 a marker or point identifier used for tangency adjustment + * @param as the angles structure whose tangency relationships are to be adjusted + */ public void adj_as_tn(int m1, int m2, Angles as) { if (m1 == 0 || m2 == 0) return; @@ -2393,6 +2987,13 @@ public void adj_as_tn(int m1, int m2, Angles as) { } + /** + * Searches and adjusts transversal angles based on the provided t-lines. + * + * @param tn1 the first transversal line + * @param tn2 the second transversal line + * @param as the angle set to update + */ public void search_as_tn1(TLine tn1, TLine tn2, Angles as) { if (tn1 == null || tn2 == null) return; @@ -2402,31 +3003,16 @@ public void search_as_tn1(TLine tn1, TLine tn2, Angles as) { adj_as_plus(tn2.l1, tn2.l2, tn1.l2, tn1.l1, as); } - final void adj_bisector(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { - LLine ln1, ln2, ln3, ln4, ln5, ln6; - if (l2 == l3) { - ln1 = l1; - ln2 = l2; - ln3 = l4; - } else if (l1 == l4) { - ln1 = l2; - ln2 = l1; - ln3 = l3; - } else - return; - if (r1.l2 == r1.l3) { - ln1 = r1.l1; - ln2 = r1.l2; - ln3 = r1.l4; - } else if (l1 == l4) { - ln1 = r1.l2; - ln2 = r1.l1; - ln3 = r1.l3; - } else - return; - - } - + /** + * Adjusts angles based on the line configuration in the given angle sets. + * + * @param l1 the first line in the configuration + * @param l2 the second line in the configuration + * @param l3 the third line in the configuration + * @param l4 the fourth line in the configuration + * @param r1 the primary angle set + * @param r2 the secondary angle set + */ final void adj_as1(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { Cond co; LLine t1, t2; @@ -2477,6 +3063,16 @@ else if (isPFull()) { } } + /** + * Adjusts angles using an alternative line pairing. + * + * @param l1 the first line in the configuration + * @param l2 the second line in the configuration + * @param l3 the third line in the configuration + * @param l4 the fourth line in the configuration + * @param r1 the primary angle set + * @param r2 the secondary angle set + */ final void adj_as2(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { Cond co; LLine t1, t2; @@ -2503,6 +3099,15 @@ final void adj_as2(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) } } + /** + * Attempts to combine line segments and adjust angles based on additional angle information. + * + * @param l1 the first line in the initial pair + * @param l2 the second line in the initial pair + * @param l3 the first line in the alternate pair + * @param l4 the second line in the alternate pair + * @param r1 the reference angle set + */ final void adj_as_plus(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1) { @@ -2599,22 +3204,46 @@ final void adj_as_plus(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1) { } + /** + * Retrieves a line that matches the endpoints of two given line pairs. + * + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @return the matching line if found; otherwise, null + */ public LLine get_82l0(LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == l4) return l1; if (l2 == l3) return l2; return null; } - public LLine get_82l1(LLine l1, LLine l2, LLine l) { - if (l1 == l) return l2; - if (l2 == l) return l1; - return null; - } - + /** + * Creates an angle point using the intersection of line segments. + * + * @param lm lemma identifier + * @param a first endpoint of the first line + * @param b second endpoint of the first line + * @param c additional parameter for the first line + * @param p first endpoint of the second line + * @param q second endpoint of the second line + * @param r additional parameter for the second line + */ final void add_ea_pt(int lm, int a, int b, int c, int p, int q, int r) { add_ea_ln(lm, fadd_ln(a, b), fadd_ln(b, c), fadd_ln(p, q), fadd_ln(q, r)); } + /** + * Adds an angle by combining four lines if the configuration is valid. + * + * @param lm lemma identifier + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @return the constructed angle set or null if invalid + */ final Angles add_ea_ln(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (d_base == 1) return null; @@ -2626,7 +3255,18 @@ final Angles add_ea_ln(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return as; } - + /** + * Determines if a set of points belongs to the specified similar triangle configuration. + * + * @param p1 first point of the first triangle + * @param p2 second point of the first triangle + * @param p3 third point of the first triangle + * @param p first point of the second triangle + * @param q second point of the second triangle + * @param r third point of the second triangle + * @param st the similar triangle to compare against + * @return true if the points match the triangle configuration; false otherwise + */ boolean on_st(int p1, int p2, int p3, int p, int q, int r, SimTri st) { //?????????????????? for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) @@ -2641,7 +3281,18 @@ boolean on_st(int p1, int p2, int p3, int p, int q, int r, SimTri st) { return (false); } - + /** + * Adds a pair of triangles based on provided vertex configurations. + * + * @param lm lemma identifier + * @param dr direction flag + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + */ final void add_stri(int lm, int dr, int a, int b, int c, int p, int q, int r) { if (!valid(lm)) return; @@ -2699,7 +3350,14 @@ final void add_stri(int lm, int dr, int a, int b, int c, int p, int q, int r) { return; } - + /** + * Checks if a line defined by two points is part of the provided congruency segment. + * + * @param p1 the first point of the line + * @param p2 the second point of the line + * @param cg the congruency segment to check + * @return true if the line is on the congruency segment; false otherwise + */ final boolean on_cg(int p1, int p2, CongSeg cg) { int i; if (p2 < p1) { @@ -2711,6 +3369,16 @@ final boolean on_cg(int p1, int p2, CongSeg cg) { return (false); } + /** + * Checks if the lines defined by two pairs of points form the provided congruency segment. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @param cg the congruency segment to check + * @return true if the points form the congruency segment; false otherwise + */ final boolean on_cg(int p1, int p2, int p3, int p4, CongSeg cg) { int i; if (p2 < p1) { @@ -2728,22 +3396,12 @@ final boolean on_cg(int p1, int p2, int p3, int p4, CongSeg cg) { return (false); } - - final CongSeg fd_cg2(int p1, int p2, CongSeg cg) { - CongSeg cg1 = all_cg.nx; - boolean f = false; - while (cg1 != null) { - if (cg1.type != 0) { - if (cg1 == cg) - f = true; - else if ((f || cg == null) && on_cg(p1, p2, cg1)) return (cg1); - } - cg1 = cg1.nx; - } - return (null); - } - - + /** + * Adjusts congruency segments by comparing the specified congruency with others. + * + * @param c flag indicating which congruency list to traverse + * @param cg the reference congruency segment + */ final void adj_cg(int c, CongSeg cg) { CongSeg cg1 = (c == 1) ? all_cg.nx : all_rg.nx; @@ -2783,7 +3441,23 @@ final void adj_cg(int c, CongSeg cg) { } } - + /** + * Searches for and creates a congruency by comparing endpoints and ratios of two segments. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c third endpoint of the first segment + * @param d fourth endpoint of the first segment + * @param a1 first endpoint of the second segment + * @param b1 second endpoint of the second segment + * @param c1 third endpoint of the second segment + * @param d1 fourth endpoint of the second segment + * @param k1 first ratio component of the first segment + * @param k2 second ratio component of the first segment + * @param k3 first ratio component of the second segment + * @param k4 second ratio component of the second segment + * @return true if a valid congruency is found or established; false otherwise + */ final boolean search_cg3(int a, int b, int c, int d, int a1, int b1, int c1, int d1, int k1, int k2, int k3, int k4) { int t1, t2, t3, t4, m1, m2; @@ -2836,13 +3510,18 @@ final boolean search_cg3(int a, int b, int c, int d, int a1, int b1, int c1, int return true; } - final int get_coll43(int a, int b, int c, int d) { - if (a == b || a == c || a == d) return a; - if (b == c || b == d) return b; - if (c == d) return c; - return 0; - } - + /** + * Adds a congruency segment based on two lines and their ratio components. + * + * @param lm lemma identifier + * @param l_no line number flag + * @param a the first point of the first line + * @param b the second point of the first line + * @param p the first point of the second line + * @param q the second point of the second line + * @param t1 first ratio component + * @param t2 second ratio component + */ final void add_cong(int lm, int l_no, int a, int b, int p, int q, int t1, int t2) { CongSeg cg; if (!valid(lm)) return; @@ -2925,6 +3604,16 @@ final void add_cong(int lm, int l_no, int a, int b, int p, int q, int t1, int t2 last_nd.u.cg = cg; } + /** + * Adds a congruency segment for two lines without specifying ratio components. + * + * @param lm lemma identifier + * @param l_no line number flag + * @param a the first point of the first line + * @param b the second point of the first line + * @param p the first point of the second line + * @param q the second point of the second line + */ final void add_cong(int lm, int l_no, int a, int b, int p, int q) { CongSeg cg; if (a == b || p == q) return; @@ -2981,6 +3670,19 @@ final void add_cong(int lm, int l_no, int a, int b, int p, int q) { last_nd.u.cg = cg; } + /** + * Adds a congruence segment based on the provided point indices and lemma. + * + * @param lm the lemma identifier + * @param p1 first point index of the first segment + * @param p2 second point index of the first segment + * @param p3 first point index of the second segment + * @param p4 second point index of the second segment + * @param a first point index of the first congruence pair + * @param b second point index of the first congruence pair + * @param p first point index of the second congruence pair + * @param q second point index of the second congruence pair + */ final void add_cong1(int lm, int p1, int p2, int p3, int p4, int a, int b, int p, int q) { CongSeg cg; Cond co; @@ -3050,6 +3752,15 @@ final void add_cong1(int lm, int p1, int p2, int p3, int p4, int a, int b, int p last_nd.u.cg = cg; } + /** + * Determines the index for a ratio segment based on point congruence. + * + * @param a first point index + * @param b second point index + * @param ra the ratio segment reference + * @param m mode indicator affecting the returned index + * @return an integer representing the determined index + */ int ind_ra(int a, int b, RatioSeg ra, int m) { int c = 0; if (xcong(a, b, ra.r[1], ra.r[2])) { @@ -3064,6 +3775,21 @@ int ind_ra(int a, int b, RatioSeg ra, int m) { return (c); } + /** + * Adds a ratio segment if the ratio parameters pass the validity checks. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param p first point index of the third ratio pair + * @param q second point index of the third ratio pair + * @param r first point index of the fourth ratio pair + * @param s second point index of the fourth ratio pair + * @return the created RatioSeg object, or null if the check fails + */ RatioSeg add_ra(int lm, int o, int a, int b, int c, int d, int p, int q, int r, int s) { RatioSeg ra; Cond co; @@ -3124,6 +3850,11 @@ RatioSeg add_ra(int lm, int o, int a, int b, int c, int d, int p, int q, int r, return (ra); } + /** + * Adjusts the ratio segments by comparing with all existing segments and reconciling differences. + * + * @param ra the starting RatioSeg to adjust + */ final void adj_ra(RatioSeg ra) { RatioSeg r1; int i1, i2, i3, i4; @@ -3170,6 +3901,18 @@ final void adj_ra(RatioSeg ra) { test_ra = last_ra; } + /** + * Adjusts a ratio segment relation using the specified ratio parameters and indices. + * + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param i1 indicator for the first ratio selection in r1 + * @param i2 indicator for the second ratio selection in r1 + * @param r1 the ratio segment to be adjusted + * @param r2 a related ratio segment used for adjustment context + */ final void adj_ra1(int a, int b, int c, int d, int i1, int i2, RatioSeg r1, RatioSeg r2) { int p, q, r, s; Cond co; @@ -3233,6 +3976,17 @@ final void adj_ra1(int a, int b, int c, int d, int i1, int i2, RatioSeg r1, Rati } } + /** + * Adjusts a ratio segment relation based on a single indicator and updates connection information. + * + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param i1 indicator dictating the selection of ratio components in r1 + * @param r1 the ratio segment to be adjusted + * @param r2 a related ratio segment for context + */ final void adj_ra2(int a, int b, int c, int d, int i1, RatioSeg r1, RatioSeg r2) { int p, q, r, s; Cond co; @@ -3265,11 +4019,35 @@ final void adj_ra2(int a, int b, int c, int d, int i1, RatioSeg r1, RatioSeg r2) } } + /** + * Adds a ratio segment if no equivalent ratio exists. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param p first point index of the third ratio pair + * @param q second point index of the third ratio pair + * @param r first point index of the fourth ratio pair + * @param s second point index of the fourth ratio pair + */ final void add_ratio(int lm, int o, int a, int b, int c, int d, int p, int q, int r, int s) { if (xeq_ratio(a, b, c, d, p, q, r, s)) return; add_ra(lm, o, a, b, c, d, p, q, r, s); } + /** + * Adds a ratio segment using only four points by inferring the remaining ratio components. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index + * @param b second point index + * @param c third point index + * @param d fourth point index + */ final void add_ratioo(int lm, int o, int a, int b, int c, int d) { if (!xeq_ratio(o, a, o, c, o, b, o, d)) add_ra(lm, 1, o, a, o, c, o, b, o, d); @@ -3287,16 +4065,22 @@ final void add_ratioo(int lm, int o, int a, int b, int c, int d) { add_ra(lm, 1, o, c, c, a, o, d, d, b); } + /** + * Checks if two points are equal. + * + * @param p1 the first point index + * @param p2 the second point index + * @return true if points are equal, false otherwise + */ boolean meq_pt(int p1, int p2) { return p1 == p2; } - final void free_dbase() { - init_dbase(); - } - -//////////////////////////////////////////////////////////// - + /** + * Processes and validates all conclusions. + * + * @return true if all conclusions are processed successfully + */ public boolean sbase() { for (int i = 1; i <= cns_no; i++) { if (!isConclusion(i)) @@ -3306,6 +4090,11 @@ public boolean sbase() { return true; } + /** + * Sets the example context for the theorem by initializing various parameters. + * + * @param tm the geometric term containing the example information + */ final public void setExample(GTerm tm) { gt = tm; cons_no = tm.getCons_no(); @@ -3316,7 +4105,11 @@ final public void setExample(GTerm tm) { pts_no = tm.getPointsNum(); } - + /** + * Sets the conclusion condition. + * + * @param tco the condition object containing conclusion data + */ final public void setConc(Cond tco) { if (tco == null) return; @@ -3342,24 +4135,25 @@ final public void setConc(Cond tco) { } } - - public void add_nln(int[] p, int n) { - for (int i = 0; i < n; i++) - fadd_ln(p[i * 2], p[i * 2 + 1]); - } - - + /** + * Processes the individual conclusion for the specified index. + * + * @param ptn the conclusion index + * @return true after processing the conclusion + */ public boolean do_i_cons(int ptn) { do_pd(ptn, allcns[ptn].type, allcns[ptn].ps); return true; } - public boolean do_i_ln(int ptn) { - do_pdln(ptn, allcns[ptn].type, allcns[ptn].ps); - return true; - } - - + /** + * Processes the predicate for a given conclusion based on its type and parameters. + * + * @param ptn the conclusion index + * @param t the type of predicate + * @param p an array of parameters associated with the predicate + * @return true if the predicate is processed successfully; false otherwise + */ public boolean do_pd(int ptn, int t, int[] p) { if (t == 0) return true; switch (t) { @@ -3575,7 +4369,11 @@ public boolean do_pd(int ptn, int t, int[] p) { } - + /** + * Adds a circle defined by the provided parameters. + * + * @param p an array containing circle parameters; p[2] must be non-zero + */ public void add_cir_n(int p[]) { if (p[2] == 0) return; @@ -3592,122 +4390,42 @@ public void add_cir_n(int p[]) { } } + /** + * Adds a line angle ratio by drawing lines between the provided endpoints and establishing + * squared ratio relationships. + * + * @param p1 the first point index + * @param p2 the second point index + * @param p3 the third point index + * @param p4 the fourth point index + * @param t1 the first ratio value (to be squared) + * @param t2 the second ratio value (to be squared) + */ public void add_laratio(int p1, int p2, int p3, int p4, int t1, int t2) { add_line1(0, p1, p2, p3); add_line1(0, p1, p2, p4); add_cong(0, 0, p1, p2, p3, p4, t1 * t1, t2 * t2); } + /** + * Adds a congruence relation between segments based on the provided endpoints and squared ratio values. + * + * @param p1 the first point index of the first segment + * @param p2 the second point index of the first segment + * @param p3 the first point index of the second segment + * @param p4 the second point index of the second segment + * @param t1 the first ratio value (to be squared) + * @param t2 the second ratio value (to be squared) + */ public void add_ratio(int p1, int p2, int p3, int p4, int t1, int t2) { add_cong(0, 0, p1, p2, p3, p4, t1 * t1, t2 * t2); } - public boolean do_pdln(int ptn, int t, int[] p) { - if (t == 0) return true; - switch (t) { - case C_POINT: - break; - case C_CONSTANT: - break; - case C_MIDPOINT: - break; - case C_FOOT: // foot - fadd_ln(p[0], p[1]); - break; - case C_O_C: - break; - case C_O_L: - fadd_ln(p[1], p[2]); - break; - case C_O_T: - add_nln(p, 2); - break; - case C_O_P: - add_nln(p, 2); - break; - case C_EQANGLE: - case C_O_A: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - fadd_ln(p[3], p[4]); - fadd_ln(p[4], p[5]); - break; - case C_O_R: - break; - case C_O_B: - break; - case C_NSQUARE: - break; - case C_PSQUARE: - break; - case C_I_CC: - break; - case C_CIRCUM: - break; - case C_ORTH: - fadd_ln(p[0], p[1]); - fadd_ln(p[0], p[2]); - fadd_ln(p[0], p[3]); - fadd_ln(p[1], p[2]); - fadd_ln(p[1], p[3]); - fadd_ln(p[2], p[3]); - break; - case C_PETRIANGLE: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - fadd_ln(p[2], p[3]); - break; - case C_NETRIANGLE: - break; - case C_REF: //Point wrpt POINT - fadd_ln(p[1], p[2]); - break; - case C_SYM: // Point wrpt LINE - add_nln(p, 2); - break; - case C_ICENT: - break; - case C_PRATIO: - add_nln(p, 2); - break; - case C_TRATIO: - add_nln(p, 2); - break; - case C_EQDISTANCE: - add_nln(p, 2); - break; - case C_SANGLE: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - break; - case C_LRATIO: - break; - case C_NRATIO: - break; - case C_LINE: - fadd_ln(p[0], p[1]); - break; - case C_TRIANGLE: - case C_ISO_TRI: - case C_R_TRI: - case C_EQ_TRI: - case C_QUADRANGLE: - case C_PENTAGON: - case C_POLYGON: - case C_TRAPEZOID: - case C_R_TRAPEZOID: - case C_PARALLELOGRAM: - case C_LOZENGE: - case C_RECTANGLE: - case C_SQUARE: - add_pg_ln(p); - break; - default: - return false; - } - return true; - } - + /** + * Adds a polygon line by connecting the series of points in a loop. + * + * @param p an array of point indices representing the polygon vertices; a zero value indicates termination + */ public void add_pg_ln(int[] p) { int t = p[0]; if (t == 0) return; @@ -3719,13 +4437,22 @@ public void add_pg_ln(int[] p) { fadd_ln(p[0], t); } - + /** + * Adds a trapezoid by drawing the primary lines for its shape. + * + * @param p an array of 4 vertex indices representing the trapezoid + */ public void add_r_trapezoid(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_tline(0, p[0], p[1], p[0], p[3]); add_tline(0, p[0], p[3], p[2], p[3]); } + /** + * Adds a parallelogram by drawing its outline, congruencies, and structural elements. + * + * @param p an array of 4 vertex indices representing the parallelogram + */ public void add_parallelogram(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[1], p[2]); @@ -3736,6 +4463,11 @@ public void add_parallelogram(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a lozenge by drawing its lines and congruencies. + * + * @param p an array of 4 vertex indices representing the lozenge + */ public void add_lozenge(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[1], p[2]); @@ -3749,6 +4481,11 @@ public void add_lozenge(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a rectangle by drawing its outline, tangents, congruencies, and structural elements. + * + * @param p an array of 4 vertex indices representing the rectangle + */ public void add_rectangle(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[2], p[1]); @@ -3763,6 +4500,11 @@ public void add_rectangle(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a square by drawing its lines, tangents, congruencies, and angle structures. + * + * @param p an array of 4 vertex indices representing the square + */ public void add_square(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[2], p[1]); @@ -3807,6 +4549,12 @@ public void add_square(int[] p) { } + /** + * Adds an auxiliary point based on the provided ProPoint type. + * + * @param pt the ProPoint object containing point and type information + * @return true if the auxiliary point is added successfully; false otherwise + */ public boolean add_auxpt(ProPoint pt) { int[] p = pt.ps; @@ -3849,6 +4597,14 @@ public boolean add_auxpt(ProPoint pt) { return true; } + /** + * Performs a predicate operation based on the given type. + * + * @param p1 the array of points and parameters (first element is used as predicate target) + * @param mk the predicate type code + * @param ptn the predicate target (overwritten by the first element of p1) + * @return true if the predicate action is executed successfully, false otherwise + */ public boolean do_pred2(int[] p1, int mk, int ptn) { ptn = p1[0]; int[] p = new int[p1.length]; @@ -4021,60 +4777,12 @@ public boolean do_pred2(int[] p1, int mk, int ptn) { return true; } - final public void add_square(ProPoint p) { - - - int i = 0; - for (; allpts[i + 1] != p; i++) ; - ProPoint p1 = allpts[i]; - - if (!(p1.ps[1] == p.ps[1] && p1.ps[2] == p.ps[2] || p1.ps[1] == p.ps[2] && p1.ps[2] == p.ps[1])) return; - - { - int a = p1.ps[0]; - int b = p1.ps[1]; - int c = p1.ps[2]; - int d = p.ps[0]; - add_at(0, a, b, c, A_90); - add_at(0, b, c, d, A_90); - add_at(0, c, d, a, A_90); - add_at(0, d, a, b, A_90); - add_at(0, a, b, d, A_45); - add_at(0, a, d, b, A_45); - add_at(0, a, c, d, A_45); - add_at(0, a, c, b, A_45); - add_at(0, c, b, d, A_45); - add_at(0, c, d, b, A_45); - add_at(0, c, a, b, A_45); - add_at(0, c, a, d, A_45); - } - - - if (p.type == C_PSQUARE && p1.type == C_NSQUARE || p.type == C_NSQUARE && p1.type == C_PSQUARE) { - if (p1.ps[1] == p.ps[2] && p1.ps[2] == p.ps[1]) { - int a = p1.ps[0]; - int b = p1.ps[1]; - int c = p1.ps[2]; - int d = p.ps[0]; - add_pline(0, a, b, c, d); - add_pline(0, a, d, b, c); - - add_tline(0, a, b, b, c); - add_tline(0, b, c, c, d); - add_tline(0, c, d, d, a); - add_tline(0, a, b, a, d); - - add_cong(0, 0, a, b, b, c); - add_cong(0, 0, a, b, c, d); - add_cong(0, 0, a, b, a, d); - add_cong(0, 0, b, c, c, d); - add_cong(0, 0, b, c, a, d); - add_cong(0, 0, c, d, a, d); - } - } - - } - + /** + * Adds an equilateral triangle using the specified points. + * + * @param ptn the identifier or index used for the triangle + * @param ps an array containing the triangle's vertex points + */ final public void add_e_triangle(int ptn, int[] ps) { int a = ps[0]; int b = ps[1]; @@ -4116,6 +4824,16 @@ final public void add_e_triangle(int ptn, int[] ps) { } } + /** + * Checks whether a triangle with vertices a, b, and c exists in the given STris, + * considering all permutations of the vertices. + * + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to search + * @return the index of the matching triangle if found; otherwise, -1 + */ final public int on_sts1(int a, int b, int c, STris st) { int p, q, r; for (int i = 0; i <= st.no; i++) { @@ -4134,6 +4852,15 @@ final public int on_sts1(int a, int b, int c, STris st) { return -1; } + /** + * Checks for the existence of a triangle with vertices a, b, and c, in the given order, within a STris. + * + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to search + * @return the index of the triangle if it exists; otherwise, -1 + */ final public int on_sts(int a, int b, int c, STris st) { int p, q, r; for (int i = 0; i <= st.no; i++) { @@ -4147,6 +4874,15 @@ final public int on_sts(int a, int b, int c, STris st) { return -1; } + /** + * Adds a triangle with vertices a, b, and c to the specified STris if it does not already exist. + * + * @param d a multiplier or descriptor value for the triangle + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to which the triangle will be added + */ final public void add_to_sts(int d, int a, int b, int c, STris st) { if (on_sts1(a, b, c, st) >= 0) return; @@ -4158,7 +4894,13 @@ final public void add_to_sts(int d, int a, int b, int c, STris st) { st.p3[n] = c; } - + /** + * Merges triangle data from the secondary STris into the primary one, based on a specified index. + * + * @param s the primary STris instance + * @param s1 the secondary STris instance to merge from + * @param t the index within the secondary STris used for merging + */ final public void cb_sts(STris s, STris s1, int t) { s1.type = 0; @@ -4198,6 +4940,12 @@ final public void cb_sts(STris s, STris s1, int t) { } + /** + * Attempts to add a SimTri to an existing STris structure. + * + * @param t the SimTri object representing the triangle to be added + * @return true if the list was updated successfully, false otherwise + */ final public boolean add_sts1(SimTri t) { STris st = null; @@ -4264,6 +5012,11 @@ final public boolean add_sts1(SimTri t) { return true; } + /** + * Adds a SimTri object to the appropriate STris structure or creates a new STris if necessary. + * + * @param st the SimTri object representing the triangle to add + */ final public void add_sts(SimTri st) { if (add_sts1(st)) return; @@ -4292,6 +5045,9 @@ final public void add_sts(SimTri st) { return; } + /** + * Collects and organizes triangles from all SimTri objects into STris structures. + */ public void collect_sts() { SimTri st = all_st.nx; tri_type = 0; @@ -4310,13 +5066,25 @@ public void collect_sts() { } } - /////////////////////////////////////////////////////////////////////// + /** + * Adds a connection between two points into the specified CSegs. + * + * @param p1 the first point + * @param p2 the second point + * @param cg the CSegs instance where the connection is added + */ public void add_to_cg(int p1, int p2, CSegs cg) { cg.no++; cg.p1[cg.no] = p1; cg.p2[cg.no] = p2; } + /** + * Merges connections from one CSegs instance into another. + * + * @param cg the primary CSegs instance + * @param cg1 the secondary CSegs instance to merge from + */ public void cb_cgs(CSegs cg, CSegs cg1) { cg1.type = 0; for (int i = 0; i <= cg1.no; i++) { @@ -4325,12 +5093,28 @@ public void cb_cgs(CSegs cg, CSegs cg1) { } } + /** + * Checks whether a connection between two points exists within the given CSegs. + * + * @param p1 the first point + * @param p2 the second point + * @param cgs the CSegs instance to check + * @return true if the connection exists, false otherwise + */ public boolean on_cgs(int p1, int p2, CSegs cgs) { for (int i = 0; i <= cgs.no; i++) if (p1 == cgs.p1[i] & p2 == cgs.p2[i]) return true; return false; } + /** + * Adds a connection between two pairs of points, merging with existing connections if applicable. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + */ public void add_cgs(int p1, int p2, int p3, int p4) { CSegs cg = all_cgs.nx; boolean t1, t2; @@ -4385,8 +5169,15 @@ else if (p3 == cg.p1[i] && p4 == cg.p2[i]) } - - ///////////////////////////////////// + /** + * Finds a PLine object that contains both line segments defined by the given points. + * + * @param p the first point of the first line segment + * @param q the second point of the first line segment + * @param r the first point of the second line segment + * @param s the second point of the second line segment + * @return the matching PLine if found; otherwise, null + */ final PLine fo_pn1(int p, int q, int r, int s) { PLine pn = all_pn.nx; boolean r1, r2; @@ -4404,6 +5195,17 @@ final PLine fo_pn1(int p, int q, int r, int s) { } + /** + * Finds a TLine object that matches the given line segments. + * + * If any parameter is zero, this method returns null. + * + * @param p1 the first point of the first line segment + * @param p2 the second point of the first line segment + * @param p3 the first point of the second line segment + * @param p4 the second point of the second line segment + * @return the matching TLine if found; otherwise, null + */ final TLine fo_tn1(int p1, int p2, int p3, int p4) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0) return null; @@ -4417,6 +5219,22 @@ final TLine fo_tn1(int p1, int p2, int p3, int p4) { return tn; } + /** + * Finds an Angles object matching the given configuration of lines. + * + * This method checks various combinations of lines in the Angles object using on_ln. + * Additional checks are applied when isPFull() returns true. + * + * @param a the first point for the first line + * @param b the second point for the first line + * @param c the first point for the second line + * @param d the second point for the second line + * @param p the first point for the third line + * @param q the second point for the third line + * @param r the first point for the fourth line + * @param s the second point for the fourth line + * @return the matching Angles object if found; otherwise, null + */ final Angles fo_as1(int a, int b, int c, int d, int p, int q, int r, int s) { Angles as = all_as.nx; while (as != null) { @@ -4436,6 +5254,16 @@ final Angles fo_as1(int a, int b, int c, int d, int p, int q, int r, int s) { return null; } + /** + * Determines whether the given LLine contains exactly the two specified points. + * + * This method counts the occurrences of the points in the LLine. + * + * @param p the first point + * @param q the second point + * @param ln the LLine to check + * @return true if the line contains both points exactly; otherwise, false + */ boolean on_ln(int p, int q, LLine ln) { int i, n; @@ -4447,23 +5275,15 @@ boolean on_ln(int p, int q, LLine ln) { return (n == 2); } - LLine fd_ln1(int p1, int p2, LLine lnx) { - LLine ln = all_ln.nx; - - while (ln != null) { - if (lnx != null && ln != lnx) - ln = ln.nx; - else if (lnx != null && ln == lnx) { - ln = ln.nx; - lnx = null; - } else if (on_ln(p1, ln) && on_ln(p2, ln)) - break; - else - ln = ln.nx; - } - return (ln); - } - + /** + * Searches for an LLine that is a super-line of the given line and contains the specified additional point. + * + * The method expects the found LLine to match the required point count. + * + * @param ln the base LLine to be contained + * @param p the additional point to be present in the super-line + * @return the matching LLine if found; otherwise, null + */ public LLine fd_ln_lp(LLine ln, int p) { // a line contian ln, and p , no others. int n = 0; if (on_ln(p, ln)) @@ -4479,6 +5299,20 @@ public LLine fd_ln_lp(LLine ln, int p) { // a line contian ln, and p , no other return null; } + /** + * Checks whether a circle defined by the given set of points exists. + * + * This method initializes test parameters using the provided points and verifies the existence + * of a corresponding circle. + * + * @param o a parameter for the circle (e.g. origin) + * @param a the first point + * @param b the second point + * @param c the third point + * @param d the fourth point + * @param e the fifth point + * @return true if the circle exists; otherwise, false + */ final public boolean xcir_n(int o, int a, int b, int c, int d, int e) { test_c.no = -1; test_c.o = o; @@ -4493,6 +5327,14 @@ final public boolean xcir_n(int o, int a, int b, int c, int d, int e) { return false; } + /** + * Adjusts the specified ACir object based on sub-circle or overlapping conditions. + * + * This method iterates through related circles and updates their types and associated properties + * when sub-circle relationships are detected. + * + * @param cr the ACir object to adjust + */ final void adj_cir1(ACir cr) { ACir cr1, cr2, cr3; Cond co; @@ -4531,6 +5373,13 @@ final void adj_cir1(ACir cr) { } } + /** + * Searches for an LLine that exactly contains the two specified points and has exactly one segment. + * + * @param p1 the first point + * @param p2 the second point + * @return the matching LLine if found; otherwise, null + */ public LLine fd_ln1(int p1, int p2) { LLine ln = all_ln.nx; while (ln != null) { @@ -4542,7 +5391,18 @@ public LLine fd_ln1(int p1, int p2) { return ln; } - + /** + * Creates and adds a PLine connecting two line segments defined by the given points. + * + * This method validates the parameters, checks for necessary conditions such as non-collinearity, + * updates or creates required LLine objects, and constructs a new PLine based on the provided points. + * + * @param lm the lemma or identifier for the PLine + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ final void add_pline1(int lm, int p1, int p2, int p3, int p4) { PLine pn; if (!valid(lm)) return; @@ -4618,6 +5478,14 @@ final void add_pline1(int lm, int p1, int p2, int p3, int p4) { } + /** + * Adjusts the configuration of the specified PLine based on its constituent lines. + * + * This method refines the composition of the PLine by evaluating its associated LLine segments, + * updating their states, and readjusting the PLine properties if necessary. + * + * @param pn the PLine to adjust + */ final void adj_pn(PLine pn) { PLine pn1, pn2, pn3; Cond co; @@ -4698,58 +5566,16 @@ final void adj_pn(PLine pn) { } } - final void add_as_codb(LLine l1, LLine l2, LLine l3, LLine l4) { - int p1, p2, p3, p4, p5, p6, p7, p8; - int a = inter_ll(l1, l2); - int b = inter_ll(l3, l4); - - if (a != 0) { - p2 = a; - p3 = a; - if (l1.pt[0] == a) - p1 = l1.pt[1]; - else - p1 = l1.pt[0]; - - if (l2.pt[0] == a) - p4 = l2.pt[1]; - else - p4 = l2.pt[0]; - } else { - p1 = l1.pt[0]; - p2 = l1.pt[1]; - p3 = l2.pt[0]; - p4 = l2.pt[1]; - } - if (b != 0) { - p6 = b; - p7 = b; - if (l3.pt[0] == b) - p5 = l3.pt[1]; - else - p5 = l3.pt[0]; - - if (l4.pt[0] == b) - p8 = l4.pt[1]; - else - p8 = l4.pt[0]; - } else { - p5 = l3.pt[0]; - p6 = l3.pt[1]; - p7 = l4.pt[0]; - p8 = l4.pt[1]; - } - add_codb(CO_ACONG, p1, p2, p3, p4, p5, p6, p7, p8); - } - - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - // traditional prove - - + /** + * Creates an Angles object using the four provided lines. + * + * @param lm the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed Angles object, or null if the input is invalid + */ Angles add_as_t(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == l2 && l3 == l4) return null; if (!valid(lm)) return null; @@ -4812,6 +5638,17 @@ Angles add_as_t(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return (as); } + /** + * Checks whether the given sets of three points satisfy the congruence conditions. + * + * @param a first point of the first segment + * @param b second point of the first segment + * @param c third point of the first segment + * @param p first point of the second segment + * @param q second point of the second segment + * @param r third point of the second segment + * @return true if the conditions for congruence hold; false otherwise + */ final boolean xacongt(int a, int b, int c, int p, int q, int r) { LLine l1, l2, l3, l4; l1 = fd_ln(a, b); @@ -4826,6 +5663,19 @@ final boolean xacongt(int a, int b, int c, int p, int q, int r) { return (this.fo_as1_t(a, b, b, c, p, q, q, r) != null); } + /** + * Finds and returns an Angles object that matches the specified endpoints from four lines. + * + * @param a the first endpoint of the first line + * @param b the second endpoint of the first line + * @param c the first endpoint of the second line + * @param d the second endpoint of the second line + * @param p the first endpoint of the third line + * @param q the second endpoint of the third line + * @param r the first endpoint of the fourth line + * @param s the second endpoint of the fourth line + * @return the matching Angles object, or null if none is found + */ final Angles fo_as1_t(int a, int b, int c, int d, int p, int q, int r, int s) { Angles as = all_as.nx; @@ -4839,17 +5689,15 @@ final Angles fo_as1_t(int a, int b, int c, int d, int p, int q, int r, int s) { return null; } - Angles fd_as_t(LLine l1, LLine l2) { - Angles as; - for (as = all_as.nx; as != null; as = as.nx) { - if ( - (l1 == as.l1 && l2 == as.l2) || (l1 == as.l2 && l2 == as.l1) || - (l1 == as.l3 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l3)) - return (as); - } - return (null); - } - + /** + * Retrieves an Angles object using four specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the matching Angles object, or null if no match is found + */ final Angles fo_las_t(LLine l1, LLine l2, LLine l3, LLine l4) { Angles as = all_as.nx; while (as != null) { @@ -4862,6 +5710,16 @@ final Angles fo_las_t(LLine l1, LLine l2, LLine l3, LLine l4) { return (null); } + /** + * Adds an Angles object from the provided lines based on the project state. + * + * @param lm the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the added Angles object + */ public Angles add_as(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (isPFull()) return add_as0(lm, l1, l2, l3, l4); @@ -4869,6 +5727,17 @@ public Angles add_as(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return add_as_t(lm, l1, l2, l3, l4); } + /** + * Adds an inscribed angle point using the provided parameters. + * + * @param lm the lemma identifier + * @param a the first point on the first line + * @param b the second point on the first line + * @param c the third point on the first line + * @param p the first point on the second line + * @param q the second point on the second line + * @param r the third point on the second line + */ final void add_ea_pt_t(int lm, int a, int b, int c, int p, int q, int r) { // for inscrible angle. if (d_base == 1) return; @@ -4887,6 +5756,13 @@ final void add_ea_pt_t(int lm, int a, int b, int c, int p, int q, int r) { Angles as = add_as(lm, l1, l2, l3, l4); } + /** + * Adds a new line segment with endpoints a and b. + * + * @param a the first endpoint + * @param b the second endpoint + * @return the new or existing LLine instance, or null if the input is invalid + */ final LLine add_ln_t0(int a, int b) { if (a == 0 || b == 0) return null; @@ -4904,10 +5780,25 @@ final LLine add_ln_t0(int a, int b) { return ln; } + /** + * Fast-adds a line segment using the given endpoints. + * + * @param p1 the first endpoint + * @param p2 the second endpoint + * @return the added LLine object + */ LLine fadd_ln_t(int p1, int p2) { return add_ln_t0(p1, p2); } + /** + * Returns the anti midpoint from a line, excluding the specified endpoints. + * + * @param ln the line to search + * @param p one of the endpoints + * @param p1 the other endpoint + * @return the internal point on the line between p and p1, or 0 if not found + */ public int get_anti_pt(LLine ln, int p, int p1) { // p is imdpoint of x and p1 for (int i = 0; i <= ln.no; i++) { if (ln.pt[i] != p && ln.pt[i] != p1 && (x_inside(p, ln.pt[i], p1))) @@ -4916,7 +5807,13 @@ public int get_anti_pt(LLine ln, int p, int p1) { // p is imdpoint of x and p1 return 0; } - + /** + * Determines whether two lines are collinear. + * + * @param l1 the first line + * @param l2 the second line + * @return true if l1 and l2 are collinear; false otherwise + */ boolean xcoll_ln(LLine l1, LLine l2) { if (l1.type == 0 && l2.type == 0) { int r = 0; @@ -4932,31 +5829,47 @@ boolean xcoll_ln(LLine l1, LLine l2) { l2 = fd_lnl(l2); return l1 == l2; } - //////////////////////////////////////////////////////////////////// - //// for multipul prove. - - ////////////////////////////////////////////////////////////////////////////////// + /** + * Adds an angle (AngleT) by creating it from line segments corresponding to points a, b, and c. + * + * @param lemma the lemma identifier + * @param a the first point of the angle + * @param b the vertex point of the angle + * @param c the third point of the angle + * @param v the angle value + * @return the created AngleT object + */ public AngleT add_at(int lemma, int a, int b, int c, int v) { return add_at(lemma, fadd_ln_t(a, b), fadd_ln_t(b, c), v); } + /** + * Adds an angle (AngleT) by creating it using line segments looked up directly. + * + * @param lemma the lemma identifier + * @param a the first point of the angle + * @param b the vertex point of the angle + * @param c the third point of the angle + * @param v the angle value + * @return the created AngleT object + */ public AngleT add_at0(int lemma, int a, int b, int c, int v) { return add_at(lemma, fd_ln(a, b), fd_ln(b, c), v); } - - public AngleT new_at(int v, int p, LLine l1, LLine l2) { - AngleT at = new AngleT(); - at.v = v; - at.p = p; - at.l1 = l1; - at.l2 = l2; - return at; - } - + /** + * Creates and adds an AngleT instance with the given lemma, lines, and angle value. + * Returns the created AngleT if successful, or null otherwise. + * + * @param lemma the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param v the angle value + * @return the created AngleT instance or null + */ public AngleT add_at(int lemma, LLine l1, LLine l2, int v) { if (isPFull()) return null; if (!valid(R_AG_SPECIAL)) return null; @@ -5004,21 +5917,53 @@ else if (v <= -A_180) return at; } + /** + * Checks whether the angle formed by points a, b, and c is congruent to the specified angle value. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @param v the angle value to compare + * @return true if the angle is congruent; false otherwise + */ public boolean xatcong(int a, int b, int c, int v) { AngleT at = fo_at(a, b, c); return check_ll_dr(at.p, at.l1, at.l2, v); } + /** + * Determines if the angle formed by the two lines is congruent. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines form a congruent angle or are collinear; false otherwise + */ public boolean xatcong(LLine l1, LLine l2) { if (l1 == l2 || xcoll_ln(l1, l2)) return true; return fd_at(l1, l2) != null; } + /** + * Finds an existing AngleT instance based on three points, mapping these points to corresponding lines. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found AngleT instance, or null if none exists + */ public AngleT fd_at(int p1, int p2, int p3) { return fd_at(fd_ln(p1, p2), fd_ln(p2, p3)); } + /** + * Searches for the first AngleT instance that matches the line segments determined by the given points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found AngleT instance, or null if not found + */ public AngleT fo_at(int p1, int p2, int p3) { AngleT at = all_at.nx; while (at != null) { @@ -5028,6 +5973,13 @@ public AngleT fo_at(int p1, int p2, int p3) { return null; } + /** + * Finds an AngleT instance defined by the two specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the found AngleT instance, or null if it does not exist + */ public AngleT fd_at(LLine l1, LLine l2) { if (l1 == null || l2 == null) return null; @@ -5041,55 +5993,42 @@ public AngleT fd_at(LLine l1, LLine l2) { return null; } + /** + * Checks if the angle between the two lines at a specific point approximates the given angle measure. + * + * @param p the vertex point + * @param l1 the first line + * @param l2 the second line + * @param d the expected angle in degrees + * @return true if the measured angle is approximately equal to d degrees; false otherwise + */ public boolean check_ll_dr(int p, LLine l1, LLine l2, int d) { double r = getAngleValue(p, l1, l2); double x = Math.abs(r * A_180 / Math.PI - d); return x < ZERO || Math.abs(x - A_180) < ZERO || Math.abs(x + A_180) < ZERO; } - public int check_ll_type(int a, int b, int c, int d) { - double r = this.getAngleValue(a, b, c); - double x = Math.abs(r * A_180 / Math.PI - d); - if (x < ZERO) return 0; - if (Math.abs(x - A_180) < ZERO) return 1; - return -1; - } - + /** + * Checks if two angle measures are equal or supplementary. + * + * @param t1 the first angle measure + * @param t2 the second angle measure + * @return true if the angles are equal or differ by 180 degrees; false otherwise + */ public boolean check_at_eq(int t1, int t2) { return t1 == t2 || Math.abs(Math.abs(t1 - t2) - A_180) < ZERO; } - //////////////////////////////////////////////////// - // polygon - public void add_polygon(int t, int p[]) { - Polygon pg = new Polygon(t); - for (int i = 0; i < p.length && p[i] != 0; i++) - pg.p[i] = p[i]; - add_pg(pg); - } - - public Polygon fd_trix(int t, int a, int b, int c) { - Polygon pg = all_pg.nx; - while (pg != null) { - if (pg.qtype == t) { - if (pg.p[0] == a && (pg.p[1] == b && pg.p[2] == c || pg.p[1] == c && pg.p[2] == b)) return pg; - if (pg.p[0] == b && (pg.p[1] == a && pg.p[2] == c || pg.p[1] == c && pg.p[2] == a)) return pg; - if (pg.p[0] == c && (pg.p[1] == b && pg.p[2] == a || pg.p[1] == a && pg.p[2] == b)) return pg; - } - pg = pg.nx; - } - return null; - } - - public void add_pg(Polygon pg) { - last_pg.nx = pg; - last_pg = pg; - this.new_pr(pg.qtype); - last_nd.u.pg = pg; - } - - ///////////////////////////////////////////////////////////////////// - + /** + * Searches for an AngTn instance with the specified set of four lines. + * The search considers both direct and reverse orders. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the found AngTn instance, or null if not found + */ public AngTn fo_atn(LLine l1, LLine l2, LLine l3, LLine l4) { AngTn atn = all_atn.nx; while (atn != null) { @@ -5104,6 +6043,20 @@ public AngTn fo_atn(LLine l1, LLine l2, LLine l3, LLine l4) { return null; } + /** + * Searches for an AngTn instance matching the provided point-derived line parameters. + * Various order combinations are evaluated. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param a1 the first point of the third line + * @param b1 the second point of the third line + * @param c1 the first point of the fourth line + * @param d1 the second point of the fourth line + * @return the matching AngTn instance, or null if not found + */ public AngTn fo_atn(int a, int b, int c, int d, int a1, int b1, int c1, int d1) { AngTn atn = all_atn.nx; while (atn != null) { @@ -5120,13 +6073,11 @@ public AngTn fo_atn(int a, int b, int c, int d, int a1, int b1, int c1, int d1) return null; } - - public AngTn add_atn(int lemma, int a, int b, int c, int a1, int b1, int c1) { - if (fo_atn(a, b, b, c, a1, b1, b1, c1) != null) return null; - - return add_atn(lemma, fadd_ln_t(a, b), fadd_ln_t(b, c), fadd_ln_t(a1, b1), fadd_ln_t(b1, c1)); - } - + /** + * Adjusts the given angle tangent node if necessary. + * + * @param atn the AngTn node to adjust + */ public void adj_atn(AngTn atn) { if (atn.type == 0) return; LLine l1 = atn.ln1; @@ -5170,6 +6121,13 @@ public void adj_atn(AngTn atn) { atn.type = 0; } + /** + * Adjusts a specific line segment within the angle tangent node based on a change. + * + * @param ln1 the modified line + * @param ln2 an associated line for adjustment + * @param atn the AngTn node to update + */ final void ch_ln_atn(LLine ln1, LLine ln2, AngTn atn) { if (atn.type == 0) return; LLine l1 = atn.ln1; @@ -5209,6 +6167,16 @@ final void ch_ln_atn(LLine ln1, LLine ln2, AngTn atn) { atn.type = 0; } + /** + * Adds a new angle tangent node using four line objects. + * + * @param lemma the lemma identifier + * @param l1 the first line in the angle configuration + * @param l2 the second line in the angle configuration + * @param l3 the third line in the angle configuration + * @param l4 the fourth line in the angle configuration + * @return the new AngTn object, or null if creation fails + */ public AngTn add_atn(int lemma, LLine l1, LLine l2, LLine l3, LLine l4) { if (isPFull()) return null; if (!valid(R_AG_ATN)) return null; @@ -5275,6 +6243,17 @@ public AngTn add_atn(int lemma, LLine l1, LLine l2, LLine l3, LLine l4) { return atn; } + /** + * Checks the directional relationship between two angles defined by three points each. + * + * @param a the first point of the first angle + * @param b the vertex point of the first angle + * @param c the second point of the first angle + * @param a1 the first point of the second angle + * @param b1 the vertex point of the second angle + * @param c1 the second point of the second angle + * @return 0, 1, 2, or 3 for specific directional configurations, or -1 if false + */ public int check_atn_dr(int a, int b, int c, int a1, int b1, int c1) { double t1 = getAngleValue(a, b, c); double t2 = getAngleValue(a1, b1, c1); @@ -5286,13 +6265,29 @@ public int check_atn_dr(int a, int b, int c, int a1, int b1, int c1) { return -1; // false } - - ///////////////////////////////////////////////////////////////// + /** + * Retrieves the adjusted angle value based on an AngleT object. + * + * @param a the first point for angle calculation + * @param b the vertex point for angle calculation + * @param c the second point for angle calculation + * @param at the AngleT object containing the original angle value + * @return the adjusted angle value + */ public int getAtv(int a, int b, int c, AngleT at) { int v = at.get_val(a, c); return getAtv(a, b, c, v); } + /** + * Computes the adjusted angle value using a given angle value. + * + * @param a the first point for angle calculation + * @param b the vertex point for angle calculation + * @param c the second point for angle calculation + * @param v the initial angle value + * @return the adjusted angle value, or 0 if no adjustment is needed + */ public int getAtv(int a, int b, int c, int v) { double r = getAngleValue(a, b, c) * A_180 / Math.PI; if (v > A_180) @@ -5306,30 +6301,65 @@ public int getAtv(int a, int b, int c, int v) { return 0; } + /** + * Determines if only existing lines should be searched. + * + * @return true if only existing lines are considered, false otherwise + */ public boolean search_only_exists_ln() { return (!R_SEARCH_ALL_LN);// && depth != 0); } - public boolean search_only_exists_ln(int a, int b) { - return (!R_SEARCH_ALL_LN) && fd_ln(a, b) == null; - } - + /** + * Checks whether lines defined by two pairs of points exist. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @return true if at least one corresponding line does not exist, false otherwise + */ public boolean search_only_exists_ln(int a, int b, int c, int d) { return (!R_SEARCH_ALL_LN) && (fd_ln(a, b) == null || fd_ln(c, d) == null); } + /** + * Checks whether lines defined by three pairs of points exist. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param e the first point of the third line + * @param f the second point of the third line + * @return true if at least one corresponding line does not exist, false otherwise + */ public boolean search_only_exists_ln(int a, int b, int c, int d, int e, int f) { return (!R_SEARCH_ALL_LN) && (fd_ln(a, b) == null || fd_ln(c, d) == null || fd_ln(e, f) == null); } + /** + * Checks if the set of four lines satisfies the search criteria based on intersections. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return true if the lines meet the search criteria, false otherwise + */ public boolean search_only_exists_ln(LLine l1, LLine l2, LLine l3, LLine l4) { if (!R_AG_ALL && (inter_lls(l1, l2) == 0 || inter_lls(l3, l4) == 0)) return false; return true; } -///////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Processes an array of integers to add nodes for a conclusion. + * Each group of three integers represents properties of one node. + * If an extra integer exists after grouping, it is processed as a separate node. + * + * @param p the array of integers representing node properties (zero-terminated) + */ public void add_nodes(int[] p) { // for conclusion; LList d = new LList(); @@ -5362,12 +6392,23 @@ public boolean search_only_exists_ln(LLine l1, LLine l2, LLine l3, LLine l4) { last_ns = d; } + /** + * Creates and returns a copy of the given node list. + * + * @param ns the original node list to copy + * @return a new node list copied from the provided list + */ public LList cp_nodes(LList ns) { LList d = new LList(); d.cp(ns); return d; } + /** + * Adds the specified node list to the global node list if it is not already present. + * + * @param d the node list to add + */ public void add_nodes(LList d) { if (d == null) return; if (x_list(d)) return; @@ -5376,6 +6417,12 @@ public void add_nodes(LList d) { last_ns = d; } + /** + * Checks whether an equivalent node list already exists in the collection. + * + * @param ls the node list to check + * @return true if an equivalent list exists; false otherwise + */ public boolean x_list(LList ls) { if (ls.nd == 0 && ls.nf == 0) return false; @@ -5387,6 +6434,13 @@ public boolean x_list(LList ls) { return false; } + /** + * Compares two node lists for equality based on their node and factor arrays. + * + * @param ls the first node list + * @param ls1 the second node list + * @return true if both lists are equal; false otherwise + */ public boolean eq_list(LList ls, LList ls1) { if (ls.nd != ls1.nd) return false; for (int i = 0; i < ls.nd; i++) { @@ -5401,6 +6455,14 @@ public boolean eq_list(LList ls, LList ls1) { return true; } + /** + * Determines if two Mnde objects are equivalent. + * Equivalence is based on the type value and, if present, the associated transformation. + * + * @param m1 the first Mnde object + * @param m2 the second Mnde object + * @return true if both Mnde objects are considered equal; false otherwise + */ public boolean eq_mnde(Mnde m1, Mnde m2) { if (m1.t != m2.t) return false; if (m1.tr == null && m2.tr == null) return true; @@ -5409,9 +6471,18 @@ public boolean eq_mnde(Mnde m1, Mnde m2) { if (m1.tr.l1 == m2.tr.l1 && m1.tr.l2 == m2.tr.l2) return true; return false; } - ///////////////////////////////////////////////////////// - + /** + * Retrieves an existing AngTr object matching the specified parameters, + * or creates a new one if none exists. + * + * @param v the angle value + * @param t1 the first transformation parameter + * @param t2 the second transformation parameter + * @param l1 the first line + * @param l2 the second line + * @return an existing or newly created AngTr object based on the parameters + */ public AngTr fadd_tr(int v, int t1, int t2, LLine l1, LLine l2) { AngTr tr = fd_tr(v, l1, l2); if (tr != null) return tr; @@ -5422,6 +6493,14 @@ public AngTr fadd_tr(int v, int t1, int t2, LLine l1, LLine l2) { return t; } + /** + * Creates and returns a new AngTr object with the specified angle value and lines. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @return a new AngTr object initialized with the provided parameters + */ public AngTr add_tr(int v, LLine l1, LLine l2) { AngTr tr = new AngTr(); tr.v = v; @@ -5432,6 +6511,14 @@ public AngTr add_tr(int v, LLine l1, LLine l2) { return tr; } + /** + * Searches for an existing AngTr object that matches the specified angle value and lines. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @return the matching AngTr object if found; otherwise, null + */ public AngTr fd_tr(int v, LLine l1, LLine l2) { AngTr tr = all_tr.nx; while (tr != null) { diff --git a/src/main/java/gprover/GDDBc.java b/src/main/java/gprover/GDDBc.java index 2d06d75d..b8504463 100644 --- a/src/main/java/gprover/GDDBc.java +++ b/src/main/java/gprover/GDDBc.java @@ -10,18 +10,28 @@ import wprover.GExpert; import java.util.Vector; - + +/** + * GDDBc class handles the geometric proof process and predicate management. + */ public class GDDBc extends GDDAux { + private static Rule test_r = new Rule(0); AuxPt axptc = null; + /** + * Constructs a new GDDBc instance initializing proof status, depth, and check value. + */ public GDDBc() { P_STATUS = 0; depth = 0; ck_value = true; } + /** + * Executes the fixed-point proof process, handling auxiliary points and node list generation. + */ void prove_fix() { axptc = null; @@ -79,24 +89,32 @@ void prove_fix() { } } - - int PTY(Cond x) { - return x.u.get_type(); - } - + /** + * Retrieves the lemma value from the condition. + * + * @param x the condition from which to obtain the lemma + * @return the lemma value associated with the condition + */ int PLM(Cond x) { return (x.u.get_lemma()); } + /** + * Retrieves the condition predicate from the underlying data structure. + * + * @param x the condition used to extract the predicate + * @return the corresponding condition predicate + */ Cond PCO(Cond x) { return (x.u.get_co()); } - int PNO(Cond x) { - return (x.u.get_no()); - } - - + /** + * Creates a copy of the given predicate condition and updates its identifier. + * + * @param co the original condition to copy + * @return a new condition copied from the provided one with updated identifiers + */ Cond cp_pred(Cond co) { Cond c = new_pr(co.pred); co.no = c.no = ++gno; @@ -108,6 +126,12 @@ Cond cp_pred(Cond co) { return (c); } + /** + * Searches for an existing predicate condition equivalent to the given condition. + * + * @param co the condition to search for + * @return the matching condition if found; otherwise, null + */ Cond fd_pred(Cond co) { Cond pr = all_nd.nx; for (; pr != null; pr = pr.nx) { @@ -116,6 +140,12 @@ Cond fd_pred(Cond co) { return (null); } + /** + * Searches for an equivalent predicate condition based on its comparison value. + * + * @param co the condition to search against + * @return the found condition if present; otherwise, null + */ Cond fd_prep(Cond co) { Cond pr = all_nd.nx; for (; pr != null; pr = pr.nx) { @@ -124,7 +154,21 @@ Cond fd_prep(Cond co) { return (null); } - + /** + * Creates and returns a predicate condition using the provided type and point parameters. + * + * @param m the predicate type identifier + * @param n the predicate condition identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param p7 the seventh point parameter + * @param p8 the eighth point parameter + * @return the constructed predicate condition or null if invalid + */ Cond add_pred(int m, int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { tm_pr1.u.setnull(); tm_pr1.pred = n; @@ -176,6 +220,13 @@ Cond add_pred(int m, int n, int p1, int p2, int p3, int p4, int p5, int p6, int } + /** + * Determines the intersection point between two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point if it exists; otherwise, 0 + */ int finter_ll(LLine l1, LLine l2) { char i, j; @@ -187,6 +238,14 @@ int finter_ll(LLine l1, LLine l2) { return (0); } + /** + * Determines the intersection point between two lines, excluding a specified point. + * + * @param l1 the first line + * @param l2 the second line + * @param p1 the point to exclude from consideration + * @return the intersection point if valid and not equal to p1; otherwise, 0 + */ int finter_ll1(LLine l1, LLine l2, int p1) { char i, j; if (l1 == l2) return (0); @@ -197,6 +256,9 @@ int finter_ll1(LLine l1, LLine l2, int p1) { return (0); } + /** + * Processes and displays the forward proof for the current condition. + */ void show_fproof() { if (conc_xtrue()) { last_nd = all_nd; @@ -209,7 +271,13 @@ void show_fproof() { } } - + /** + * Processes forward predicates for the specified condition. + * + * Traverses the linked list of conditions and applies appropriate predicate rules. + * + * @param co the starting condition to process + */ void forw_pred(Cond co) { Cond pr1, pr2, pr3; show_dtype = 0; @@ -303,73 +371,16 @@ void forw_pred(Cond co) { } } - public boolean add_pr_coll(Cond pr, Cond pr1) { - if (pr.pred == CO_PERP && PLM(pr) == 11 && pr1.pred == CO_ACONG) { - int i1, i2, k1, k2; - if (xcoll4(pr.p[0], pr.p[1], pr1.p[4], pr1.p[5])) { - i1 = pr1.p[4]; - i2 = pr1.p[5]; - k1 = pr1.p[6]; - k2 = pr1.p[7]; - } else { - k1 = pr1.p[4]; - k2 = pr1.p[5]; - i1 = pr1.p[6]; - i2 = pr1.p[7]; - } - for_c4(pr.p[0], pr.p[1], i1, i2); - for_c4(pr.p[2], pr.p[3], k1, k2); - } else if (pr.pred == CO_ACONG && pr1.pred == CO_CYCLIC && PLM(pr) == 41) { - LLine l1 = fd_ln(pr.p[0], pr.p[1]); - LLine l2 = fd_ln(pr.p[2], pr.p[3]); - LLine l3 = fd_ln(pr.p[4], pr.p[5]); - LLine l4 = fd_ln(pr.p[6], pr.p[7]); - int i1 = finter_ll(l1, l2); - int i2 = finter_ll(l3, l4); - int k1 = finter_ll(l1, l3); - int k2 = finter_ll(l2, l4); - if (sdiff(i1, i2, k1, k2, pr.p)) { - for_c4(pr.p[0], pr.p[1], i1, k1); - for_c4(pr.p[2], pr.p[3], i1, k2); - for_c4(pr.p[4], pr.p[5], i2, k1); - for_c4(pr.p[6], pr.p[7], i2, k2); - Cond prc = add_pred(1, CO_ACONG, i1, k1, i1, k2, i2, k1, i2, k2); - pr.addcond(prc); - return false; - } - } else if (pr.pred == CO_ACONG && pr1.pred == CO_CYCLIC && PLM(pr) == 22) { - if (sdiff(pr1.p[0], pr1.p[1], pr1.p[2], 0, pr.p)) { - LLine l1 = fd_ln(pr.p[0], pr.p[1]); - LLine l2 = fd_ln(pr.p[2], pr.p[3]); - LLine l3 = fd_ln(pr.p[4], pr.p[5]); - LLine l4 = fd_ln(pr.p[6], pr.p[7]); - if (l1 == l4) { - int k1 = finter_ll(l2, l3); - int i1 = finter_ll(l1, l2); - int i2 = finter_ll(l1, l3); - for_c6(pr.p[0], pr.p[1], i1, i2, pr.p[6], pr.p[7]); - for_c4(pr.p[2], pr.p[3], k1, i1); - for_c4(pr.p[4], pr.p[5], k1, i2); - Cond prc = add_pred(1, CO_ACONG, i1, i2, i1, k1, i2, k1, i2, i1); - pr.addcond(prc); - } else { - int k1 = finter_ll(l1, l4); - int i1 = finter_ll(l2, l1); - int i2 = finter_ll(l2, l4); - for_c6(pr.p[2], pr.p[3], i1, i2, pr.p[4], pr.p[5]); - for_c4(pr.p[0], pr.p[1], k1, i1); - for_c4(pr.p[6], pr.p[7], k1, i2); - Cond prc = add_pred(1, CO_ACONG, k1, i1, i1, i2, i1, i2, i2, k1); - pr.addcond(prc); - - } - return false; - } - } - - return true; - } - + /** + * Adds a predicate for a collision based on the given conditions. + * + * Determines the appropriate collision predicate by checking common line intersections + * and adds a corresponding parallel predicate condition. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition containing line information + * @param pr2 the second sub-condition containing line information + */ public void add_pred_coll(Cond pr, Cond pr1, Cond pr2) { int lemma = PLM(pr); switch (lemma) { @@ -396,6 +407,16 @@ else if (on_ln(pr.p[i], pr.p[j], l2) && on_ln(pr.p[k], l1)) } } + /** + * Adds a predicate for parallelism based on the provided sub-conditions. + * + * Chooses the appropriate rule based on a lemma value and constructs the relevant predicate + * conditions using line or angle data. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition providing primary predicate data + * @param pr2 the second sub-condition providing supplementary predicate data + */ public void add_pred_para(Cond pr, Cond pr1, Cond pr2) { LLine ln; PLine pn1; @@ -522,6 +543,16 @@ else if (xcoll_ln(fd_ln(pr.p[2], pr.p[3]), pn.ln[i])) } } + /** + * Adds a predicate for perpendicularity based on the given conditions. + * + * Selects the appropriate perpendicularity rule using a lemma value and established geometric + * relationships, then adds the resulting predicate condition. + * + * @param pr the main condition in which the predicate is to be added + * @param pr1 the first sub-condition providing geometric entity information + * @param pr2 the second sub-condition providing geometric entity information + */ public void add_pred_perp(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -605,6 +636,15 @@ public void add_pred_perp(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Adds a predicate for cyclic configurations based on the given conditions. + * + * Extracts circle information from the sub-conditions and creates cyclic predicate conditions. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition containing circle data + * @param pr2 the second sub-condition containing circle data + */ public void add_pred_cr(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); switch (lm) { @@ -620,6 +660,15 @@ public void add_pred_cr(Cond pr, Cond pr1, Cond pr2) { } + /** + * Constructs a cyclic predicate condition from the given circle. + * + * Calculates a set of points on the circle and creates a cyclic predicate condition. + * + * @param pr the original condition used to reference predicate parameters + * @param c1 the circle from which cyclic properties are derived + * @return a new predicate condition representing the cyclic property + */ public Cond add_pred_cyclic1(Cond pr, ACir c1) { int[] p = new int[4]; for (int i = 0; i < 4; i++) @@ -647,6 +696,22 @@ public Cond add_pred_cyclic1(Cond pr, ACir c1) { return add_pred(0, CO_CYCLIC, c1.o, p[0], p[1], p[2], p[3], 0, 0, 0); } + /** + * Adds a predicate based on points and two lines. + * + * Determines appropriate points on the provided lines and constructs a predicate condition with + * the supplied parameters. + * + * @param m the mode or additional modifier for the predicate + * @param n the predicate type identifier + * @param p1 the first point reference + * @param p2 the second point reference + * @param l1 the first line for the predicate + * @param p3 the third point reference + * @param p4 the fourth point reference + * @param l2 the second line for the predicate + * @return a new predicate condition based on the given point and line data + */ public Cond add_pred_pntn(int m, int n, int p1, int p2, LLine l1, int p3, int p4, LLine l2) { int m1, m2, m3, m4; @@ -669,6 +734,22 @@ else if (on_ln(p4, l2)) return add_pred(m, n, m1, m2, m3, m4, 0, 0, 0, 0); } + /** + * Adds a predicate based on tangent line intersections. + * + * Determines intersection points or valid points from the two lines and constructs a tangent rule + * predicate with the specified parameters. + * + * @param m the mode or modifier for the predicate + * @param n the predicate type + * @param p1 the first point candidate for line l1 + * @param p2 the second point candidate for line l1 + * @param l1 the first line used to determine the tangent condition + * @param p3 the first point candidate for line l2 + * @param p4 the second point candidate for line l2 + * @param l2 the second line used to determine the tangent condition + * @return a new predicate condition representing the tangent rule + */ public Cond add_pred_tn13(int m, int n, int p1, int p2, LLine l1, int p3, int p4, LLine l2) { int m1, m2, m3, m4; int o = inter_lls(l1, l2); @@ -694,6 +775,15 @@ else if (on_ln(p4, l2)) return add_pred(m, n, m1, m2, m3, m4, 0, 0, 0, 0); } + /** + * Adds a predicate for angle tangency based on the provided conditions. + * + * Uses geometric relationships from the sub-conditions to construct an angle tangency predicate. + * + * @param pr the main condition to which the predicate will be added + * @param pr1 the first sub-condition containing angle information + * @param pr2 the second sub-condition that may provide additional angle data + */ public void add_pred_atn(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -729,6 +819,23 @@ public void add_pred_atn(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Adds predicates for angle tangency transformations based on paired line configurations. + * + * Compares the relationships between two sets of lines and constructs paired predicates to + * represent angle tangent conditions. + * + * @param pr the main condition to add the predicates to + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @param s1 the first line of the complementary pair + * @param s2 the second line of the complementary pair + * @param s3 the third line used for additional tangent validation + * @param s4 the fourth line used for additional tangent validation + * @return true if the appropriate tangent predicates were added; false otherwise + */ public boolean add_pred_atn_atnas(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, LLine s1, LLine s2, LLine s3, LLine s4) { if (on_ln4(pr.p, l1, l2, s1, s2)) { @@ -755,6 +862,16 @@ public boolean add_pred_atn_atnas(Cond pr, LLine l1, LLine l2, LLine l3, LLine l return false; } + /** + * Adds an angle tangency predicate based on provided angle transformations. + * + * Analyzes the relationships between two angle-based conditions and constructs corresponding + * tangent predicates. + * + * @param pr the main condition to modify + * @param pr1 the first sub-condition containing angle transformation data + * @param pr2 the second sub-condition containing angle transformation data + */ public void add_pred_at(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -863,6 +980,13 @@ public void add_pred_at(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Processes the provided conditions and angle structures to add angle predicates. + * + * @param pr the main condition to add predicates to + * @param pr1 the first condition containing angle information + * @param pr2 the second condition containing angle information + */ public void add_pred_as(Cond pr, Cond pr1, Cond pr2) { Angles as1, as2; as1 = as2 = null; @@ -990,6 +1114,13 @@ public void add_pred_as(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Creates angle predicates by comparing two angle structures and adds them to the condition. + * + * @param pr the target condition to add predicates to + * @param as1 the first angle structure + * @param as2 the second angle structure + */ public void add_as82_t(Cond pr, Angles as1, Angles as2) { LLine l1, l2, l3, l4, l5, l6, l7, l8; l1 = as1.l1; @@ -1027,6 +1158,20 @@ public void add_as82_t(Cond pr, Angles as1, Angles as2) { return; } + /** + * Attempts to add angle congruence predicates using candidate lines from two angle structures. + * + * @param pr the condition containing predicate parameters + * @param l1 the first line from the first structure + * @param l2 the second line from the first structure + * @param l3 the first line from the second structure + * @param l4 the second line from the second structure + * @param l5 a candidate line from the first structure of the second angle structure + * @param l6 a candidate line from the first structure of the second angle structure + * @param l7 a candidate line from the second structure of the second angle structure + * @param l8 a candidate line from the second structure of the second angle structure + * @return true if predicates were successfully added; false otherwise + */ public boolean add_as82t1(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, LLine l5, LLine l6, LLine l7, LLine l8) { @@ -1061,6 +1206,18 @@ public boolean add_as82t1(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, return true; } + /** + * Retrieves candidate line pairs for predicates based on provided parameters. + * + * @param p the integer array containing predicate parameters + * @param l1 the primary line candidate from the first structure + * @param s1 the secondary candidate line corresponding to l1 + * @param l2 the primary line candidate from the second structure + * @param l3 the secondary line candidate from the third structure + * @param s2 the candidate line corresponding to l3 + * @param l4 a fallback line candidate + * @return an array of two candidate lines if matching lines are found; null otherwise + */ LLine[] get_cond_lns(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, LLine l4) { LLine[] lns = get_cond_ln(p, l1, s1, l2, l3, s2, l4); if (lns != null) return lns; @@ -1073,6 +1230,18 @@ LLine[] get_cond_lns(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, return null; } + /** + * Retrieves candidate lines if all predicate parameters lie on the specified lines. + * + * @param p the integer array of predicate parameters + * @param l1 the first line to check + * @param s1 the candidate line corresponding to l1 + * @param l2 the second line to check + * @param l3 the third line to check + * @param s2 the candidate line corresponding to l3 + * @param l4 the fourth line to check + * @return an array containing two candidate lines if conditions match; null otherwise + */ public LLine[] get_cond_ln(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, LLine l4) { if (!on_ln4(p, l1, l2, l3, l4)) return null; LLine[] ns = new LLine[2]; @@ -1081,10 +1250,27 @@ public LLine[] get_cond_ln(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLin return ns; } + /** + * Checks whether each pair of predicate parameters corresponds to a point on the given lines. + * + * @param p the integer array of predicate parameters + * @param l1 the first line for verification + * @param l2 the second line for verification + * @param l3 the third line for verification + * @param l4 the fourth line for verification + * @return true if each predicate parameter pair lies on the corresponding line; false otherwise + */ public boolean on_ln4(int[] p, LLine l1, LLine l2, LLine l3, LLine l4) { return on_ln(p[0], p[1], l1) && on_ln(p[2], p[3], l2) && on_ln(p[4], p[5], l3) && on_ln(p[6], p[7], l4); } + /** + * Processes angle structures to determine appropriate lines and add angle congruence predicates. + * + * @param pr the condition object holding predicate parameters + * @param as1 the first angle structure + * @param as2 the second angle structure + */ public void add_as82(Cond pr, Angles as1, Angles as2) { LLine l1, l2, l3, l4; l1 = l2 = l3 = l4 = null; @@ -1117,6 +1303,18 @@ public void add_as82(Cond pr, Angles as1, Angles as2) { pr.addcond(co1, co2); } + /** + * Creates a tangent predicate using four point parameters and an additional value. + * + * @param m a mode or flag for predicate creation + * @param n a predicate type identifier + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @param p5 an additional parameter influencing the tangent value + * @return a newly created condition representing a tangent predicate + */ public Cond add_pred_4p_tang(int m, int n, int p1, int p2, int p3, int p4, int p5) { int t1, t2, t3; t1 = t2 = t3 = 0; @@ -1140,6 +1338,17 @@ public Cond add_pred_4p_tang(int m, int n, int p1, int p2, int p3, int p4, int p return add_pred(m, n, t1, t2, t3, p5, 0, 0, 0, 0); } + /** + * Determines the angle transformation value based on the provided points and angle transformation objects. + * + * @param p1 the first point for comparison + * @param p2 the second point for comparison + * @param p3 the third point for comparison + * @param p4 the fourth point for comparison + * @param at1 the first angle transformation object + * @param at2 the second angle transformation object + * @return the computed angle value + */ public int get_at2_v(int p1, int p2, int p3, int p4, AngleT at1, AngleT at2) { LLine l1 = at1.l1; LLine l2 = at1.l2; @@ -1156,6 +1365,19 @@ public int get_at2_v(int p1, int p2, int p3, int p4, AngleT at1, AngleT at2) { return 0; } + /** + * Determines a pair of lines based on predicate parameters and candidate line options. + * + * @param a the first integer parameter for the predicate + * @param b the second integer parameter for the predicate + * @param c the third integer parameter for the predicate + * @param d the fourth integer parameter for the predicate + * @param ln1 the first candidate line + * @param ln2 the second candidate line + * @param ln3 the third candidate line + * @param ln4 the fourth candidate line + * @return an array containing two lines if a valid pair is found; null otherwise + */ LLine[] get4lntn(int a, int b, int c, int d, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { LLine[] ls = new LLine[2]; if (on_ln(a, b, ln1) && on_ln(c, d, ln2)) { @@ -1175,6 +1397,11 @@ LLine[] get4lntn(int a, int b, int c, int d, LLine ln1, LLine ln2, LLine ln3, LL return ls; } + /** + * Forwards equal angle predicate if the condition is of type CO_ACONG. + * + * @param pr the condition containing angle parameters + */ void forw_eqangle(Cond pr) { if (pr.pred != Gib.CO_ACONG) return; LLine ln1 = fd_ln(pr.p[0], pr.p[1]); @@ -1189,83 +1416,11 @@ void forw_eqangle(Cond pr) { } } - void for_c4(int p1, int p2, int p3, int p4) { - int[] ps = new int[4]; - int i, p = -1; - - if (p1 != 0 && p1 != p2 && p1 != p3 && p1 != p4) { - p++; - ps[p] = p1; - } - if (p2 != 0 && p2 != p3 && p2 != p4) { - p++; - ps[p] = p2; - } - if (p3 != 0 && p3 != p4) { - p++; - ps[p] = p3; - } - if (p4 != 0) { - p++; - ps[p] = p4; - } - if (p > 1) { - - gprint(Cm.s2707); - gprint("["); - for (i = 0; i <= p; i++) { - gprint(ANAME(ps[i])); - } - gprint(Cm.s2070); - gprint(", "); - } - } - - void for_c6(int p1, int p2, int p3, int p4, int p5, int p6) { - int[] ps = new int[6]; - int i, p = -1; - if (p1 != 0 && p1 != p2 && p1 != p3 && p1 != p4 && p1 != p5 && p1 != p6) { - p++; - ps[p] = p1; - } - if (p2 != 0 && p2 != p3 && p2 != p4 && p2 != p5 && p2 != p6) { - p++; - ps[p] = p2; - } - if (p3 != 0 && p3 != p4 && p3 != p5 && p3 != p6) { - p++; - ps[p] = p3; - } - if (p4 != 0 && p4 != p5 && p4 != p6) { - p++; - ps[p] = p4; - } - if (p5 != 0 && p5 != p6) { - p++; - ps[p] = p5; - } - if (p6 != 0) { - p++; - ps[p] = p6; - } - if (p > 1) { - gprint(Cm.s2707); - gprint("["); - for (i = 0; i <= p; i++) { - gprint(ANAME(ps[i])); - } - gprint("]"); - gprint(Cm.s2070); - gprint(", "); - } - } - - void show_nco(Cond co) { - gprint("(" + co.no + ")"); - show_dtype = 0; - show_pred(co); - } - + /** + * Iterates through all conditions and displays each predicate, including any sub-conditions. + * + * @return true after processing all predicates + */ boolean show_allpred() { Cond co = all_nd.nx; Cond pr1; @@ -1282,7 +1437,12 @@ boolean show_allpred() { return true; } - + /** + * Displays the human-readable form of a given predicate condition. + * + * @param co the condition to display + * @return true after the display has been generated + */ boolean show_pred(Cond co) { switch (co.pred) { case 0: @@ -1531,6 +1691,13 @@ boolean show_pred(Cond co) { return true; } + /** + * Compares two predicate conditions to check for equivalence. + * + * @param co the first condition to compare + * @param pr the second condition to compare + * @return true if both conditions are considered equivalent, false otherwise + */ boolean compare_pred(Cond co, Cond pr) // do_pred(x,x,3) ----------> check two predicate is the same. { if (co.pred != pr.pred) return (false); @@ -1594,6 +1761,12 @@ else if (co.p[0] == pr.p[3] && co.p[1] == pr.p[2] && co.p[2] == pr.p[1] && co.p[ return ex; } + /** + * Checks whether a given predicate is obviously true based on its parameters. + * + * @param co the condition to check + * @return true if the condition meets an obvious criteria, false otherwise + */ boolean check_pred(Cond co) // if it obviousely. { boolean va = false; @@ -1633,6 +1806,11 @@ boolean check_pred(Cond co) // if it obviousely. } + /** + * Processes the predicate condition by executing the corresponding operation based on its type. + * + * @param co the condition to process + */ final void do_pred(Cond co) { switch (co.pred) { @@ -1699,7 +1877,13 @@ final void do_pred(Cond co) { } } - + /** + * Generates a string representation of point names from a condition's parameters. + * + * @param co the condition containing the point parameters + * @param n the starting index of the points in the array + * @return the generated string of point names + */ String show_pts(Cond co, int n) { int i, k; i = k = 0; @@ -1715,29 +1899,15 @@ String show_pts(Cond co, int n) { return s; } - void show_copt(Cond co, int n) { - int i, k; - i = k = 0; - for (i = n; i <= 5; i++) if (co.p[i] != 0) k = i; - - for (i = n; i <= k; i++) { - if (co.p[i] != 0) { - gprint(ANAME(co.p[i])); - if (i != k) gprint(","); - } - } - } - - - boolean sdiff(int a, int b, int c, int d, int ps[]) { - int i; - for (i = 0; i <= 7; i++) { - if (ps[i] == a || ps[i] == b || ps[i] == c || ps[i] == d) continue; - return (true); - } - return (false); - } - + /** + * Compares two arrays of characteristic values to determine if they have the same elements. + * + * @param ch1 the first array of characteristics + * @param n1 the number of valid entries in the first array + * @param ch2 the second array of characteristics + * @param n2 the number of valid entries in the second array + * @return true if both arrays are equal (ignoring order), false otherwise + */ boolean eq_chs(int[] ch1, int n1, int[] ch2, int n2) // Check !! { int id1 = 1; @@ -1764,6 +1934,16 @@ boolean eq_chs(int[] ch1, int n1, int[] ch2, int n2) // Check !! return (true); } + /** + * Retrieves two lines based on the given endpoints from an Angles object's line set. + * + * @param a first point parameter associated with the first line + * @param b second point parameter associated with the first line + * @param c first point parameter associated with the second line + * @param d second point parameter associated with the second line + * @param as the Angles object containing four lines (l1, l2, l3, l4) + * @return an array of two LLine objects if a valid pair is found; otherwise, null + */ LLine[] geti81(int a, int b, int c, int d, Angles as) { LLine l1, l2, l3, l4; l1 = as.l1; @@ -1773,6 +1953,20 @@ LLine[] geti81(int a, int b, int c, int d, Angles as) { return get4ln(l1, l2, l3, l4, a, b, c, d); } + /** + * Determines and returns two complementary LLine objects from the provided four lines + * based on matching endpoint conditions. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @param a first endpoint parameter for matching + * @param b second endpoint parameter for matching + * @param c third endpoint parameter for matching + * @param d fourth endpoint parameter for matching + * @return an array of two LLine objects satisfying the conditions; returns null if none found + */ LLine[] get4ln(LLine l1, LLine l2, LLine l3, LLine l4, int a, int b, int c, int d) { LLine[] ln = new LLine[2]; @@ -1815,6 +2009,16 @@ LLine[] get4ln(LLine l1, LLine l2, LLine l3, LLine l4, int a, int b, int c, int } + /** + * Retrieves a pair of LLine objects from an Angles object based on endpoint criteria. + * + * @param a first endpoint parameter + * @param b second endpoint parameter + * @param c third endpoint parameter + * @param d fourth endpoint parameter + * @param as the Angles object with four lines (l1, l2, l3, l4) + * @return an array of two LLine objects if matching conditions are met; otherwise, null + */ LLine[] geti82(int a, int b, int c, int d, Angles as) { LLine l1, l2, l3, l4; l1 = as.l1; @@ -1848,11 +2052,20 @@ LLine[] geti82(int a, int b, int c, int d, Angles as) { return ln; } + /** + * Determines whether the current conclusion is valid. + * + * @return true if the conclusion satisfies the required geometric conditions; false otherwise + */ boolean conc_xtrue() { return (docc()); } - + /** + * Evaluates the current conclusion by testing various geometric predicates. + * + * @return true if the condition passes the geometric tests; false otherwise + */ boolean docc() { boolean j = false; switch (conc.pred) { @@ -1923,10 +2136,11 @@ boolean docc() { return (j); } - /////////////////////////////////////////// - // pred. - - + /** + * Displays the composite condition by printing concatenated condition information. + * + * @param co the condition object to be displayed + */ void show_cos(Cond co) { if (co != null) { gprint(Cm.s2727); @@ -1947,7 +2161,10 @@ void show_cos(Cond co) { } } - + /** + * Generates textual representations for all geometric entities in the database. + * This includes midpoints, lines, points, circles, angles, and other conditions. + */ public void gen_dbase_text() { this.setPrintToString(); @@ -2045,13 +2262,21 @@ public void gen_dbase_text() { } } - + /** + * Displays the provided condition using the default display format. + * + * @param co the condition object to display + */ void show_co(Cond co) { show_dtype = 0; show_pred(co); } - + /** + * Displays an angle statement from an angle statement object. + * + * @param ast the angle statement object to be displayed + */ public void show_ast(AngSt ast) { gprint(ast.no + "."); if (ast.no < 10) gprint(" "); @@ -2063,6 +2288,11 @@ public void show_ast(AngSt ast) { ast.sd = this.getPrintedString(); } + /** + * Displays the angle represented by an AngleT object, including its line representation and computed value. + * + * @param at the AngleT object containing angle information + */ void show_at(AngleT at) { if (at == null) return; show_agll(at.l1, at.l2); @@ -2076,7 +2306,12 @@ void show_at(AngleT at) { gprint(" = " + ((float) v) / A_TIME); } - //////////////////////////////////////////////////////////// + /** + * Inserts a CClass object into a sorted Vector based on its identifier. + * + * @param obj the CClass object to be inserted + * @param v the Vector collection maintaining sorted CClass objects + */ public void insertVector(CClass obj, Vector v) { if(obj == null) return; @@ -2093,6 +2328,11 @@ public void insertVector(CClass obj, Vector v) { v.add(obj); } + /** + * Returns a Vector containing all MidPt objects with a non-zero type. + * + * @return a Vector of valid MidPt objects + */ public Vector getAll_md() { Vector v = new Vector(); MidPt md = all_md.nx; @@ -2104,6 +2344,11 @@ public Vector getAll_md() { return v; } + /** + * Returns a Vector containing all LLine objects with a non-zero type and at least 2 points. + * + * @return a Vector of valid LLine objects + */ public Vector getAll_ln() { Vector v = new Vector(); LLine ln = all_ln.nx; @@ -2115,6 +2360,11 @@ public Vector getAll_ln() { return v; } + /** + * Returns a Vector containing all PLine objects with a non-zero type. + * + * @return a Vector of valid PLine objects + */ public Vector getAll_pn() { Vector v = new Vector(); PLine pn = all_pn.nx; @@ -2126,6 +2376,11 @@ public Vector getAll_pn() { return v; } + /** + * Returns a Vector containing all TLine objects with a non-zero type. + * + * @return a Vector of valid TLine objects + */ public Vector getAll_tn() { Vector v = new Vector(); TLine tn = all_tn.nx; @@ -2137,6 +2392,11 @@ public Vector getAll_tn() { return v; } + /** + * Returns a Vector containing all ACir objects with a non-zero type and at least 2 points. + * + * @return a Vector of valid ACir objects + */ public Vector getAll_cir() { Vector v = new Vector(); ACir cr = all_cir.nx; @@ -2148,6 +2408,11 @@ public Vector getAll_cir() { return v; } + /** + * Returns a Vector containing all AngSt objects with a non-zero type. + * + * @return a Vector of valid AngSt objects + */ public Vector getAll_as() { Vector v = new Vector(); AngSt ast = all_ast.nx; @@ -2159,6 +2424,11 @@ public Vector getAll_as() { return v; } + /** + * Returns a Vector containing all AngleT objects with a non-zero type. + * + * @return a Vector of valid AngleT objects + */ public Vector getAll_at() { Vector v = new Vector(); AngleT at = all_at.nx; @@ -2170,6 +2440,11 @@ public Vector getAll_at() { return v; } + /** + * Returns a Vector containing all AngTn objects with a non-zero type. + * + * @return a Vector of valid AngTn objects + */ public Vector getAll_atn() { Vector v = new Vector(); AngTn at = all_atn.nx; @@ -2181,7 +2456,11 @@ public Vector getAll_atn() { return v; } - + /** + * Returns a Vector containing all CSegs objects with a non-zero type. + * + * @return a Vector of valid CSegs objects + */ public Vector getAll_cg() { Vector v = new Vector(); CSegs cg = all_cgs.nx; @@ -2193,6 +2472,11 @@ public Vector getAll_cg() { return v; } + /** + * Returns a Vector containing all CongSeg objects with a non-zero type. + * + * @return a Vector of valid CongSeg objects + */ public Vector getAll_rg() { Vector v = new Vector(); CongSeg cg = all_rg.nx; @@ -2204,28 +2488,11 @@ public Vector getAll_rg() { return v; } - public Vector getAll_st() { - Vector v = new Vector(); - SimTri st = all_st.nx; - while (st != null) { - if (st.type != 0 && !xcoll(st.p1[0], st.p1[1], st.p1[2])) - insertVector(st, v); - st = st.nx; - } - return v; - } - - public Vector getAll_ct() { - Vector v = new Vector(); - SimTri ct = all_ct.nx; - while (ct != null) { - if (ct.type != 0 && !xcoll(ct.p1[0], ct.p1[1], ct.p1[2])) - insertVector(ct, v); - ct = ct.nx; - } - return v; - } - + /** + * Returns a Vector containing all RatioSeg objects with a non-zero type. + * + * @return a Vector of valid RatioSeg objects + */ public Vector getAll_ra() { Vector v = new Vector(); RatioSeg ra = all_ra.nx; @@ -2237,6 +2504,11 @@ public Vector getAll_ra() { return v; } + /** + * Returns a Vector containing all STris objects with a non-zero type. + * + * @return a Vector of valid STris objects + */ public Vector getAll_sts() { Vector v = new Vector(); STris sts = all_sts.nx; @@ -2248,6 +2520,11 @@ public Vector getAll_sts() { return v; } + /** + * Returns a Vector containing all STris objects (alternate set) with a non-zero type. + * + * @return a Vector of valid alternate STris objects + */ public Vector getAll_cts() { Vector v = new Vector(); STris sts = all_cts.nx; @@ -2259,6 +2536,15 @@ public Vector getAll_cts() { return v; } + /** + * Searches for a fact based on the specified type and string parameters. + * + * @param t the fact type selector + * @param s1 the first string parameter + * @param s2 the second string parameter + * @param s3 the third string parameter + * @return a Vector containing the matching fact objects + */ public Vector search_a_fact(int t, String s1, String s2, String s3) { int t1 = this.fd_pt(s1); int t2 = this.fd_pt(s2); @@ -2302,6 +2588,13 @@ public Vector search_a_fact(int t, String s1, String s2, String s3) { return v; } + /** + * Retrieves a line if it has at least two points. + * + * @param a the first point parameter + * @param b the second point parameter + * @return the matching line if it exists and meets the criteria; otherwise, null + */ private LLine fd_lnno3(int a, int b) { LLine ln = fd_ln(a, b); if (ln != null && ln.no >= 2) @@ -2309,6 +2602,14 @@ private LLine fd_lnno3(int a, int b) { return null; } + /** + * Searches for angle transformation nodes and adds them to the provided vector. + * + * @param a the first point parameter + * @param b the second point parameter + * @param c the third point parameter + * @param v the vector to collect matching angle transformation nodes + */ private void fo_atn2(int a, int b, int c, Vector v) { AngTn atn = all_atn.nx; @@ -2323,6 +2624,15 @@ else if (on_ln(a, b, atn.ln3) && on_ln(b, c, atn.ln4) || on_ln(a, b, atn.ln4) && } } + /** + * Searches for a triangle matching the given parameters and adds it to the vector. + * + * @param a the first point parameter + * @param b the second point parameter + * @param c the third point parameter + * @param v the vector to collect the matching triangle nodes + * @return always returns null + */ STris fo_tri2(int a, int b, int c, Vector v) { STris st = all_sts.nx; while (st != null) { @@ -2343,6 +2653,14 @@ STris fo_tri2(int a, int b, int c, Vector v) { return null; } + /** + * Searches for and adds congruence or circular segments matching the given points. + * + * @param a the first point parameter + * @param b the second point parameter + * @param v the vector to collect matching segment objects + * @return always returns null + */ CClass fo_cg2(int a, int b, Vector v) { CSegs cgs = all_cgs.nx; @@ -2363,7 +2681,17 @@ CClass fo_cg2(int a, int b, Vector v) { return null; } - /////////////////////////////////////////////////////////////////////////////////////// + /** + * Creates a predicate for angle similarity based on four provided lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred(int m, int n, LLine l1, LLine l2, LLine l3, LLine l4) { int p1, p2, p3, p4, p5, p6, p7, p8; int a = inter_ll(l1, l2); @@ -2395,6 +2723,19 @@ Cond add_as_pred(int m, int n, LLine l1, LLine l2, LLine l3, LLine l4) { return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate from point parameters and two lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4) { int p5, p6, p7, p8; int b = inter_ll(l3, l4); @@ -2425,6 +2766,19 @@ Cond add_as_pred1(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate using a line to derive additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l1 the line used to obtain additional point information + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param l2 the second line used to obtain additional point information + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, int p5, int p6, LLine l2) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2462,6 +2816,21 @@ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, int p5, int p6, LLine return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate from two pairs of points on two lines by selecting the most likely configuration. + * + * @param m the predicate type + * @param n the predicate identifier + * @param m1 the first candidate point on the first line + * @param m2 the second candidate point on the first line + * @param m3 the first candidate point on the second line + * @param m4 the second candidate point on the second line + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred_12(int m, int n, int m1, int m2, int m3, int m4, LLine l1, LLine l2, LLine l3, LLine l4) { // m1,m2 on l1, m3,m4 on l2; find the most likely predicate int p1, p2, p3, p4, p5, p6, p7, p8; @@ -2503,6 +2872,21 @@ else if (m4 == p2) return add_pred(m, n, l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1], l3.pt[0], l3.pt[1], l4.pt[0], l4.pt[1]); } + /** + * Creates a predicate from two pairs of points on two lines with a different configuration. + * + * @param m the predicate type + * @param n the predicate identifier + * @param m1 the first candidate point on the first line + * @param m2 the second candidate point on the first line + * @param m3 the first candidate point on the third line + * @param m4 the second candidate point on the third line + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred_13(int m, int n, int m1, int m2, int m3, int m4, LLine l1, LLine l2, LLine l3, LLine l4) { // m1,m2 on l1, m3,m4 on l3; find the most likely predicate int p1, p2, p3, p4, p5, p6, p7, p8; @@ -2548,6 +2932,19 @@ else if (m4 == p6) return add_pred(m, n, l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1], l3.pt[0], l3.pt[1], l4.pt[0], l4.pt[1]); } + /** + * Creates a predicate from a line and additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param l1 the line providing initial point information + * @param p1 the first point parameter on the line + * @param p2 the second point parameter on the line + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param l2 the second line used for deriving further point information + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, LLine l1, int p1, int p2, int p5, int p6, LLine l2) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2585,6 +2982,19 @@ Cond add_as_pred1(int m, int n, LLine l1, int p1, int p2, int p5, int p6, LLine return add_pred(m, n, p3, p4, p1, p2, p5, p6, p7, p8); } + /** + * Creates a predicate from two lines and additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l1 the first line + * @param l2 the second line + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, LLine l2, int p5, int p6) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2621,6 +3031,19 @@ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, LLine l2, int p5, int return add_pred(m, n, p1, p2, p3, p4, p7, p8, p5, p6); } + /** + * Creates an angle transformation predicate based on given point parameters and two lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_atn(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4) { int p5, p6, p7, p8; int b = inter_ll(l3, l4); @@ -2650,6 +3073,19 @@ Cond add_as_atn(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4 return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate using point parameters and two lines for congruence segments. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l2 the first line + * @param l3 the second line + * @param p7 the seventh point parameter + * @param p8 the eighth point parameter + * @return the constructed predicate object + */ Cond add_as_pred2(int m, int n, int p1, int p2, LLine l2, LLine l3, int p7, int p8) { int p3, p4, p5, p6; if (on_ln(p1, l2)) { @@ -2688,12 +3124,13 @@ Cond add_as_pred2(int m, int n, int p1, int p2, LLine l2, LLine l3, int p7, int return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } -///////////////////////////////////////////////////////////////////////////// -//***************************************************************************** -// adding auxiliary points - - //////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Checks if the given condition is valid. Validity depends on whether the predicate is CO_ACONG + * and specific point values satisfy the anti-angle criteria. + * + * @param c the condition to be validated + * @return true if the condition is valid; false otherwise + */ public boolean check_tValid(Cond c) { if (isPFull()) return true; if (c.pred != CO_ACONG) return true; @@ -2704,10 +3141,9 @@ public boolean check_tValid(Cond c) { return true; } -/////////////////////////////////////////////////////////////////////////////////////////////////// -///// for backward chaining. - - + /** + * Parses the global node list, processes sublists, and displays the list content using backup and preview mechanisms. + */ public void parse_llist() { LList ns = all_ns.nx; if (ns == null) return; @@ -2751,7 +3187,12 @@ public void parse_llist() { } } - + /** + * Retrieves the next proof head node list from the global node list. + * + * @param ls the current node list + * @return the next node list for proof head, or null if no further node is available + */ LList get_next_ls_prove_head(LList ls) { LList ns = all_ns.nx; if (ns == null) return null; @@ -2771,6 +3212,11 @@ LList get_next_ls_prove_head(LList ls) { return rs; } + /** + * Displays the list preview by printing the node list and all its associated rules. + * + * @param ls the node list to preview + */ void show_lprv(LList ls) { setPrintToString(); @@ -2787,6 +3233,11 @@ void show_lprv(LList ls) { } } + /** + * Searches for angle splitting opportunities within the given node list and adds corresponding split rules. + * + * @param ls the node list to search for angle splits + */ public void search_ag_split(LList ls) { if (ls.nd == 1) return; @@ -2820,6 +3271,11 @@ public void search_ag_split(LList ls) { } } + /** + * Searches the TLine list for applicable transformations and adds corresponding rules to the given node list. + * + * @param ls the node list to process for transformation rules + */ public void search_t_list(LList ls) { TLine tn = all_tn.nx; @@ -2835,6 +3291,11 @@ public void search_t_list(LList ls) { } } + /** + * Searches the node list for predicate rules based on angle properties and anti-point values, adding matching rules. + * + * @param ls the node list to search for predicate rules + */ public void search_p_list(LList ls) { for (int i = 0; i < ls.nd; i++) { Mnde m = ls.md[i]; @@ -2848,6 +3309,15 @@ public void search_p_list(LList ls) { } } + /** + * Searches the node list for transformation matches based on the given lines and intersection value, + * and adds corresponding tag rules. + * + * @param ls the node list to search + * @param l1 the first line for the search criteria + * @param l2 the second line for the search criteria + * @param v the intersection value used for matching + */ public void search_list_tn(LList ls, LLine l1, LLine l2, int v) { if (v != 0) { for (int i = 0; i < ls.nd; i++) { @@ -2870,24 +3340,13 @@ public void search_list_tn(LList ls, LLine l1, LLine l2, int v) { } } - public void search_p_list(Vector v) { - - for (int i = 0; i < v.size(); i++) { - LList ls = (LList) v.get(i); - - } - } - - public void search_list_ln(LList ls) { - for (int i = 0; i < ls.nd; i++) { - AngTr t = ls.md[i].tr; - if (t.v == ls.pt) { - - } - - } - } - + /** + * Creates and returns a tag rule for an angle based on the intersection of two lines. + * + * @param l1 the first line for the rule + * @param l2 the second line for the rule + * @return a tag rule with angle relations configured + */ public Rule add_rule_tag(LLine l1, LLine l2) { Rule r = new Rule(Rule.T_ANGLE); Mnde m = new Mnde(); @@ -2902,6 +3361,15 @@ public Rule add_rule_tag(LLine l1, LLine l2) { return r; } + /** + * Creates and returns a split-angle rule that partitions an angle into sub-angles using the given lines. + * + * @param v the angle value used for splitting + * @param l1 the first line for the transformation + * @param l2 the second line forming the angle vertex + * @param l3 the third line completing the new angle configuration + * @return a split-angle rule containing the constructed transformations + */ public Rule add_rule_spag(int v, LLine l1, LLine l2, LLine l3) { Rule r = new Rule(Rule.SPLIT_ANGLE); Mnde m = new Mnde(); @@ -2920,6 +3388,12 @@ public Rule add_rule_spag(int v, LLine l1, LLine l2, LLine l3) { return r; } + /** + * Creates a P_ANGLE rule using the provided angle transformation. + * + * @param t the angle transformation containing the angle value and associated lines + * @return a new Rule object of type P_ANGLE + */ public Rule add_rule_p_ag(AngTr t) { int v = t.v; @@ -2948,8 +3422,15 @@ public Rule add_rule_p_ag(AngTr t) { return r; } - - + /** + * Creates an EX_ANGLE rule based on three lines forming an angle. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @return a new Rule object of type EX_ANGLE, or null if a valid intersection is not found + */ public Rule add_rule_exag(int v, LLine l1, LLine l2, LLine l3) { Rule r = new Rule(Rule.EX_ANGLE); Mnde m = new Mnde(); @@ -2973,8 +3454,12 @@ public Rule add_rule_exag(int v, LLine l1, LLine l2, LLine l3) { return r; } - private static Rule test_r = new Rule(0); - + /** + * Subtracts matching nodes from the provided node list using the specified rule. + * + * @param ls the original node list + * @param r the rule to apply for subtracting matching nodes + */ public void list_sub(LList ls, Rule r) { if (r == null) return; @@ -3023,14 +3508,11 @@ public void list_sub(LList ls, Rule r) { } - public boolean equal_md(Mnde m1, Mnde m2) { - if (m1.tr == null && m2.tr == null) { - if (m1.t == m2.t) return true; - return false; - } - return false; - } - + /** + * Retrieves a vector of node lists sorted by their point counts. + * + * @return a Vector containing sorted node lists + */ public Vector getPVector() { Vector v = new Vector(); LList ns = all_ns.nx; @@ -3048,6 +3530,11 @@ public Vector getPVector() { return v; } + /** + * Displays a single node list in a formatted manner. + * + * @param ls the node list to be displayed + */ public void show_llist(LList ls) { for (int i = 0; i < ls.nd; i++) { Mnde m = ls.md[i]; @@ -3075,10 +3562,11 @@ public void show_llist(LList ls) { } -// public void show_rule(rule r) { -// if (r.type == rule.) -// } - + /** + * Displays all node lists contained in the provided vector. + * + * @param v a vector containing node lists to be displayed + */ public void show_llists(Vector v) { for (int i = 0; i < v.size(); i++) { @@ -3087,6 +3575,11 @@ public void show_llists(Vector v) { } } + /** + * Displays the Mnde object either by showing its transformation or its angle value. + * + * @param m the Mnde object to be displayed + */ public void show_mnde(Mnde m) { if (m.tr == null) @@ -3095,28 +3588,11 @@ public void show_mnde(Mnde m) { show_tr(m.tr); } - - void show_bk_list(LList ls) { - - setPrintToString(); - if (ls == null) return; - while (ls != null) { - show_llist(ls); - ls.text = this.getPrintedString(); - show_rule(ls.rl[0]); - - ls = ls.fr; - } - } - - LList fd_nx_list(LList ls) { - if (ls == null) return all_ns.nx; - LList ls1 = all_ns.nx; - while (ls1 != ls) - ls1 = ls1.nx; - return ls1.nx; - } - + /** + * Parses a backup list of node lists, updating rules and transformations as needed. + * + * @param ls the starting node list for the backup parsing process + */ void parse_bk_list(LList ls) { Vector v = new Vector(); while (ls != null) { @@ -3183,7 +3659,13 @@ void parse_bk_list(LList ls) { } } - + /** + * Searches the node list for an angle transformation matching the specified transformation. + * + * @param t the target angle transformation to find + * @param ls the node list to search for a matching transformation + * @return the matching AngTr object if found; otherwise, null + */ public AngTr find_tr_in_ls(AngTr t, LList ls) { for (int i = 0; i < ls.nd; i++) { AngTr t1 = ls.md[i].tr; @@ -3192,6 +3674,11 @@ public AngTr find_tr_in_ls(AngTr t, LList ls) { return null; } + /** + * Displays the provided rule in a formatted manner. + * + * @param r the rule to be displayed + */ void show_rule(Rule r) { if (r == null) return; diff --git a/src/main/java/gprover/GTerm.java b/src/main/java/gprover/GTerm.java index 5f1ac26d..85608159 100644 --- a/src/main/java/gprover/GTerm.java +++ b/src/main/java/gprover/GTerm.java @@ -8,6 +8,18 @@ * JGEX supports loading and saving scripts in a simple textual format. * Among the examples, these files have no extension (see, e.g. 3_JAR/simson). * This class can load and save them. + * * Represents geometric constructions and their associated operations. + * * + * *This class encapsulates the management of points, construction steps, + * * and constraints within a geometric theorem proving framework. + * * It provides methods for adding, retrieving, and processing geometric data, + * * including the generation of non-degenerate and prerequisite constraints. + * * Fundamental operations include loading, saving, and validating the structure + * * of geometric constructions.
+ * * + * *Utilize this class to perform geometric analyses and manipulations necessary + * * for automated theorem proving and geometric constraint solving within the + * * framework.
*/ public class GTerm { @@ -29,13 +41,18 @@ public class GTerm { private Vector ccons = new Vector(); private Vector ncons = new Vector(); + /** + * Constructs a new GTerm instance. + */ public GTerm() { } - public Vector getCgs() { - return ccons; - } - + /** + * Returns the constraint at the specified index from the constraint vector. + * + * @param n the 0-based index of the constraint to retrieve + * @return the constraint at index n, or null if n is out of range + */ public Cons getCons(int n) { int n1 = gcons.size(); if (n < 0 || n >= n1) @@ -43,6 +60,11 @@ public Cons getCons(int n) { return (Cons) gcons.get(n); } + /** + * Returns a vector containing non‐degenerate constraints. + * + * @return a vector of CNdg objects representing non‐degenerate constraints + */ public Vector getNcons() { Vector v = new Vector(); @@ -64,6 +86,12 @@ else if (c.type == Gib.CO_PERP) return v; } + /** + * Generates a string description for the specified CNdg object based on the provided parameters. + * + * @param dg the CNdg object to update with its description + * @param pss the array of parameters used for generating the description + */ public void generateSd(CNdg dg, Object[] pss) { switch (dg.type) { case Gib.NDG_COLL: @@ -82,18 +110,21 @@ public void generateSd(CNdg dg, Object[] pss) { } + /** + * Returns the vector containing all constraints. + * + * @return the vector of constraint objects + */ public Vector getCons() { return gcons; } - public Vector getPureCons() { - Vector v = new Vector(); - int n = gcons.size(); - for (int i = 1; i < n - 1; i++) - v.add(gcons.get(i)); - return v; - } - + /** + * Copies all constraints into the given array, starting at index 1. + * + * @param cn the array in which to store the constraint objects + * @return the number of constraints copied + */ public int setAllcons(Cons[] cn) { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -102,6 +133,12 @@ public int setAllcons(Cons[] cn) { return gcons.size(); } + /** + * Copies all points into the given array, starting at index 1. + * + * @param pp the array in which to store the point objects + * @return the number of points copied + */ public int setAllpts(ProPoint[] pp) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -110,10 +147,20 @@ public int setAllpts(ProPoint[] pp) { return gpoints.size(); } + /** + * Returns the number of points in the construction. + * + * @return the number of points + */ public int getPointsNum() { return gpoints.size(); } + /** + * Returns a vector containing the names of all points. + * + * @return a vector of point names + */ public Vector getAllptsText() { Vector v = new Vector(); @@ -124,15 +171,29 @@ public Vector getAllptsText() { return v; } + /** + * Returns the number of constraints (as derived from the points vector). + * + * @return the number of constraints + */ public int getCons_no() { return gpoints.size(); } - + /** + * Returns the current conclusion condition. + * + * @return the Cond object representing the conclusion + */ public Cond getConc() { return conc; } + /** + * Retrieves the conclusion constraint if it exists. + * + * @return the conclusion constraint, or null if none exists + */ public Cons getConclusion() { int s = gcons.size(); if (s == 0) return null; @@ -142,6 +203,12 @@ public Cons getConclusion() { return null; } + /** + * Sets the conclusion constraint and updates the underlying condition. + * + * @param c the conclusion constraint to set + * @return true if the conclusion was set successfully, false otherwise + */ public boolean setConclusion(Cons c) { int s = gcons.size(); @@ -177,15 +244,31 @@ public boolean setConclusion(Cons c) { return true; } + /** + * Returns the name of the construction. + * + * @return the construction name + */ public String getName() { return name; } + /** + * Sets the name for the construction. + * + * @param s the name to set + */ public void setName(String s) { name = s; } - + /** + * Reads an A-term from the provided BufferedReader. + * + * @param in the BufferedReader to read from + * @return true if the term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm(BufferedReader in) throws IOException { Vector glines = new Vector(); int status = 0; @@ -255,6 +338,13 @@ public boolean readAterm(BufferedReader in) throws IOException { return true; } + /** + * Writes the current A-term to the specified FileOutputStream. + * + * @param out the FileOutputStream to write to + * @return true if the A-term is successfully written; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean writeAterm(FileOutputStream out) throws IOException { String sn = name; if (sn == null || sn.length() == 0) @@ -272,6 +362,13 @@ public boolean writeAterm(FileOutputStream out) throws IOException { return true; } + /** + * Reads an A-term from the given DataInputStream. + * + * @param in the DataInputStream to read from + * @return true if the A-term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm(DataInputStream in) throws IOException { int n = in.readInt(); Vector glines = new Vector(); @@ -286,6 +383,13 @@ public boolean readAterm(DataInputStream in) throws IOException { return true; } + /** + * Writes the current A-term to the provided DataOutputStream using an alternative format. + * + * @param out the DataOutputStream to write to + * @return true if the A-term is successfully written; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean writeAterm2(DataOutputStream out) throws IOException { int n = gcons.size(); out.writeInt(n + 2); @@ -309,6 +413,12 @@ public boolean writeAterm2(DataOutputStream out) throws IOException { return true; } + /** + * Adds a new point with the specified name if it does not already exist. + * + * @param s the name of the point to add + * @return false if the point already exists, otherwise false after adding the point + */ public boolean add_pt(String s) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -320,6 +430,16 @@ public boolean add_pt(String s) { return false; } + /** + * Sets the location for the point matching the given name. + * + * @param sn the name of the point + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param x1 the first additional coordinate parameter + * @param y1 the second additional coordinate parameter + * @return true if the point location is successfully set; false otherwise + */ public boolean setPtLoc(String sn, double x, double y, int x1, int y1) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -332,6 +452,13 @@ public boolean setPtLoc(String sn, double x, double y, int x1, int y1) { return false; } + /** + * Reads an A-term from the provided DataInputStream while ignoring header lines. + * + * @param in the DataInputStream to read from + * @return true if the A-term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm2(DataInputStream in) throws IOException { int n = in.readInt(); Vector glines = new Vector(); @@ -346,7 +473,9 @@ public boolean readAterm2(DataInputStream in) throws IOException { return true; } - + /** + * Clears all stored points, construction steps, and resets the construction name. + */ public void clear() { gpoints.clear(); gcons.clear(); @@ -354,20 +483,22 @@ public void clear() { name = null; } - + /** + * Clears current construction data and sets constraints from the given vector. + * + * @param v the vector containing new constraints + */ public void addConsV(Vector v) { this.clear(); gcons.addAll(v); } - public void setGenerated(boolean r) { - generated = r; - } - - public boolean isGenerated() { - return generated; - } - + /** + * Generates the construction based on the provided vector of input lines. + * + * @param glines the vector containing construction lines + * @return true if the generation is successful; false otherwise + */ public boolean generate(Vector glines) { if (generated) return true; @@ -395,7 +526,12 @@ public boolean generate(Vector glines) { return true; } - + /** + * Generates the positions of points using the stored position string. + * Parses the position string, updates each point's coordinates, and sets the position flag. + * + * @return true if the positions were generated successfully or no positions were provided. + */ boolean generate_position() { String s = posString.trim(); if (s == null || s.length() == 0) { @@ -492,11 +628,21 @@ boolean generate_position() { return true; } - + /** + * Adds an auxiliary point to the construction. + * + * @param pt the point to be added. + */ public void addauxedPoint(ProPoint pt) { gpoints.add(pt); } + /** + * Adds an auxiliary constraint to the construction. + * Inserts the constraint appropriately depending on whether a conclusion exists. + * + * @param c the constraint to be added. + */ public void addauxedCons(Cons c) { int n = gcons.size(); if (n == 0) @@ -508,6 +654,11 @@ public void addauxedCons(Cons c) { } } + /** + * Returns the number of constructions excluding the final conclusion if present. + * + * @return the count of constructions. + */ public int getconsNum() { int n = gcons.size() - 1; if (n <= 0) @@ -518,14 +669,29 @@ public int getconsNum() { return n - 1; } + /** + * Determines if the term is animated based on the animation string. + * + * @return true if the term is animated, false otherwise. + */ public boolean isTermAnimated() { return aniString.startsWith("ANI"); } + /** + * Retrieves the animation string for the term. + * + * @return the animation string. + */ public String getAnimateString() { return aniString; } + /** + * Checks if the positions of points have been set. + * + * @return true if positions are set, false otherwise. + */ public boolean isPositionSet() { return is_position_set; } @@ -607,6 +773,13 @@ boolean addConclusion(String ln) { return true; } + /** + * Adds a construction condition parsed from the provided script line. + * Handles various types of conditions including point definitions and constraints. + * + * @param ln the script line representing the condition. + * @return true if the condition was added successfully, false otherwise. + */ boolean addCondition(String ln) { String st = ln.trim().substring(0, 4); if (st.equalsIgnoreCase("show")) { @@ -659,6 +832,12 @@ boolean addCondition(String ln) { return true; } + /** + * Retrieves the predicate type corresponding to the provided string. + * + * @param sh the string representing the predicate. + * @return the integer value corresponding to the predicate type. + */ private int getPred(String sh) { int t = CST.get_pred(sh); if (t == 0) @@ -666,9 +845,13 @@ private int getPred(String sh) { return t; } - public void addSquare(String[] list) { - } + /** + * Processes an inter-line constraint. + * Adds a circumcenter point if required before creating the constraint. + * + * @param list the array of parameters representing the constraint. + */ public void addInterLS(String[] list) { if (list.length != 7) { return; @@ -685,6 +868,13 @@ public void addInterLS(String[] list) { this.addCd(Gib.C_I_LS, list); } + + /** + * Processes an inter-segment constraint. + * Adds circumcenter points if needed before creating the constraint. + * + * @param list the array of parameters representing the constraint. + */ public void addInterSS(String[] list) { if (list.length != 8) { return; @@ -709,21 +899,14 @@ public void addInterSS(String[] list) { this.addCd(Gib.C_I_SS, list); } - public void addRatio(int type, String[] list) { - - try { - ProPoint pt = this.addPt(list[1]); - pt.setType(type); - int i = 0; - for (i = 1; i < list.length - 1; i++) - pt.setPS(findPt(list[i]), i - 1); - pt.setPS(Integer.parseInt(list[i]), i - 1); - } catch (NumberFormatException ee) { - Cm.print(ee.getMessage()); - } - - } + /** + * Adds a constant to the construction. + * Creates a new constant constraint using the provided identifier and function. + * + * @param sf the identifier for the constant. + * @param func the function defining the constant. + */ public void addConstant(String sf, String func) { Cons c = new Cons(Gib.C_CONSTANT); @@ -771,6 +954,12 @@ public void addConstant(String sf, String func) { } + /** + * Adds a point to the list and updates the initial point construction if needed. + * + * @param pt the point to be added. + * @return the new total count of points. + */ int addPtToList(ProPoint pt) { gpoints.add(pt); @@ -781,32 +970,11 @@ int addPtToList(ProPoint pt) { return gpoints.size(); } - void addCircle(String[] list) { - for (int i = 1; i <= 3; i++) { - ProPoint pt = new ProPoint(); - pt.name = list[i]; - pt.type = Gib.C_POINT; - addPtToList(pt); - } - - ProPoint pt = new ProPoint(); - pt.name = get_cir_center_name(); - pt.type = Gib.C_CIRCUM; - pt.ps[0] = this.findPt(list[1]); - pt.ps[1] = this.findPt(list[2]); - pt.ps[2] = this.findPt(list[3]); - int o = addPtToList(pt); - - for (int i = 4, j = 0; i < list.length; i++, j++) { - ProPoint pt1 = new ProPoint(); - pt1.name = list[i]; - pt1.type = Gib.C_O_C; - pt1.ps[0] = this.findPt(pt.name); - pt1.ps[1] = this.findPt(list[1]); - addPtToList(pt1); - } - } - + /** + * Generates a unique name for a circle center that does not conflict with existing points. + * + * @return the generated circle center name. + */ String get_cir_center_name() { int i = 1; while (true) { @@ -826,6 +994,12 @@ String get_cir_center_name() { } } + /** + * Retrieves a point based on its 1-based index. + * + * @param x the 1-based index of the point. + * @return the corresponding ProPoint, or null if the index is out of bounds. + */ public ProPoint getProPoint(int x) { if (x <= 0 || x > gpoints.size()) { return null; @@ -833,6 +1007,12 @@ public ProPoint getProPoint(int x) { return ((ProPoint) gpoints.get(x - 1)); } + /** + * Retrieves a construction constraint based on its 1-based index. + * + * @param x the 1-based index of the constraint. + * @return the corresponding Cons object, or null if the index is out of bounds. + */ public Cons getPcons(int x) { if (x <= 0 || x > gcons.size()) { return null; @@ -841,6 +1021,12 @@ public Cons getPcons(int x) { } + /** + * Retrieves the name of a point based on its 1-based index. + * + * @param x the 1-based index of the point. + * @return the point name, or an empty string if the index is invalid. + */ public String getPtName(int x) { if (x <= 0 || x > gpoints.size()) { return ""; @@ -848,7 +1034,9 @@ public String getPtName(int x) { return ((ProPoint) gpoints.get(x - 1)).name; } - + /** + * Recalculates and updates constraint point indexes and conclusion values. + */ public void ge_cpt() { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -908,6 +1096,14 @@ else if (this.isStringTypeInt(s)) { } + /** + * Finds the center point index based on three given point names. + * + * @param a the first point name + * @param b the second point name + * @param c the third point name + * @return the index of the center point if found; 0 otherwise + */ int findCenter(String a, String b, String c) { if (a == null || b == null || c == null) { return 0; @@ -934,6 +1130,12 @@ int findCenter(String a, String b, String c) { return 0; } + /** + * Finds the index of the point that matches the specified name. + * + * @param sn the name of the point to search for + * @return the index of the point if found; 0 otherwise + */ int findPt(String sn) { for (int j = 0; j < gpoints.size(); j++) { ProPoint p = (ProPoint) gpoints.get(j); @@ -944,6 +1146,12 @@ int findPt(String sn) { return 0; } + /** + * Adds a new point with the specified name if it does not exist. + * + * @param sn the name of the point to add + * @return the added or existing ProPoint instance + */ ProPoint addPt(String sn) { ProPoint pt; if ((pt = fd_pt(sn)) == null) { @@ -955,6 +1163,12 @@ ProPoint addPt(String sn) { return pt; } + /** + * Retrieves a point with the specified name from the list. + * + * @param sn the name of the point to retrieve + * @return the ProPoint if found; null otherwise + */ protected ProPoint fd_pt(String sn) { for (int i = 0; i < gpoints.size(); i++) { ProPoint pt = (ProPoint) gpoints.get(i); @@ -965,6 +1179,12 @@ protected ProPoint fd_pt(String sn) { return null; } + /** + * Determines whether the provided string represents a valid integer. + * + * @param s the string to check + * @return true if the string is a valid integer representation; false otherwise + */ boolean isStringTypeInt(String s) { if (s == null || s.length() == 0) return false; int i = 0; @@ -977,6 +1197,13 @@ boolean isStringTypeInt(String s) { return true; } + /** + * Creates and adds a constant constraint using the specified type and parameters. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created constant constraint + */ Cons addCd(int type, String[] list) { Cons c = getCd(type, list); if (c != null) @@ -984,6 +1211,11 @@ Cons addCd(int type, String[] list) { return c; } + /** + * Converts the string parameters of the given constraint to point indexes. + * + * @param c the constraint to process + */ public void ge_pss2ps(Cons c) { int i = 0; while (true) { @@ -996,12 +1228,24 @@ public void ge_pss2ps(Cons c) { } + /** + * Updates and adds a non-degenerate constraint if it is not already present. + * + * @param c the constraint to add + */ public void addNdg(Cons c) { ge_pss2ps(c); if (!ncons.contains(c)) ncons.add(c); } + /** + * Creates and adds a non-degenerate constraint from the provided type and parameters. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created non-degenerate constraint + */ Cons addNdg(int type, String[] list) { Cons c = getCd(type, list); if (c != null) @@ -1009,6 +1253,13 @@ Cons addNdg(int type, String[] list) { return c; } + /** + * Creates a constraint based on the provided type and parameter list. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created constraint + */ Cons getCd(int type, String[] list) { int len = list.length; if (len <= 1) @@ -1049,15 +1300,23 @@ Cons getCd(int type, String[] list) { return c; } + /** + * Saves data to the given output stream. + * + * @param out the DataOutputStream to write to + * @return true if the save operation is successful + * @throws IOException if an I/O error occurs + */ boolean Save(DataOutputStream out) throws IOException { out.writeChars("\n"); return true; } - public String NAME(int i) { - return this.getPtName(i); - } - + /** + * Retrieves the text representation of the current conclusion. + * + * @return the conclusion text, or "NO" if no conclusion is set + */ public String getConcText() { Cons c = this.getConclusion(); if (c == null) @@ -1065,10 +1324,18 @@ public String getConcText() { return CST.getDString(c.pss, c.type); } + /** + * Sets the conclusion number. + */ public void setConclusionNo() { } + /** + * Checks if a valid conclusion exists in the construction. + * + * @return true if the last condition type is within the valid range (>= 50 and < 100); false otherwise. + */ public boolean hasConclusion() { int n = gcons.size(); if (n == 0) @@ -1078,6 +1345,12 @@ public boolean hasConclusion() { } + /** + * Determines whether the point identified by the given index is free. + * + * @param n the 1-based index of the point to check. + * @return true if the point is not used as the last element in any constraint; false otherwise. + */ public boolean isFreePoint(int n) { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -1092,6 +1365,11 @@ public boolean isFreePoint(int n) { // return false; } + /** + * Returns a string representation of the construction. + * + * @return the name of the construction if available; otherwise, the default string representation. + */ public String toString() { if (name != null) { return name; @@ -1100,11 +1378,11 @@ public String toString() { } } - /** - * **************pc****************** + * Processes and returns a vector of processed constraints. + * + * @return a vector containing the processed constraints. */ - public Vector pc() { Vector vlist = new Vector(); Vector v = new Vector(); @@ -1179,13 +1457,9 @@ else if (c.is_conc()) return vlist; } - private void showNCMessage(Cons c1, Cons c2) { - String s1 = c1.toDString(); - if (c2 != null) - s1 += "\n" + c2.toDString(); - JOptionPane.showMessageDialog(null, "NOT CONSTRUCTIVE\n" + s1); - } - + /** + * Aggregates and computes all circle constraints from the current constraint data. + */ public void getAllCircles() { Vector v = ccons; @@ -1249,6 +1523,14 @@ else if (c.ps[k * 2 + 1] == c.ps[j]) } } + /** + * Adds a circle constraint between the two specified points to the provided constraint, + * if the connection does not already exist. + * + * @param a the first point index. + * @param b the second point index. + * @param cs the constraint to which the circle condition is added. + */ public void addccc(int a, int b, Cons cs) { int n = (cs.no + 1) / 2; for (int i = 0; i < n; i++) { @@ -1260,6 +1542,12 @@ public void addccc(int a, int b, Cons cs) { cs.no += 2; } + /** + * Adds prerequisite equality constraints based on the given type and associated points. + * + * @param t the constraint type. + * @param p an array of point indices representing the constraint. + */ public void add_preq(int t, int[] p) { switch (t) { case Gib.C_O_C: @@ -1329,6 +1617,14 @@ public void add_preq(int t, int[] p) { } } + /** + * Adds an equality constraint equating the distances between the two pairs of points. + * + * @param a the first point index of the first pair. + * @param b the second point index of the first pair. + * @param c the first point index of the second pair. + * @param d the second point index of the second pair. + */ public void add_eqcons(int a, int b, int c, int d) { Cons cs = new Cons(Gib.C_EQDISTANCE, 100); cs.add_pt(a); @@ -1338,7 +1634,13 @@ public void add_eqcons(int a, int b, int c, int d) { ccons.add(cs); } - + /** + * Retrieves and removes the first constraint in the vector that contains the specified point. + * + * @param pt the point identifier to search for in the constraints. + * @param v the vector of constraints to search through. + * @return the constraint that contains the point, or null if no such constraint exists. + */ public Cons getcons(int pt, Vector v) { for (int i = 0; i < v.size(); i++) { Cons c = (Cons) v.get(i); @@ -1350,6 +1652,12 @@ public Cons getcons(int pt, Vector v) { return null; } + /** + * Generates all non-degenerate constraints from the given vector. + * + * @param v the vector of constraints from which to generate non-degenerate constraints. + * @return a vector containing all non-degenerate constraints. + */ public Vector getAllNdgs(Vector v) { Vector v1 = new Vector(); @@ -1360,6 +1668,12 @@ public Vector getAllNdgs(Vector v) { return v1; } + /** + * Generates non-degenerate constraints based on the specified constraint and adds them to the provided vector. + * + * @param c the original constraint used as a basis for generating non-degenerate constraints. + * @param v the vector to which the generated constraints will be added. + */ public void generateCons(Cons c, Vector v) { switch (c.type) { @@ -1526,14 +1840,19 @@ public void generateCons(Cons c, Vector v) { } } - public Cons getNDG_AA(Cons c) { - if (c.type != Gib.C_I_AA) - return null; - return null; - - } - - + /** + * Creates a non-degenerate parallel constraint from the provided points and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param t4 the fourth point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @param o4 the fourth associated object. + * @return a Cons object representing the non-degenerate parallel constraint, or null if conditions are not met. + */ public Cons getNDG_PARA(int t1, int t2, int t3, int t4, Object o1, Object o2, Object o3, Object o4) { if (t1 > t2) { int t = t1; @@ -1586,6 +1905,19 @@ public Cons getNDG_PARA(int t1, int t2, int t3, int t4, Object o1, Object o2, Ob } + /** + * Creates a non-degenerate perpendicular constraint based on the provided points and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param t4 the fourth point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @param o4 the fourth associated object. + * @return a Cons object representing the non-degenerate perpendicular constraint. + */ public Cons getNDG_PERP(int t1, int t2, int t3, int t4, Object o1, Object o2, Object o3, Object o4) { if (t1 > t2) { int t = t1; @@ -1633,6 +1965,17 @@ public Cons getNDG_PERP(int t1, int t2, int t3, int t4, Object o1, Object o2, Ob return c1; } + /** + * Creates a non-degenerate collinearity constraint from the given point identifiers and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @return a Cons object representing the non-degenerate collinearity constraint, or null if any two points are equal. + */ public Cons getNDG_COLL(int t1, int t2, int t3, Object o1, Object o2, Object o3) { if (t1 == t2 || t1 == t3 || t2 == t3) return null; Cons c1 = new Cons(Gib.NDG_COLL); @@ -1672,6 +2015,15 @@ public Cons getNDG_COLL(int t1, int t2, int t3, Object o1, Object o2, Object o3) } + /** + * Creates a non-degenerate non-isotropic constraint from two point identifiers and their associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @return a Cons object representing the non-degenerate non-isotropic constraint. + */ public Cons getNDG_NON_ISOTROPIC(int t1, int t2, Object o1, Object o2) { Cons c1 = new Cons(Gib.NDG_NON_ISOTROPIC); if (t1 > t2) { @@ -1690,6 +2042,15 @@ public Cons getNDG_NON_ISOTROPIC(int t1, int t2, Object o1, Object o2) { return c1; } + /** + * Creates a non-degenerate inequality constraint based on two point identifiers and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @return a Cons object representing the non-degenerate inequality constraint. + */ public Cons getNDG_NEQ(int t1, int t2, Object o1, Object o2) { if (t1 > t2) { int t = t1; @@ -1707,6 +2068,13 @@ public Cons getNDG_NEQ(int t1, int t2, Object o1, Object o2) { return c1; } + /** + * Adds a non-degenerate constraint to the specified vector. + * If a similar constraint exists, it avoids duplication or replaces the existing one. + * + * @param c the non-degenerate constraint to add. + * @param v the vector in which the constraint is to be added. + */ public void addNDG(Cons c, Vector v) { if (c == null) return; @@ -1722,6 +2090,13 @@ public void addNDG(Cons c, Vector v) { v.add(c); } + /** + * Checks if the first non-degenerate constraint is considered contained within the second. + * + * @param c the constraint to check for containment. + * @param c1 the constraint that may contain the first. + * @return true if the first constraint is contained within the second, false otherwise. + */ public boolean NDG_Contains(Cons c, Cons c1) // c < c1 { diff --git a/src/main/java/gprover/Gib.java b/src/main/java/gprover/Gib.java index bb5fef85..b6d0ef28 100644 --- a/src/main/java/gprover/Gib.java +++ b/src/main/java/gprover/Gib.java @@ -6,6 +6,15 @@ import java.util.Vector; +/** + * The Gib class provides functionality for geometric computations, + * including operations on angles, lines, circles, triangles, and other + * geometric constructions. + * + *This class is a central component within the geometric prover system, + * facilitating the creation, manipulation, and evaluation of various geometric + * entities and their relationships.
+ */ public class Gib { //********************pred types************************* @@ -339,12 +348,8 @@ public class Gib { protected Cond conc = new Cond(); protected int cons_no = 0; - //***************************end of inputs****************** - protected final static int PFULL = 0; - protected final static int PTRADITION = 1; - //*****************************othres*********************** final protected static ACir test_c = new ACir(); final protected static LLine test_ln = new LLine(); @@ -366,8 +371,10 @@ public class Gib { protected StringBuffer sout = null; protected boolean DEBUG = true; - //*****************************end of othres*********************** - + /** + * Initializes the rule configuration. + * Sets all rules to true and then disables specific rules. + */ public static void initRules() { for (int i = 0; i < RValue.length; i++) RValue[i] = true; @@ -382,6 +389,10 @@ public static void initRules() { } + /** + * Constructs a new Gib instance. + * Initializes all internal data structures and sets default values. + */ public Gib() { co_db = new Cond(); @@ -418,6 +429,10 @@ public Gib() { gt = null; } + /** + * Initializes the database. + * Resets various lists, counters, and clears auxiliary collections. + */ public void init_dbase() { depth = 0; @@ -493,38 +508,44 @@ public void init_dbase() { tm_pr1 = new Cond(); } + /** + * Validates the provided index. + * + * @param i the index to check + * @return true if the index is within valid bounds; false otherwise + */ boolean valid(int i) { if (i == 0 || i > 100) return true; if (i < 0 || i >= RValue.length) return false; return RValue[i - 1]; } - Cond add_e_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - Cond co = new Cond(); - - co.pred = n; - co.no = 0; - co.u.ln = null; - co.p[0] = p1; - co.p[1] = p2; - co.p[2] = p3; - co.p[3] = p4; - co.p[4] = p5; - co.p[5] = p6; - co.p[6] = p7; - co.p[7] = p8; - co.cd = co_db.nx; - return co; - } - + /** + * Retrieves the x-coordinate of the point at the specified index. + * + * @param p the index of the point in the array + * @return the x-coordinate of the point + */ final double VPTX(int p) { return allpts[p].x; } + /** + * Retrieves the y-coordinate of the point at the specified index. + * + * @param p the index of the point in the array + * @return the y-coordinate of the point + */ final double VPTY(int p) { return allpts[p].y; } + /** + * Retrieves the name of the point at the specified index. + * + * @param p the index of the point in the array + * @return the name of the point, or null if the index is negative + */ final String ANAME(int p) { if (p < 0) return null; @@ -539,6 +560,12 @@ final String ANAME(int p) { return null; } + /** + * Searches for a point by its name. + * + * @param s the name to search for + * @return the index of the point if found; otherwise, 0 + */ final int SPT(String s) { if (s == null || s.length() == 0) return 0; @@ -549,28 +576,11 @@ final int SPT(String s) { return 0; } -// final double get_ptx(int i) { -// Pro_point pt = allpts[i]; -// if (pt != null) -// return pt.x; -// else { -// //####### -// //Cm.print(i + " error"); -// return 0.0; -// } -// } -// -// final double get_pty(int i) { -// Pro_point pt = allpts[i]; -// if (pt != null) -// return pt.y; -// else { -// //####### -// //Cm.print(i + " error"); -// return 0.0; -// } -// } - + /** + * Counts the number of defined properties among various entities. + * + * @return the total count of properties + */ final int getNumberofProperties() { int n = 0; MidPt md = all_md.nx; @@ -667,6 +677,12 @@ final int getNumberofProperties() { return n; } + /** + * Retrieves the point at the specified index. + * + * @param i the index of the point in the array + * @return the ProPoint at the specified index + */ final ProPoint APT(int i) { ProPoint pt = allpts[i]; if (pt == null) { @@ -675,22 +691,33 @@ final ProPoint APT(int i) { return pt; } - final int ATYPE(int p, int t) { - return (allpts)[p].type = t; - } - + /** + * Returns the type of the point at the given index. + * + * @param t the index of the point in the array + * @return the type of the point + */ final int ATYPE(int t) { return (allpts)[t].type; } - final int AUX(int p, int t) { - return (allpts)[p].aux = t; - } - + /** + * Retrieves an auxiliary point index from the given point. + * + * @param p the index of the point in the array + * @param i the auxiliary index within the point + * @return the auxiliary point index + */ final int APTS(int p, int i) { return ((allpts)[p].ps[i]); } + /** + * Returns the x-coordinate of the point at the given index. + * + * @param p the index of the point in the allpts array + * @return the x-coordinate of the point, or 0.0 if the point is null + */ final double aptx(int p) { if (allpts[p] != null) return allpts[p].x; @@ -700,6 +727,12 @@ final double aptx(int p) { } } + /** + * Returns the y-coordinate of the point at the given index. + * + * @param p the index of the point in the allpts array + * @return the y-coordinate of the point, or 0.0 if the point is null + */ final double apty(int p) { if (allpts[p] != null) return allpts[p].y; @@ -709,24 +742,35 @@ final double apty(int p) { } } + /** + * Checks if the specified index corresponds to a conclusion. + * + * @param n the index in the allcns array + * @return true if the conclusion exists and is valid; false otherwise + */ final boolean isConclusion(int n) { if (allcns[n] != null) return allcns[n].is_conc(); return false; } - final XTerm P1(int p) { - return null; - } - - final XTerm P2(int p) { - return null; - } - + /** + * Finds the point index by its name. + * + * @param s the name of the point + * @return the index of the point if found; 0 otherwise + */ public int fd_pt(String s) { return SPT(s); } + /** + * Finds a point by its coordinates. + * + * @param x the x-coordinate to match + * @param y the y-coordinate to match + * @return the point if one exists within tolerance; null otherwise + */ public ProPoint fd_pt(double x, double y) { double m, n; for (int i = 1; i <= pts_no; i++) { @@ -738,24 +782,35 @@ public ProPoint fd_pt(double x, double y) { return null; } + /** + * Sets the print mode to output to a string buffer. + */ void setPrintToString() { printype = 1; sout = new StringBuffer();//""; } - void setPrintToScreen() { - printype = 0; - sout = new StringBuffer();//""; - } - + /** + * Disables printing output. + */ public void setNoPrint() { printype = -1; } + /** + * Returns the string buffer containing the file proof. + * + * @return the string buffer with the proof content + */ StringBuffer getFileProve() { return sout; } + /** + * Retrieves and resets the printed output string. + * + * @return the printed output as a string + */ String getPrintedString() { if (sout == null) return ""; String s = sout.toString(); @@ -763,11 +818,21 @@ String getPrintedString() { return s; } + /** + * Prints an error message if debugging is enabled. + * + * @param s the error message to print + */ void eprint(String s) { if (Cm.DEBUG) System.out.println(s); } + /** + * Prints a general message based on the current print type. + * + * @param s the message to print + */ void gprint(String s) { if (printype == 0) { if (Cm.DEBUG) @@ -778,31 +843,50 @@ void gprint(String s) { } } + /** + * Prints a debug message if debugging is enabled. + * + * @param s the debug message to print + */ void debug_print(String s) { if (DEBUG) Cm.print(s); } + /** + * Checks if the proof status is full. + * + * @return true if the proof status is full; false otherwise + */ public boolean isPFull() { return P_STATUS == 0; } - public boolean isPTra() { - return P_STATUS == 1; - } - + /** + * Exits the application with the specified error id. + * + * @param id the error id for the exit process + */ public void gexit(int id) { gprint("exit " + id); Cm.print("Error, exit " + id); } - void gdb_help() { - } - + /** + * Displays the parallel line information. + * + * @param pn the PLine object representing parallel lines + */ void show_pn(PLine pn) { gprint(pn_string(pn)); } + /** + * Returns a formatted string representing the parallel lines in a PLine. + * + * @param pn the PLine object containing lines to be formatted + * @return the formatted string of parallel lines + */ String pn_string(PLine pn) { String s = ""; for (int i = 0; i <= pn.no; i++) { @@ -813,10 +897,23 @@ String pn_string(PLine pn) { return s; } + /** + * Displays the string representation of the given line. + * + * @param ln the LLine object to display + * @param nk flag indicating whether to translate as collinear + */ void show_ln(LLine ln, boolean nk) { gprint(ln_string(ln, nk)); } + /** + * Returns a formatted string representing the line. + * + * @param ln the LLine object to convert to string + * @param nk flag indicating whether to use collinearity translation + * @return the formatted string of the line + */ String ln_string(LLine ln, boolean nk) { int i; if (ln == null) @@ -832,6 +929,12 @@ String ln_string(LLine ln, boolean nk) { } } + /** + * Returns a formatted string representing the perpendicular relationship of a TLine. + * + * @param tn the TLine object to convert to string + * @return the formatted string indicating perpendicularity + */ String tn_string(TLine tn) { LLine l1, l2; @@ -844,10 +947,20 @@ String tn_string(TLine tn) { return s; } + /** + * Displays the formatted string for the given TLine. + * + * @param tn the TLine object representing perpendicular lines + */ void show_tn(TLine tn) { gprint(tn_string(tn)); } + /** + * Displays the angle represented by an AngTn object as a combination of two angle components. + * + * @param atn the AngTn object containing two sets of line pairs forming an angle + */ void show_atn(AngTn atn) { show_agll(atn.ln1, atn.ln2); gprint(" + "); @@ -855,6 +968,11 @@ void show_atn(AngTn atn) { gprint(" = 90"); } + /** + * Displays the segments contained in a CSegs object. + * + * @param cg the CSegs object holding congruent segments + */ void show_cseg(CSegs cg) { if (cg.no < 0) { gprint("NULL"); @@ -867,6 +985,11 @@ void show_cseg(CSegs cg) { } } + /** + * Displays the congruent segment information for the given CongSeg object. + * + * @param cg the CongSeg object containing congruence data + */ void show_cg(CongSeg cg) { if (cg == null) { Cm.print("cong_seg is null"); @@ -920,10 +1043,27 @@ void show_cg(CongSeg cg) { } } + /** + * Prints the formatted angle string for the angle defined by four points. + * + * @param p1 the first vertex of the angle + * @param p2 the second vertex of the angle + * @param p3 the third vertex of the angle + * @param p4 the fourth vertex of the angle + */ void print_fang(int p1, int p2, int p3, int p4) { gprint(get_fang_str(p1, p2, p3, p4)); } + /** + * Returns a formatted string representing an angle defined by four points. + * + * @param p1 the first vertex of the angle + * @param p2 the second vertex of the angle + * @param p3 the third vertex of the angle + * @param p4 the fourth vertex of the angle + * @return the formatted angle string + */ String get_fang_str(int p1, int p2, int p3, int p4) { int p0; @@ -950,11 +1090,23 @@ String get_fang_str(int p1, int p2, int p3, int p4) { } + /** + * Returns the name of the point identified by its index. + * + * @param p the index of the point + * @return the name of the point, or an empty string if the index is zero + */ final String pt_name(int p) { if (p != 0) return (APT(p).name); else return (""); } + /** + * Displays the angle between two lines by determining their intersection point. + * + * @param ln1 the first LLine object + * @param ln2 the second LLine object + */ final public void show_agll(LLine ln1, LLine ln2) { // overrited. int n = inter_lls(ln1, ln2); if (n == 0) @@ -966,6 +1118,11 @@ final public void show_agll(LLine ln1, LLine ln2) { // overrited. } } + /** + * Displays a formatted representation of an angle expressed by an Angles object. + * + * @param as the Angles object containing the angle representation + */ final void show_as(Angles as) { if (as == null) return; show_agll(as.l1, as.l2); @@ -973,16 +1130,32 @@ final void show_as(Angles as) { show_agll(as.l3, as.l4); } + /** + * Returns a formatted string representing the midpoint relationship. + * + * @param md the MidPt object containing midpoint data + * @return the formatted midpoint string + */ final String md_print(MidPt md) { String st = GExpert.getTranslationViaGettext("{0} is the midpoint of {1}", ANAME(md.m), ANAME(md.a) + ANAME(md.b)); return st; } + /** + * Displays a formatted representation of the midpoint. + * + * @param md the midpoint to be displayed + */ final void show_md(MidPt md) { gprint(md_print(md)); } + /** + * Displays a formatted representation of the ratio segment. + * + * @param ra the ratio segment to be displayed + */ final void show_ra(RatioSeg ra) { if (show_dtype != 0) { gprint("[" + ra.type + "]:"); @@ -993,6 +1166,12 @@ final void show_ra(RatioSeg ra) { gprint(str); } + /** + * Returns a string representation of the circle. + * + * @param cr the circle object + * @return the formatted circle string + */ final String cr_string(ACir cr) { char i; if (cr == null) { @@ -1015,10 +1194,20 @@ final String cr_string(ACir cr) { return GExpert.getTranslationViaGettext("Circle {0}", s); } + /** + * Displays the circle using its string representation. + * + * @param cr the circle object to be displayed + */ final void show_cr(ACir cr) { gprint(cr_string(cr)); } + /** + * Displays a formatted representation of the similar triangle. + * + * @param st the similar triangle to be displayed + */ final void show_ct(SimTri st) { gprint(Cm.s2722); if (show_dtype != 0) { @@ -1030,15 +1219,11 @@ final void show_ct(SimTri st) { gprint(s); } - final void show_st(SimTri st) { - gprint(Cm.s2720); - - String s = "[" + st.dr + "." + - ANAME(st.p1[0]) + ANAME(st.p1[1]) + ANAME(st.p1[2]) + - "." + ANAME(st.p2[0]) + ANAME(st.p2[1]) + ANAME(st.p2[2]) + "] "; - gprint(s); - } - + /** + * Displays a formatted representation of a set of similar triangles. + * + * @param st the set of similar triangles to be displayed + */ final void show_sts(STris st) { String s = ""; int i = 0; @@ -1050,17 +1235,33 @@ final void show_sts(STris st) { gprint(s); } - + /** + * Exits the system with the specified exit status. + * + * @param v the exit status code + */ final public void exit(int v) { Cm.print("System exit: " + v); System.exit(v); } + /** + * Prints an error message and terminates the program. + * + * @param s the error message to display before exiting + */ final public void gerror(String s) { Cm.print("Error: " + s); System.exit(0); } + /** + * Returns a common point between two lines, or 0 if none exists. + * + * @param l1 the first line + * @param l2 the second line + * @return the common point of the two lines, or 0 if there is no intersection + */ final int inter_lls(LLine l1, LLine l2) { int i, j; if (l1 == null || l2 == null) return (0); @@ -1072,6 +1273,13 @@ final int inter_lls(LLine l1, LLine l2) { return (0); } + /** + * Returns the first point from the line that is not equal to the specified point. + * + * @param l1 the line to search + * @param p1 the point to be excluded + * @return the first point in the line that differs from p1, or 0 if none found + */ final int get_lpt1(LLine l1, int p1) { char j; for (j = 0; j <= l1.no; j++) { @@ -1080,6 +1288,14 @@ final int get_lpt1(LLine l1, int p1) { return (0); } + /** + * Returns the first point from the line that is different from both specified points. + * + * @param l1 the line to search + * @param p1 the first point to be excluded + * @param p2 the second point to be excluded + * @return the first point in the line that differs from both p1 and p2, or 0 if none found + */ final int get_lpt2(LLine l1, int p1, int p2) { char j; for (j = 0; j <= l1.no; j++) { @@ -1088,6 +1304,12 @@ final int get_lpt2(LLine l1, int p1, int p2) { return (0); } + /** + * Returns the default condition for the specified geometric class. + * + * @param cc the geometric class object + * @return a default condition associated with the provided class, or null if unsupported + */ final public Cond getDefaultCond(CClass cc) { Cond co = new Cond(); co.pred = 0; @@ -1208,6 +1430,17 @@ final public Cond getDefaultCond(CClass cc) { //show /////////////////////////////////// + /** + * Computes the orientation of two triangles defined by their vertices. + * + * @param p1 the first point of the first triangle + * @param p2 the second point of the first triangle + * @param p3 the third point of the first triangle + * @param p4 the first point of the second triangle + * @param p5 the second point of the second triangle + * @param p6 the third point of the second triangle + * @return 1 if the triangles share the same orientation, -1 otherwise + */ int check_tri_dr(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = (aptx(p2) - aptx(p1)) * (apty(p3) - apty(p1)) - (aptx(p3) - aptx(p1)) * (apty(p2) - apty(p1)); @@ -1221,34 +1454,91 @@ int check_tri_dr(int p1, int p2, int p3, int p4, int p5, int p6) { return -1; } + /** + * Disables further checking and logs a check error. + */ final void add_checkError() { ck_value = false; gprint("On Check Error!"); } + /** + * Determines whether the three given points are collinear. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @return true if the points are collinear; false otherwise + */ final boolean check_coll(int p1, int p2, int p3) { return Math.abs((apty(p2) - apty(p1)) * (aptx(p3) - aptx(p1)) - (aptx(p2) - aptx(p1)) * (apty(p3) - apty(p1))) < ZERO; } + /** + * Determines whether the four given points are collinear by checking if both + * the third and fourth points lie on the line through the first two points. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @param p4 index of the fourth point + * @return true if all points are collinear; false otherwise + */ final boolean check_coll(int p1, int p2, int p3, int p4) { return check_coll(p1, p2, p3) && check_coll(p1, p2, p4); } + /** + * Checks whether two lines are parallel. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are parallel; false otherwise + */ final boolean check_para(LLine l1, LLine l2) { return check_para(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1]); } + /** + * Checks whether two segments defined by their endpoints are parallel. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the segments are parallel; false otherwise + */ final boolean check_para(int p1, int p2, int p3, int p4) { return Math.abs((apty(p2) - apty(p1)) * (aptx(p4) - aptx(p3)) - (aptx(p2) - aptx(p1)) * (apty(p4) - apty(p3))) < ZERO; } + /** + * Determines whether two segments defined by their endpoints are perpendicular. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the segments are perpendicular; false otherwise + */ final boolean check_perp(int p1, int p2, int p3, int p4) { return Math.abs((apty(p2) - apty(p1)) * (apty(p4) - apty(p3)) + (aptx(p4) - aptx(p3)) * (aptx(p2) - aptx(p1))) < ZERO; } + /** + * Checks if the angles formed by points (p1, p2, p3) and (p4, p5, p6) are equal. + * + * @param p1 index of the vertex for the first angle + * @param p2 index of the first arm point for the first angle + * @param p3 index of the second arm point for the first angle + * @param p4 index of the vertex for the second angle + * @param p5 index of the first arm point for the second angle + * @param p6 index of the second arm point for the second angle + * @return true if the two angles are equal within a tolerance; false otherwise + */ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("null point in eqangle"); @@ -1257,11 +1547,35 @@ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6) return Math.abs(getAngleValue(p1, p2, p2, p3) - getAngleValue(p4, p5, p5, p6)) < ZERO; } + /** + * Checks whether the sum of the two angles defined by the given points equals 90°. + * + * @param p1 index of the vertex for the first angle + * @param p2 index of an arm point for the first angle + * @param p3 index of the other arm point for the first angle + * @param p4 index of the vertex for the second angle + * @param p5 index of an arm point for the second angle + * @param p6 index of the other arm point for the second angle + * @return true if the sum of angles is 90° (within tolerance); false otherwise + */ protected boolean check_atn(int p1, int p2, int p3, int p4, int p5, int p6) { double r = getAngleValue(p1, p2, p3) + getAngleValue(p4, p5, p6); return Math.abs(r - Math.PI / 2) < ZERO || Math.abs(r + Math.PI / 2) < ZERO; } + /** + * Checks if two angles defined by four points are equal or supplementary. + * + * @param p1 index of the first point of the first angle + * @param p2 index of the second point of the first angle + * @param p3 index of the third point of the first angle + * @param p4 index of the fourth point of the first angle + * @param p5 index of the first point of the second angle + * @param p6 index of the second point of the second angle + * @param p7 index of the third point of the second angle + * @param p8 index of the fourth point of the second angle + * @return true if the angles are equal or supplementary (within tolerance); false otherwise + */ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("null point in eqangle"); @@ -1273,6 +1587,19 @@ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6, return r < ZERO || Math.abs(r - Math.PI) < ZERO; } + /** + * Checks if two angle values computed via a transformed approach are equal. + * + * @param p1 index of the first point of the first angle + * @param p2 index of the second point of the first angle + * @param p3 index of the third point of the first angle + * @param p4 index of the fourth point of the first angle + * @param p5 index of the first point of the second angle + * @param p6 index of the second point of the second angle + * @param p7 index of the third point of the second angle + * @param p8 index of the fourth point of the second angle + * @return true if the absolute transformed angle values are equal (within tolerance); false otherwise + */ protected boolean check_eqangle_t(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("Check EQANgle ==0"); @@ -1285,12 +1612,28 @@ protected boolean check_eqangle_t(int p1, int p2, int p3, int p4, int p5, int p6 return r < ZERO; } + /** + * Determines whether the angle formed by three points is a right angle (90°). + * + * @param p1 index of the vertex of the angle + * @param p2 index of the first arm point + * @param p3 index of the second arm point + * @return true if the angle is 90° (within tolerance); false otherwise + */ public boolean check_angle_ls_90(int p1, int p2, int p3) { double r1 = getAngleValue(p1, p2, p3); return Math.abs(Math.abs(r1) - Math.PI / 2) < ZERO; } + /** + * Determines if a point lies strictly between two other points along both axes. + * + * @param p1 index of the point to test + * @param p2 index of the first boundary point + * @param p3 index of the second boundary point + * @return true if p1 is inside the interval defined by p2 and p3; false otherwise + */ protected boolean x_inside(int p1, int p2, int p3) { double r1 = ((aptx(p1) - aptx(p2)) * (aptx(p1) - aptx(p3))); double r2 = ((apty(p1) - apty(p2)) * (apty(p1) - apty(p3))); @@ -1300,6 +1643,17 @@ protected boolean x_inside(int p1, int p2, int p3) { return false; } + /** + * Computes an angle value using transformed points. + * + * The method considers special ordering of the points to compute the appropriate angle. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @param p4 index of the fourth point + * @return the computed angle value + */ protected double getAngleValue_t(int p1, int p2, int p3, int p4) { int p0; if (p1 == p4) { @@ -1324,6 +1678,17 @@ protected double getAngleValue_t(int p1, int p2, int p3, int p4) { return getAngleValue(p1, p2, p3, p4); } + /** + * Checks if the distance between two pairs of points are equal after scaling. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @param t1 scaling factor for the first segment + * @param t2 scaling factor for the second segment + * @return true if the scaled distances are equal (within tolerance); false otherwise + */ protected boolean check_eqdistance(int p1, int p2, int p3, int p4, double t1, double t2) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1339,6 +1704,15 @@ protected boolean check_eqdistance(int p1, int p2, int p3, int p4, double t1, do return Math.abs(r) < ZERO; } + /** + * Checks if the distances between two pairs of points are equal. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the distances are equal (within tolerance); false otherwise + */ protected boolean check_eqdistance(int p1, int p2, int p3, int p4) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1352,14 +1726,45 @@ protected boolean check_eqdistance(int p1, int p2, int p3, int p4) { - Math.pow(x4 - x3, 2) - Math.pow(y4 - y3, 2)) < ZERO; } + /** + * Validates whether the ratio of the squared lengths of two segments remain equal. + * + * @param a index of the first point of the first segment + * @param b index of the second point of the first segment + * @param c index of the first point of the second segment + * @param d index of the second point of the second segment + * @param p index of the first point of the third segment + * @param q index of the second point of the third segment + * @param r index of the first point of the fourth segment + * @param s index of the second point of the fourth segment + * @return true if the products of squared lengths are equal (within tolerance); false otherwise + */ protected boolean check_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { return Math.abs(length2(a, b) * length2(r, s) - length2(c, d) * length2(p, q)) < ZERO; } + /** + * Checks if two pairs of points are equal regardless of order. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return true if the pairs (p1, p2) and (p3, p4) are equal in any order, false otherwise + */ public boolean ck_4peq(int p1, int p2, int p3, int p4) { return p1 == p3 && p2 == p4 || p1 == p4 && p2 == p3; } + /** + * Evaluates directional compatibility between two segments defined by two pairs of points. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + * @return true if the segments satisfy specific directional conditions, false otherwise + */ public boolean ck_dr(int p1, int p2, int p3, int p4) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1374,6 +1779,13 @@ public boolean ck_dr(int p1, int p2, int p3, int p4) { return (r1 > 0 && r2 > 0) || (r1 == 0 && r2 > 0) || (r1 > 0 && r2 == 0); } + /** + * Calculates the squared Euclidean distance between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the squared distance between p1 and p2 + */ protected double length2(int p1, int p2) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1382,10 +1794,26 @@ protected double length2(int p1, int p2) { return Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2); } + /** + * Computes the angle value at the middle point defined by three points. + * + * @param p1 the first point + * @param p2 the vertex point where the angle is measured + * @param p3 the third point + * @return the angle value at p2 (in radians) + */ protected double getAngleValue(int p1, int p2, int p3) { return getAngleValue(p1, p2, p3, p2); } + /** + * Determines the angle formed at a common point by two lines. + * + * @param p the intersection point of the lines + * @param l1 the first line + * @param l2 the second line + * @return the angle between l1 and l2 at point p (in radians) + */ protected double getAngleValue(int p, LLine l1, LLine l2) { int a, b; if (p == l1.pt[0]) @@ -1399,6 +1827,15 @@ protected double getAngleValue(int p, LLine l1, LLine l2) { return getAngleValue(a, p, b, p); } + /** + * Checks if the angle formed by three points is approximately equal to a given value. + * + * @param a the first point + * @param b the vertex point where the angle is measured + * @param c the third point + * @param v the target angle value in degrees + * @return true if the measured angle is approximately equal to v, false otherwise + */ protected boolean check_ateq(int a, int b, int c, int v) { double r = getAngleValue(a, b, c); double x = Math.abs(r * A_180 / Math.PI - v); @@ -1409,16 +1846,15 @@ protected boolean check_ateq(int a, int b, int c, int v) { return d; } - protected boolean check_tn_eq(LLine l1, LLine l2, LLine l3, LLine l4, int p1, int p2) { - double r = getAngleValue(p1, l1, l2); - double r1 = getAngleValue(p2, l3, l4); - if (Math.abs(r - r1) < 0.01) return true; - if (Math.abs(Math.abs(r - r1) - Math.PI) < ZERO) - return false; - else - return false; - } - + /** + * Computes the angle difference between the lines defined by two point pairs. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return the difference between the angles (in radians) of the two lines + */ protected double getAngleValue(int p1, int p2, int p3, int p4) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0) { int k = 0; @@ -1467,6 +1903,17 @@ protected double getAngleValue(int p1, int p2, int p3, int p4) { return dr; } + /** + * Checks whether the triangles defined by the given points are similar. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are similar based on their side ratios, false otherwise + */ boolean check_simtri(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = getRatio(p1, p2, p4, p5); @@ -1476,6 +1923,17 @@ boolean check_simtri(int p1, int p2, int p3, int p4, int p5, int p6) { return (Math.abs(r1 - r2) < ZERO) && (Math.abs(r1 - r3) < ZERO); } + /** + * Checks whether two triangles are congruent by comparing side ratios and one corresponding side length. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are congruent, false otherwise + */ boolean check_congtri(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = getRatio(p1, p2, p4, p5); @@ -1486,6 +1944,14 @@ boolean check_congtri(int p1, int p2, int p3, int p4, int p5, int p6) { (Math.abs(length2(p1, p2) - length2(p4, p5)) < ZERO); } + /** + * Determines if the first point is the midpoint of the segment defined by the other two points. + * + * @param p1 the point to test as the midpoint + * @param p2 the first endpoint of the segment + * @param p3 the second endpoint of the segment + * @return true if p1 is the midpoint of p2 and p3, false otherwise + */ boolean check_mid(int p1, int p2, int p3) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1496,13 +1962,28 @@ boolean check_mid(int p1, int p2, int p3) { return Math.abs(x2 + x3 - 2 * x1) < ZERO && Math.abs(y2 + y3 - 2 * y1) < ZERO; } + /** + * Calculates the ratio of the squared distances between two pairs of points. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + * @return the ratio of the squared distance between (p1, p2) and (p3, p4) + */ double getRatio(int p1, int p2, int p3, int p4) { double r1 = (Math.pow(aptx(p1) - aptx(p2), 2) + Math.pow(apty(p1) - apty(p2), 2)) / (Math.pow(aptx(p3) - aptx(p4), 2) + Math.pow(apty(p3) - apty(p4), 2)); return r1; } - + /** + * Computes the integer square root of a number. + * Returns the square root if the number is a perfect square; otherwise, returns -1. + * + * @param n the number to compute the square root of + * @return the integer square root if it exists; -1 otherwise + */ int Sqrt(int n) { int i = 1; while (i * i < n) @@ -1512,6 +1993,18 @@ int Sqrt(int n) { } + /** + * Checks if two triangles, defined by three vertex points each, are identical. + * The comparison is independent of the vertex order. + * + * @param p1 vertex of the first triangle + * @param p2 vertex of the first triangle + * @param p3 vertex of the first triangle + * @param q1 vertex of the second triangle + * @param q2 vertex of the second triangle + * @param q3 vertex of the second triangle + * @return true if the triangles are the same; false otherwise + */ final public boolean same_tri(int p1, int p2, int p3, int q1, int q2, int q3) { if ( p1 == q1 && (p2 == q2 && p3 == q3 || p2 == q3 && p3 == q2) || @@ -1521,19 +2014,10 @@ final public boolean same_tri(int p1, int p2, int p3, int q1, int q2, int q3) { return false; } - - public void add_ast(Angles as) { - AngSt ast = all_ast.nx; - while (ast != null) { - if (ast.addAngle(as)) - return; - ast = ast.nx; - } - ast = new AngSt(); - ast.addAngle(as); - return; - } - + /** + * Collects angle expressions into a collection. + * Processes the global list of angle objects and groups unique angle expressions. + */ public void collect_angst() { Vector v = new Vector(); @@ -1563,6 +2047,13 @@ public void collect_angst() { } } + /** + * Adds an angle expression to a new angle structure. + * Updates the global angle structure list with the provided angle. + * + * @param ag the angle expression to add + * @param v a vector used for collecting angle structures + */ public void addAngst(Angles ag, Vector v) { AngSt a = new AngSt(); a.addAngle(ag); @@ -1570,6 +2061,12 @@ public void addAngst(Angles ag, Vector v) { last_ast = a; } + /** + * Attempts to insert an angle expression into the existing angle structure list. + * + * @param ag the angle expression to insert + * @return true if the angle was merged with an existing structure; false otherwise + */ public boolean insertAngle(Angles ag) { if (ag.l1 == ag.l3 && ag.l2 == ag.l4 || ag.l1 == ag.l2 && ag.l3 == ag.l4) return true; @@ -1584,6 +2081,13 @@ public boolean insertAngle(Angles ag) { return false; } + /** + * Finds and returns the angle structure that contains the specified lines. + * + * @param l1 the first line to search within angle structures + * @param l2 the second line to search within angle structures + * @return the angle structure containing the lines, or null if not found + */ public AngSt fd_ast(LLine l1, LLine l2) { AngSt ast = all_ast.nx; while (ast != null) { @@ -1592,9 +2096,14 @@ public AngSt fd_ast(LLine l1, LLine l2) { } return null; } - //////////////////////////////////////////////////////////////////////////////////// - /// auxpoint list + /** + * Computes the greatest common divisor (GCD) of two long integers using the Euclidean algorithm. + * + * @param l1 the first number + * @param l2 the second number + * @return the GCD of the two numbers + */ long gcd(long l1, long l2) { long l; if (l1 < 0L) { @@ -1622,11 +2131,13 @@ long gcd(long l1, long l2) { protected Vector vauxpts = new Vector(); protected Vector vauxptf = new Vector(); - int get_auxptn() { - return vauxpts.size(); - } - - final public static void setValue(int n, boolean v) { + /** + * Sets the boolean flag at a given index in a shared values array. + * + * @param n the 1-based index of the value to set + * @param v the boolean value to set + */ + public static void setValue(int n, boolean v) { RValue[n - 1] = v; } } diff --git a/src/main/java/gprover/Gr.java b/src/main/java/gprover/Gr.java index a44c6b59..36802c3e 100644 --- a/src/main/java/gprover/Gr.java +++ b/src/main/java/gprover/Gr.java @@ -1,197 +1,22 @@ package gprover; + /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 15:02:14 - * To change this template use File | Settings | File Templates. + * Represents group related polynomial operations. */ public class Gr extends Poly { - ElTerm rev_elim(ElTerm v) - { - XTerm p; - p = v.p1; - v.p1 = v.p2; - v.p2 = p; - return (v); - } - - -/* ps operations */ - DTerm ps_member(XTerm p, DTerm ps) - { - for (; ps != null; ps = ps.nx) { - if (eq_poly(p, ps.p)) return (ps); - } - return (null); - } - - DTerm ps_inter(DTerm ps1, DTerm ps2) - { - DTerm ps, ps0, ps3; - - if (ps1 == null) - return (null); - else if (ps2 == null) - return (null); - else { - ps = new DTerm(); - ps.nx = null; - ps0 = ps; - while (ps1 != null) { - ps3 = ps_member(ps1.p, ps2); - if (ps3 != null) { - ps0.nx = get_dt(min((ps1.deg), (ps3.deg)), cp_poly(ps1.p), null); - ps0 = ps0.nx; - } - ps1 = ps1.nx; - } - return (ps.nx); - } - } - - DTerm ps_diff2(DTerm ps1, DTerm ps2) /*destructive for ps1 */ - { - DTerm ps, ps0, ps3; - - if (ps1 == null) - return (null); - else if (ps2 == null) - return (ps1); - else { - ps = new DTerm(); - ps.nx = ps1; - while (ps2 != null) { - ps0 = ps; - ps3 = ps0.nx; - while ((ps3 != null) && !(eq_poly(ps2.p, ps3.p))) { - ps0 = ps3; - ps3 = ps3.nx; - } - if (ps3 != null) { - ps3.deg -= ps2.deg; - if (ps3.deg <= 0) { - ps0.nx = ps3.nx; - put_p(ps3.p); - put_d(ps3); - } - } - ps2 = ps2.nx; - } - return (ps.nx); - } - } - - DTerm ps_append(DTerm ps1, DTerm ps2) - { - DTerm ps; - if (ps1 == null) - return (ps2); - else if (ps2 == null) - return (ps1); - else { - for (ps = ps1; ps.nx != null; ps = ps.nx) { - } - ps.nx = ps2; - return (ps1); - } - } - - DTerm ps_diff(DTerm ps1, DTerm ps2) - { - DTerm ps, ps0; - ps = new DTerm(); - if (ps1 == null) return (null); - if (ps2 == null) return (ps1); - { - ps.nx = ps1; - ps0 = ps; - while (ps1 != null) { - if (ps_member(ps1.p, ps2) != null) { - ps0.nx = ps1.nx; - put_p(ps1.p); - put_d(ps1); - ps1 = ps0.nx; - } else { - ps0 = ps1; - ps1 = ps0.nx; - } - } - return (ps.nx); - } - } - - DTerm ps_union(DTerm ps1, DTerm ps2) -//dterm ps1, ps2; - { - if (ps1 == null) return (ps2); - if (ps2 == null) return (ps1); - ps2 = ps_diff(ps2, ps1); - return (ps_append(ps1, ps2)); - } - - int ps_term1(DTerm dp) { - int k = 0; - for (DTerm ps = dp; ps != null; ps = ps.nx) { - if (!npoly(ps.p)) k++; - } - return k; - } - - - XTerm ps_plus(DTerm dp) - { - XTerm p1; - DTerm dp1; - - p1 = get_n(0L); - while (dp != null) { - if (dp.deg <= 0) { - put_p(dp.p); - } else if (dp.deg == 1) - p1 = pplus(p1, dp.p); - else - p1 = pplus(p1, ppower(dp.p, dp.deg)); - dp1 = dp; - dp = dp.nx; - put_d(dp1); - } - return (p1); - } - - XTerm ps_times(DTerm dp) - { - XTerm p1; - DTerm dp1; - - p1 = get_n(1L); - while (dp != null) { - if (dp.deg <= 0) { - put_p(dp.p); - } else if (dp.deg == 1) - p1 = ptimes(p1, dp.p); - else - p1 = ptimes(p1, ppower(dp.p, dp.deg)); - dp1 = dp; - dp = dp.nx; - put_d(dp1); - } - return (p1); - } - -/* gr operations */ - - GrTerm cp_gr(GrTerm gr) - { - GrTerm gr1 = mk_gr(gr.c1, gr.ps1, gr.c2, gr.ps2, gr.c, gr.nx); - if (gr.c == 0) - gr1.ps = gr.ps; - else - gr1.el = gr.el; - return (gr1); - } + /** + * Creates a new GrTerm object with the specified parameters. + * + * @param c1 the first coefficient + * @param ps1 the first polynomial term + * @param c2 the second coefficient + * @param ps2 the second polynomial term + * @param c the constant term + * @param nx the next GrTerm in the list + * @return the created GrTerm object + */ GrTerm mk_gr(long c1, DTerm ps1, long c2, DTerm ps2, int c, GrTerm nx) { GrTerm gr = new GrTerm(); gr.c1 = c1; @@ -203,6 +28,15 @@ GrTerm mk_gr(long c1, DTerm ps1, long c2, DTerm ps2, int c, GrTerm nx) { return (gr); } + /** + * Creates a new GrTerm object with the specified coefficients and polynomial terms. + * + * @param c1 the first coefficient + * @param p1 the first polynomial term + * @param c2 the second coefficient + * @param p2 the second polynomial term + * @return the created GrTerm object + */ GrTerm mk_gr1(long c1, XTerm p1, long c2, XTerm p2) { GrTerm gr; gr = new GrTerm(); @@ -220,340 +54,4 @@ GrTerm mk_gr1(long c1, XTerm p1, long c2, XTerm p2) { gr.ps = null; return (gr); } - - int gr_length(GrTerm gr) - { - DTerm ps; - int k, m = 0; - for (ps = gr.ps1; ps != null; ps = ps.nx) { - k = plength(ps.p); - if (k > m) m = k; - } - for (ps = gr.ps2; ps != null; ps = ps.nx) { - k = plength(ps.p); - if (k > m) m = k; - } - return (m); - } - - void put_gr(GrTerm gr) - { - DTerm ps, ps1; - ps = gr.ps1; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - ps = gr.ps2; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - if (gr.c == -1) { - ps = gr.ps; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - } else if (gr.c > 0) { - ElTerm el, e1; - el = gr.el; - while (el != null) { - put_p(el.p1); - put_p(el.p2); - e1 = el; - el = el.nx; - //free((el_term)e1); - } - } - //free((gr_term)gr); - } - - -/* simplification */ - static DTerm ps_d1, ps_d2; - - GrTerm simp_gr(GrTerm gr) { - DTerm ps0, ps1, ps2, ps3; - XTerm p1, p2; - GrTerm gr0; - - if (num_zop(gr.c1) && num_zop(gr.c2)) return (null); - - ps1 = ps_simp(cp_pols(gr.ps1)); - ps2 = ps_simp(cp_pols(gr.ps2)); - - /*printf("simplfi_gr\n"); - print_gr(gr); - printf("\n sps1: ()"); print_ps(ps1); - printf("\n sps2: ()"); print_ps(ps2); printf("\n"); - */ - ps0 = null; - if ((num_zop(gr.c1) || pzerop(ps1.p)) && - (num_zop(gr.c2) || pzerop(ps2.p))) { - put_ps(ps1); - put_ps(ps2); - gr0 = mk_gr(mk_num(0L), null, mk_num(0L), null, -2, null); - gr0.ps = null; - } else if (num_zop(gr.c1) || pzerop(ps1.p)) { - put_ps(ps1); - gr0 = mk_gr(mk_num(0L), null, mk_num(1L), ps2, -2, null); - gr0.ps = null; - if (ps_term1(ps2) <= ps_term1(gr.ps2)) { - put_ps(ps2); - return (null); - } - } else if (num_zop(gr.c2) || pzerop(ps2.p)) { - put_ps(ps2); - if (ps_term1(ps1) <= ps_term1(gr.ps1)) { - put_ps(ps1); - return (null); - } - gr0 = mk_gr(mk_num(1L), ps1, mk_num(0L), null, -2, null); - gr0.ps = null; - } else { - ps1 = get_dt(1, get_num(gr.c1), ps1); - ps2 = get_dt(1, get_num(gr.c2), ps2); - ps3 = ps_div(ps1, ps2); - if (ps3 != null) { - ps1 = ps_d1; - ps2 = ps_d2; - ps0 = ps_append(ps0, ps3); - } - ps3 = ps_div(ps2, ps1); - if (ps3 != null) { - ps2 = ps_d1; - ps1 = ps_d2; - ps0 = ps_append(ps0, ps3); - } - if (ps0 == null) { - put_ps(ps1); - put_ps(ps2); - return (null); - } - p1 = ps1.p; - p2 = ps2.p; - gr0 = mk_gr(p1.c, ps1.nx, p2.c, ps2.nx, -1, null); - gr0.ps = ps0; - } - /*printf("\nsimplfi_gr out:\n"); print_gr(gr0);printf("\n"); */ - return (gr0); - } - - DTerm ps_div(DTerm ps1, DTerm ps2) - { - DTerm ps_1, ps_0, ps00, ps02, ps3, ps4; - XTerm p1, p2; - int d; - long c; - -/* printf("\nps_div\n");print_ps(ps1); printf("\n\n");print_ps(ps2); */ - - if (ps1 == null || ps2 == null) return (null); - ps_0 = new DTerm(); - ps_0.nx = null; - ps00 =ps_0; - - ps4 = ps2; - ps02 = ps2; - while (ps02.nx != null) ps02 = ps02.nx; - ps_1 = new DTerm(); - while (ps4 != null) { - ps3 = ps1; - ps_1.nx = null; - do { - if (ps3.deg > 0) { - if (npoly(ps3.p) && npoly(ps4.p)) { - p1 = ps3.p; - p2 = ps4.p; - c = num_gcd(p1.c, p2.c); - if (!num_unit(c)) { - d = min(ps4.deg, ps3.deg); - ps4.deg -= d; - ps3.deg -= d; - ps00.nx = get_dt(d, get_num(c), null); - ps00 = ps00.nx; - if (!num_eq(p1.c, c)) { - ps_1.nx = get_dt(d, get_num(num_d(p1.c, c)), ps_1.nx); - } - if (!num_eq(p2.c, c)) { - ps02.nx = get_dt(d, get_num(num_d(p2.c, c)), null); - ps02 = ps02.nx; - } - } - } else if (npoly(ps3.p)) { - } else if (npoly(ps4.p)) { - } else { - p1 = pdiv(cp_poly(ps3.p), ps4.p); - if (p1 != null) { - d = min(ps4.deg, ps3.deg); - ps4.deg -= d; - ps3.deg -= d; - ps00.nx = get_dt(d, cp_poly(ps4.p), null); - ps00 = ps00.nx; - if (p1.var == null) { - if (!num_unit(p1.c)) { - gerror("ps_div\n"); - return null; - } - put_x(p1); - } else - ps_1.nx = get_dt(d, p1, ps_1.nx); - } - } - } - ps3 = ps3.nx; - } while (ps3 != null && ps4.deg > 0); - if (ps_1.nx != null) { - ps1 = ps_red(ps_append(ps1, ps_1.nx)); - } - ps4 = ps4.nx; - } - - if (ps_0.nx == null) { - return (null); - } - ps_d1 = ps_red(ps1); - ps_d2 = ps_red(ps2); - return (ps_0.nx); - } - - DTerm ps_red(DTerm ps) - { - DTerm ps_t, ps1, ps2, ps3; - XTerm p1; - long c = mk_num(1L); - ps_t = new DTerm(); - ps_t.nx = ps; - ps1 =ps_t; - ps2 = ps1.nx; - while (ps2 != null) { - if (ps2.deg <= 0) { - ps3 = ps2; - ps2 = ps2.nx; - ps1.nx = ps2; - put_p(ps3.p); - put_d(ps3); - } else if (npoly(ps2.p)) { - p1 = ps2.p; - c = num_t(c, lpower(p1.c, ps2.deg)); - ps3 = ps2; - ps2 = ps2.nx; - ps1.nx = ps2; - put_p(ps3.p); - put_d(ps3); - } else { - ps1 = ps2; - ps2 = ps2.nx; - } - } - return (get_dt(1, get_num(c), ps_t.nx)); - } - - DTerm ps_simp(DTerm ps) - { - DTerm ps_t, ps0, ps1, ps2, ps3; - XTerm p1; - int sn = 1; - ps_t = new DTerm(); - ps_t.nx = null; - ps1 = ps_t; - while (ps != null) { - ps2 = vfactor(ps.p); - p1 = ps2.p; - if (num_zop(p1.c)) { - ps3 = ps2.nx; - put_x(p1); - put_d(ps2); - sn = 0; - } else if (num_unit(p1.c)) { - ps3 = ps2.nx; - put_x(p1); - put_d(ps2); - } else { - ps3 = ps2; - } - while (ps3 != null) { - ps3.deg *= ps.deg; - ps2 = ps_t.nx; - while ((ps2 != null) && !(eq_poly(ps2.p, ps3.p))) ps2 = ps2.nx; - if (ps2 != null) { - put_p(ps3.p); - ps2.deg += ps3.deg; - ps0 = ps3; - ps3 = ps3.nx; - put_d(ps0); - } else { - ps1.nx = ps3; - ps1 = ps3; - ps3 = ps3.nx; - ps1.nx = null; - } - } - ps2 = ps; - ps = ps.nx; - put_d(ps2); - } - if (sn == 0) { - put_ps(ps_t.nx); - return (get_dt(1, get_n(0L), null)); - } - if (ps_t.nx == null) ps_t.nx = get_dt(1, get_n(1L), null); - return (ps_t.nx); - } - -/*destructive for p*/ - DTerm vfactor(XTerm p) { - DTerm ps, ps1, ps2; - XTerm p1; - int d1; - long c = mk_num(1L); - - ps = new DTerm(); - ps.nx = null; - ps1 = ps; - p1 = p; - while (p1.var != null) { - d1 = mdeg(p, p1.var); -/* printf("pdeg: %d\n",d1); */ - if (d1 > 0) { - ps1.nx = get_dt(d1, get_m(p1.var), null); - ps1 = ps1.nx; - } - ps2 = p1.ps; - p1 = ps2.p; - } - if (ps.nx != null) { - p1 = ps_times(cp_pols(ps.nx)); - p = pdiv(p, p1); - put_p(p1); - } - if (p.var == null) { - c = p.c; - put_x(p); - } else { - c = lcontent(p); - if (num_nunit(c)) { - p1 = get_n(-1L); - p = ptimes(p, p1); - } else if (!num_unit(c)) { - p1 = get_num(c); - p = pcdiv(p, p1); - put_x(p1); - } - ps1.nx = get_dt(1, p, null); - ps1 = ps1.nx; - } - ps2 = get_dt(1, get_num(c), ps.nx); - ps.nx = ps2; - return (ps.nx); - } - - } diff --git a/src/main/java/gprover/GrTerm.java b/src/main/java/gprover/GrTerm.java index c1ffef11..138a50b5 100644 --- a/src/main/java/gprover/GrTerm.java +++ b/src/main/java/gprover/GrTerm.java @@ -3,11 +3,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 13:16:18 - * To change this template use File | Settings | File Templates. + * The GrTerm class represents a geometric term in the theorem proving framework. + * It includes properties for coefficients, polynomial terms, construction type, + * elimination terms, simplifiers, and a linked list of geometric terms. */ public class GrTerm { @@ -27,28 +25,39 @@ public class GrTerm { public String text = ""; + /** + * Returns the text representation of this geometric term. + * + * @return the text representing this geometric term. + */ public String toString() { return text; } - public DTerm getps1() { - return ps1; - } - - public XTerm getds1() { - if (ps1 != null) - return ps1.p; - else return null; - } - + /** + * Sets the PTN (property tracking number) for this term. + * + * @param n the new PTN value. + */ public void setPTN(int n) { ptn = n; } + /** + * Retrieves the PTN (property tracking number) of this term. + * + * @return the current PTN value. + */ public int getPTN() { return ptn; } + /** + * Checks whether this geometric term is equivalent to zero. + * Determines zero based on the first polynomial term or its coefficient. + * + * @return true if the term is zero; false otherwise. + */ public boolean isZero() { if (ps1 == null) { if (c1 == 0) @@ -60,6 +69,12 @@ public boolean isZero() { return false; } + /** + * Retrieves all XTerm objects from the first polynomial term. + * Cuts the mark from the first XTerm in the resulting list. + * + * @return a vector containing all XTerm objects. + */ public Vector getAllxterm() { Vector v = new Vector(); if (ps1 != null && ps1.p != null) { @@ -81,6 +96,11 @@ public Vector getAllxterm() { return v; } + /** + * Retrieves all variables present in the first and second polynomial terms. + * + * @return a vector containing all variables. + */ public Vector getAllvars() { Vector v = new Vector(); getPSVar(v, ps1); @@ -88,6 +108,12 @@ public Vector getAllvars() { return v; } + /** + * Collects variables recursively from a chain of DTerm objects and adds them to the provided vector. + * + * @param v the vector to which variables are added. + * @param d the DTerm chain to process. + */ void getPSVar(Vector v, DTerm d) { while (d != null) { getPVar(v, d.p); @@ -95,12 +121,17 @@ void getPSVar(Vector v, DTerm d) { } } + /** + * Retrieves a variable from an XTerm and its associated DTerm chain, + * adding them to the provided vector. + * + * @param v the vector to which the variable is added. + * @param x the XTerm from which the variable is retrieved. + */ void getPVar(Vector v, XTerm x) { if (x == null) return; if (x.var != null) v.add(x.var); getPSVar(v, x.ps); } - - } diff --git a/src/main/java/gprover/Incenter.java b/src/main/java/gprover/Incenter.java index 8de0583f..e9ce44df 100644 --- a/src/main/java/gprover/Incenter.java +++ b/src/main/java/gprover/Incenter.java @@ -1,22 +1,26 @@ - /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:32:05 - * To change this template use File | Settings | File Templates. + * Represents an incenter in a geometric proof. + * This class extends the CClass and includes properties for lemma, coordinates, and a reference to the next incenter. */ package gprover; -public class Incenter extends CClass -{ - // int type; + +public class Incenter extends CClass { + /** The lemma associated with the incenter. */ int lemma; + + /** The coordinate of the incenter. */ int co; + + /** The indices of the points forming the incenter. */ int i, a, b, c; + + /** The next incenter in the list. */ Incenter nx; - public Incenter() - { + /** + * Constructs an Incenter object with default values. + */ + public Incenter() { type = lemma = 0; i = a = b = c = 0; co = 0; diff --git a/src/main/java/gprover/LLine.java b/src/main/java/gprover/LLine.java index 16a8141b..6132cd28 100644 --- a/src/main/java/gprover/LLine.java +++ b/src/main/java/gprover/LLine.java @@ -1,9 +1,5 @@ /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:32:37 - * To change this template use File | Settings | File Templates. + * Represents a geometric line in the construction. */ package gprover; @@ -15,6 +11,9 @@ public class LLine extends CClass { public int[] pt; LLine nx; + /** + * Constructs an LLine object with default values. + */ public LLine() { type = lemma = no = 0; co = null; @@ -22,7 +21,11 @@ public LLine() { nx = null; } - + /** + * Copies the properties of another LLine object to this one. + * + * @param l1 the LLine object to copy from + */ public void cp_ln(LLine l1) { lemma = l1.lemma; co = null; @@ -32,6 +35,12 @@ public void cp_ln(LLine l1) { nx = null; } + /** + * Checks if the line contains a specific point. + * + * @param n the point to check + * @return true if the line contains the point, false otherwise + */ public boolean containPt(int n) { if (n == 0) return false; for (int i = 0; i < MAX_GEO; i++) @@ -39,6 +48,13 @@ public boolean containPt(int n) { return false; } + /** + * Finds the intersection point of two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point, or 0 if there is no intersection + */ public static int inter_lls(LLine l1, LLine l2) { if (l1 == null || l2 == null || l1 == l2) return (0); if (l1 == l2) return 0; @@ -50,6 +66,13 @@ public static int inter_lls(LLine l1, LLine l2) { return (0); } + /** + * Gets a point from the line that is not equal to the specified point. + * + * @param l1 the line + * @param p1 the point to exclude + * @return a point from the line that is not equal to p1, or 0 if no such point exists + */ public static int get_lpt1(LLine l1, int p1) { for (int j = 0; j <= l1.no; j++) { if (l1.pt[j] != p1) return (l1.pt[j]); @@ -57,6 +80,12 @@ public static int get_lpt1(LLine l1, int p1) { return (0); } + /** + * Checks if a point is on the line. + * + * @param p the point to check + * @return true if the point is on the line, false otherwise + */ final public boolean on_ln(int p) { for (int i = 0; i <= no; i++) if (pt[i] == p) diff --git a/src/main/java/gprover/LList.java b/src/main/java/gprover/LList.java index 766c0b3a..46631d50 100644 --- a/src/main/java/gprover/LList.java +++ b/src/main/java/gprover/LList.java @@ -1,32 +1,58 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 19, 2006 - * Time: 9:27:45 PM - * To change this template use File | Settings | File Templates. + * Represents a list of geometric elements. + * This class extends the CClass and includes properties for different types of elements, rules, and methods to manipulate them. */ public class LList extends CClass { + /** Constant value representing a value type. */ final public static int VALUE = 0; + + /** Constant value representing a line type. */ final public static int LINE = 1; + + /** Constant value representing an angle type. */ final public static int ANGLE = 2; + /** Maximum number of elements. */ final public static int MAX_MDE = 10; + /** Indicates if the list is solved. */ boolean solved = false; + /** The type of the list. */ int type = -1; + + /** Array of Mnde objects representing the elements. */ public Mnde[] md; + + /** Array of Mnde objects representing the elements. */ public Mnde[] mf; - public int nd, nf; - int npt, pt; + /** Number of elements in md. */ + public int nd; + + /** Number of elements in mf. */ + public int nf; + + /** Number of points. */ + int npt; + + /** Point value. */ + int pt; + + /** Array of Rule objects representing the rules. */ public Rule[] rl; + + /** Reference to the first LList object. */ public LList fr; - LList nx; + /** Reference to the next LList object. */ + LList nx; + /** + * Constructs an LList object with default values. + */ public LList() { md = new Mnde[MAX_MDE]; mf = new Mnde[MAX_MDE]; @@ -34,6 +60,11 @@ public LList() { nd = nf = 0; } + /** + * Gets the number of points and updates the npt and pt fields. + * + * @return the number of points + */ public int get_npt() { int num = 0; int t = 0; @@ -55,6 +86,11 @@ public int get_npt() { return num; } + /** + * Copies the properties of another LList object to this one. + * + * @param ls the LList object to copy from + */ public void cp(LList ls) { type = ls.type; nd = ls.nd; @@ -67,18 +103,13 @@ public void cp(LList ls) { mf[i] = new Mnde(); mf[i].cp(ls.mf[i]); } - - } - - public void sub1(AngTr t1, AngTr t2) { - for (int i = 0; i < nd; i++) { - if (md[i].tr == t1) { - md[i].tr = t2; - return; - } - } } + /** + * Adds an Mnde object to the md array. + * + * @param m the Mnde object to add + */ public void add_md(Mnde m) { if (m == null) return; @@ -88,23 +119,36 @@ public void add_md(Mnde m) { nd = i + 1; } + /** + * Adds an Mnde object to the mf array. + * + * @param m the Mnde object to add + */ public void add_mf(Mnde m) { if (m == null) return; int i; for (i = 0; i < MAX_MDE && mf[i] != null; i++) ; mf[i] = m; nf = i + 1; - } + /** + * Adds a Rule object to the rl array. + * + * @param r the Rule object to add + */ public void add_rule(Rule r) { int i; for (i = 0; i < MAX_MDE && rl[i] != null; i++) ; rl[i] = r; } + /** + * Returns a string representation of the LList object. + * + * @return a string representation of the LList object + */ public String toString() { return text; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Main.java b/src/main/java/gprover/Main.java index d802bddb..8c6407cc 100644 --- a/src/main/java/gprover/Main.java +++ b/src/main/java/gprover/Main.java @@ -3,24 +3,30 @@ import java.io.*; import java.util.Vector; - -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-15 - * Time: 17:20:04 - * To change this template use File | Settings | File Templates. - */ public class Main { + + /** + * The main method that serves as the entry point of the application. + * + * @param args the command line arguments + */ + public static void main(String[] args) { + main1(args); + } + + /** + * The main logic of the application. + * Reads geometric terms from files, processes them, and outputs the results. + * + * @param args the command line arguments + */ public static void main1(String[] args) { try { - String user_directory = System.getProperty("user.dir"); String sp = File.separator; String dr = user_directory + sp + "examples"; File file = new File(dr); - Vector vm = new Vector(); readThems(file, vm); for (int id = 0; id < vm.size(); id++) { @@ -67,7 +73,6 @@ public static void main1(String[] args) { if (ff.exists()) { ff.delete(); fp = new FileOutputStream(ff, true); - } else { ff.createNewFile(); fp = new FileOutputStream(ff, false); @@ -93,133 +98,19 @@ public static void main1(String[] args) { } } - static void proveGDD(GTerm gt) { - - } - - public static void main(String[] args) { - main1(args); - } - - static void proveFull() { - try { - String user_directory = System.getProperty("user.dir"); - String sp = File.separator; - String dr = user_directory + sp + "ex"; - File file = new File(dr); - - - Vector vm = new Vector(); - readThems(file, vm); - for (int id = 0; id < vm.size(); id++) { - GTerm gt = (GTerm) vm.get(id); - System.out.print(id + " : " + gt.getName() + "\t\t"); - if (id % 4 == 0) - Cm.print("\n"); - - - } - - int t = 0; - int f = 0; - int n = 0; - Cm.print("\n\n************************\n"); - - Vector tlist = new Vector(); - long t1 = System.currentTimeMillis(); - Full full = new Full(); - int nt = 0; - for (int id = 0; id < vm.size(); id++) { - Full.set_showdetai(false); - - - full.init_dbase(); - - GTerm gt = (GTerm) vm.get(id); - full.setExample(gt); - full.sbase(); - full.setNoPrint(); - - if (id == 482) { - System.gc(); - } - full.prove_full(); - if (full.isProvedTrue()) { - FileOutputStream fp; - String drec = (dr + sp + "proved"); - File ff = new File(drec + sp + gt.getName() + ".rtf"); - - if (ff.exists()) { - ff.delete(); - fp = new FileOutputStream(ff, true); - - } else { - ff.createNewFile(); - fp = new FileOutputStream(ff, false); - } - if (fp == null) return; - DataOutputStream out = new DataOutputStream(fp); - - boolean s = false; - GrTerm gr = full.getFullAngleProofHead(); - while (gr != null) { - ElTerm e = gr.el; - if (e == null) { - gr = gr.nx; - continue; - } - while (e != null) { - Cond c = e.co; - full.setPrintToString(); - while (c != null) { - full.setConc(c); - if (full.docc()) { - full.show_fproof(); - Cond conc = full.all_nd.nx; - int nx = 0; - while (conc != null) { - nx++; - conc = conc.nx; - } - if (nx > 1) { - s = true; - System.out.print("(" + nx + ")"); - // full.show_fproof(); - out.writeBytes(full.getFileProve().append("\n********************************\n").toString()); - } - } - c = c.nx; - } - e = e.nx; - } - gr = gr.nx; - - } - if (s) { - gt.Save(out); - } - out.close(); - nt ++; - System.out.print(id + " : " + gt.getName() + "\t\ttrue\n"); - - } else { - // System.out.print(id + " : " + gt.getName() + "\t\tfalse\n"); - } - } - Cm.print("Total :" +vm.size() +", and true: " +nt); - } catch (IOException ee) { - - } - - } - + /** + * Reads geometric terms from files and adds them to a vector. + * + * @param file the directory containing the files + * @param v the vector to store the geometric terms + * @throws IOException if an I/O error occurs + */ static void readThems(File file, Vector v) throws IOException { File[] sf = file.listFiles(new FileFilter() { public boolean accept(File pathname) { String nm = pathname.getName(); return !(nm.contains(".")); } - }); for (int i = 0; i < sf.length; i++) { if (sf[i].isDirectory()) @@ -237,13 +128,4 @@ public boolean accept(File pathname) { } } } - - - static int inputInt() throws IOException { - byte[] bm = new byte[10]; - System.in.read(bm); - String sid = new String(bm).trim(); - int dd = Integer.parseInt(sid); - return dd; - } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Main2.java b/src/main/java/gprover/Main2.java index 12772a12..8986c6ab 100644 --- a/src/main/java/gprover/Main2.java +++ b/src/main/java/gprover/Main2.java @@ -1,26 +1,14 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-18 - * Time: 21:26:51 - * To change this template use File | Settings | File Templates. - */ package gprover; import javax.swing.*; import java.io.*; +/** + * Represents a geometric line in the construction. + */ public class Main2 { public static void main(String[] args) { -// final public static int CM_EX_PARA = 1; -// final public static int CM_EX_ORTH = 2; -// final public static int CM_EX_SIMSON = 3; -// final public static int CM_EX_SQ = 4; -// final public static int CM_EX_PAPPUS = 5; -// final public static int CM_EX_PEDAL = 6; -// final public static int CM_EX_MIQ1 = 7; - String user_directory = System.getProperty("user.dir"); String sp = File.separator; String dr = user_directory + sp + "examples"; @@ -33,68 +21,16 @@ public static void main(String[] args) { gt.readAterm(new BufferedReader(new FileReader(chooser.getSelectedFile()))); GDDBc db = new GDDBc(); db.init_dbase(); -// db.proc_exam(gdd.CM_EX_PARA); db.setExample(gt); db.sbase(); -// do { -// fixpoint(); -// last_nd = &all_nd; -// all_nd.nx = NULL; -// if (!conc_xtrue()) { -// if (print_geo) gprint("\n\n Beginning make auxillary points\n"); -// add_aux(); -// if (print_geo) { -// show_cons(); -// show_nds(); -// } -// } -// } while (all_nd.nx != NULL); db.fixpoint(); - //db.show_dbase((char)0); -// db.size_of_dbase('c'); - db.show_fproof(); - -// if (true) -// { -// FileOutputStream fp; -// String drec = (dr + sp); -// File ff = new File(drec + sp + gt.name + ".txt"); -// -// if (ff.exists()) -// { -// fp = new FileOutputStream(ff, true); -// -// } else -// { -// ff.createNewFile(); -// fp = new FileOutputStream(ff, false); -// } -// if (fp == null) return; -// DataOutputStream out = new DataOutputStream(fp); -// gt.Save(out); -// -//// db.setPrintToFile(); -// db.show_fproof((char) 1); -// db.show_dbase((char) 0); -// // out.writeBytes(db.getFileProve() + "\n********************************\n"); -// out.close(); -// -//// gt.print(); -//// db.show_fproof((char) 1); -// CMisc.print(gt.name + " " + "is true"); -// } else -// { db.show_dbase((char)0); -// CMisc.print(gt.name + " " + "is false"); -// } + db.show_fproof(); - //db.show_dbase((char) 0); } catch (IOException ee) { System.err.println("IOException " + ee.toString()); } - - //CMisc.print(Cm.s2077); } } diff --git a/src/main/java/gprover/MathBase.java b/src/main/java/gprover/MathBase.java index cc02a0a6..66cd71a8 100644 --- a/src/main/java/gprover/MathBase.java +++ b/src/main/java/gprover/MathBase.java @@ -1,13 +1,17 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-14 - * Time: 13:47:59 - * To change this template use File | Settings | File Templates. + * Provides basic arithmetic, string, and array manipulation methods. */ public class MathBase extends GDDBc { + + /** + * Compares two character arrays lexicographically. + * + * @param p1 the first character array + * @param p2 the second character array + * @return a negative, zero, or positive integer as p1 is less than, equal to, or greater than p2 + */ int strcmp(char[] p1, char[] p2) { int l1, l2; if (p1 == null && p2 == null) @@ -28,6 +32,13 @@ else if (p1 == null) return -1; } + /** + * Compares two strings lexicographically. + * + * @param s1 the first string + * @param s2 the second string + * @return a negative, zero, or positive integer as s1 is less than, equal to, or greater than s2 + */ int strcmp(String s1, String s2) { if (s1 != null) return s1.compareTo(s2); @@ -37,6 +48,13 @@ else if (s2 == null) return -1; } + /** + * Copies the source character array to the destination array. + * + * @param p the destination character array + * @param s the source character array + * @return true if the copy was successful + */ boolean strcpy(char[] p, char[] s) { if (s == null) return true; @@ -48,106 +66,205 @@ boolean strcpy(char[] p, char[] s) { return true; } + /** + * Determines if the given XTerm represents a number. + * + * @param p the XTerm to check + * @return true if p represents a number, false otherwise + */ boolean numberp(XTerm p) { return (p.var == null); } + /** + * Determines if the given XTerm represents a polynomial. + * + * @param p the XTerm to check + * @return true if p represents a polynomial, false otherwise + */ boolean npoly(XTerm p) { return (p.var == null); } + /** + * Determines if the given XTerm represents zero. + * + * @param p the XTerm to check + * @return true if p represents zero, false otherwise + */ boolean pzerop(XTerm p) { return ((p.var == null) && (num_zop(p.c))); } + /** + * Determines if the given XTerm represents the unit value 1. + * + * @param p the XTerm to check + * @return true if p represents 1, false otherwise + */ boolean unitp(XTerm p) { return ((p.var == null) && (p.c == mk_num(1L))); } + /** + * Determines if the given XTerm represents the negative unit value -1. + * + * @param p the XTerm to check + * @return true if p represents -1, false otherwise + */ boolean nunitp(XTerm p) { return ((p.var == null) && (p.c == mk_num(-1L))); } + /** + * Checks whether the given number is zero. + * + * @param x the number to check + * @return true if x is zero, false otherwise + */ boolean num_zop(long x) { return (x) == 0L; } + /** + * Checks whether the given number is positive. + * + * @param x the number to check + * @return true if x is positive, false otherwise + */ boolean num_posp(long x) { return (x) > 0L; } + /** + * Checks whether the given number is negative. + * + * @param x the number to check + * @return true if x is negative, false otherwise + */ boolean num_negp(long x) { return x < 0L; } + /** + * Creates a numeric representation from a long value. + * + * @param x the input value + * @return the numeric representation of x + */ long mk_num(long x) { return x; } - long num_m(long x, long y) { - return ((x) - (y)); - } - + /** + * Computes the sum of two numbers. + * + * @param x the first number + * @param y the second number + * @return the sum of x and y + */ long num_p(long x, long y) { return x + y; } + /** + * Computes the product of two numbers. + * + * @param x the first number + * @param y the second number + * @return the product of x and y + */ long num_t(long x, long y) { return x * y; } + /** + * Computes the integer division of one number by another. + * + * @param x the dividend + * @param y the divisor + * @return the quotient of x divided by y + */ long num_d(long x, long y) { return x / y; } + /** + * Returns the negation of the given number. + * + * @param x the number to negate + * @return the negated value of x + */ long num_neg(long x) { return -x; } - long num_gcd(long x, long y) { - return lgcd((x), (y)); - } - - long num_p3(long x, long y, long z) { - return ((x) + (y) + (z)); - } - - long num_t3(long x, long y, long z) { - return ((x) * (y) * (z)); - } - + /** + * Computes the remainder when one number is divided by another. + * + * @param x the dividend + * @param y the divisor + * @return the remainder of x divided by y + */ long num_mod(long x, long y) { return ((x) % (y)); } + /** + * Computes the modulus of a number by 2. + * + * @param x the number to evaluate + * @return the remainder of x divided by 2 + */ long num_modt(long x) { return ((x) % 2L); } + /** + * Checks if the given number is the unit value 1. + * + * @param p the number to check + * @return true if p is 1, false otherwise + */ boolean num_unit(long p) { return (p) == 1L; } + /** + * Checks if the given number is the negative unit value -1. + * + * @param p the number to check + * @return true if p is -1, false otherwise + */ boolean num_nunit(long p) { return (p) == (-1L); } - double num_to_f(long x) { - return (double) (x); - } - + /** + * Determines the number of digits in the given number. + * + * @param x the number to evaluate + * @return the number of digits in x + */ long num_digs(long x) { return int_digs(x); } + /** + * Displays the numeric value by converting it to its string representation. + * + * @param x the number to display + */ void num_show(long x) { int_show(x); } - int min(int a, int b) { - return ((a < b) ? (a) : (b)); - } - + /** + * Counts the number of digits in a long integer. + * + * @param x the number to evaluate + * @return the count of digits in x + */ int int_digs(long x) { int i = 0; if (x < 0L) x = -x; @@ -158,14 +275,32 @@ int int_digs(long x) { return (i); } + /** + * Converts a long number to an integer. + * + * @param c the number to convert + * @return the integer representation of c + */ int num_int(long c) { return (int) c; } + /** + * Displays the integer value by printing its string representation. + * + * @param x the number to display + */ void int_show(long x) { gprint(Integer.toString((int) x)); } + /** + * Computes the greatest common divisor of two numbers. + * + * @param l1 the first number + * @param l2 the second number + * @return the greatest common divisor of l1 and l2 + */ long lgcd(long l1, long l2) { long l; if (l1 < 0L) { @@ -186,31 +321,4 @@ long lgcd(long l1, long l2) { } return (l2); } - - - long ngcd(long l1, long l2) { - long n = lgcd(l1, l2); - if (n < 0L) n = -n; - return (n); - } - - long lpower(long l, long n) { - long d = (1L); - if (n <= 0) - return ((1L)); - else { - while (n > 1) { - if (n % 2 == 0) { - n /= 2; - l = num_t(l, l); - } else { - n -= 1; - d = num_t(d, l); - } - } - return (num_t(d, l)); - } - } - - } diff --git a/src/main/java/gprover/MidPt.java b/src/main/java/gprover/MidPt.java index 02076100..c7820a9f 100644 --- a/src/main/java/gprover/MidPt.java +++ b/src/main/java/gprover/MidPt.java @@ -1,21 +1,28 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:31:33 - * To change this template use File | Settings | File Templates. + * Represents a midpoint in a geometric construction. + * This class extends CClass and includes properties for lemma, conditions, and coordinates. */ -package gprover; -public class MidPt extends CClass -{ -// int type; +public class MidPt extends CClass { + // int type; // Commented out type field + + /** The lemma associated with the midpoint. */ int lemma; + + /** The condition associated with the midpoint. */ Cond co; + + /** The coordinates of the midpoint. */ public int m, a, b; + + /** Reference to the next MidPt object. */ MidPt nx; - public MidPt() - { + + /** + * Constructs a MidPt object with default values. + */ + public MidPt() { type = lemma = m = a = b = 0; co = null; nx = null; diff --git a/src/main/java/gprover/Mnde.java b/src/main/java/gprover/Mnde.java index 091f14e1..8ad2dafe 100644 --- a/src/main/java/gprover/Mnde.java +++ b/src/main/java/gprover/Mnde.java @@ -1,24 +1,30 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 17, 2006 - * Time: 5:00:43 PM - * To change this template use File | Settings | File Templates. + * Represents a geometric construction node. */ public class Mnde { int t, type; public AngTr tr; Mnde nx; + + /** + * Constructs a Mnde object with default values. + */ public Mnde() { t = 1; type = 0; tr = null; nx = null; - + } + + /** + * Copies the values from another Mnde object to this object. + * + * @param m the Mnde object to copy from + */ public void cp(Mnde m) { t = m.t; diff --git a/src/main/java/gprover/NdgCs.java b/src/main/java/gprover/NdgCs.java index 93bc572c..330904d3 100644 --- a/src/main/java/gprover/NdgCs.java +++ b/src/main/java/gprover/NdgCs.java @@ -1,28 +1,51 @@ package gprover; - +/** + * Represents a node in a geometric construction tree. + */ public class NdgCs { + /** The parent node. */ NdgCs parent = null; + + /** The geometric condition associated with this node. */ CNdg nd = null; - int ntype = 0; // 0. Normal, 1. exists. + + /** The type of the node (0 for normal, 1 for exists). */ + int ntype = 0; + + /** Indicates if this node is a leaf. */ boolean leaf = false; + + /** Indicates if this node is valid. */ boolean valid = true; + /** The index of the last constraint added. */ int no = -1; + + /** The child nodes of this node. */ NdgCs[] child = new NdgCs[3]; - Cons[] allcns = new Cons[100]; + /** The constraints associated with this node. */ + Cons[] allcns = new Cons[100]; + /** + * Adds a constraint to this node. + * + * @param c the constraint to add + */ public void add(Cons c) { if (c != null) { allcns[++no] = c; } } - + /** + * Gets the maximum constraint index. + * + * @return the maximum constraint index + */ public int getMaxCnsInt() { int n = 0; - for (int i = 0; i <= no; i++) { if (allcns[i] == null) continue; @@ -33,12 +56,23 @@ public int getMaxCnsInt() { return n; } + /** + * Adds a constraint at a specific index. + * + * @param i the index + * @param c the constraint to add + */ public void add(int i, Cons c) { if (c != null) { allcns[i] = c; } } + /** + * Gets the number of non-null constraints. + * + * @return the number of non-null constraints + */ public int getNotNullNum() { int k = 0; for (int i = 0; i <= no; i++) { @@ -48,6 +82,11 @@ public int getNotNullNum() { return k; } + /** + * Adds a child node to this node. + * + * @param c the child node to add + */ public void addChild(NdgCs c) { for (int i = 0; i < child.length; i++) { if (child[i] == null) { @@ -57,6 +96,12 @@ public void addChild(NdgCs c) { } } + /** + * Replaces a point in all constraints. + * + * @param m the point to replace + * @param n the new point + */ public void replace(int m, int n) { for (int i = 0; i <= no; i++) { Cons c1 = allcns[i]; @@ -65,23 +110,13 @@ public void replace(int m, int n) { } } - public void sort() { - - for (int i = 0; i <= no; i++) { - Cons c1 = allcns[i]; - for (int j = 0; j < i; j++) { - Cons c2 = allcns[j]; - if (c1 != null && c2 != null && compare(c1, c2) < 0) { - for (int k = i - 1; k >= j; k--) - allcns[k + 1] = allcns[k]; - allcns[j] = c1; - break; - } - } - } - - } - + /** + * Compares two constraints. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @return a negative integer, zero, or a positive integer as the first constraint is less than, equal to, or greater than the second + */ public static int compare(Cons c1, Cons c2) { int n1 = c1.getLastPt(); int n2 = c2.getLastPt(); @@ -92,15 +127,20 @@ public static int compare(Cons c1, Cons c2) { return -1; return compare1(c1, c2, n1); } - if (n1 > n2) return 1; - return 0; } - private static int compare1(Cons c1, Cons c2, int n) // euql type; - { + /** + * Helper method to compare two constraints with equal types. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @param n the point index to compare + * @return a negative integer, zero, or a positive integer as the first constraint is less than, equal to, or greater than the second + */ + private static int compare1(Cons c1, Cons c2, int n) { while (n > 0) { int n1 = c1.getLessPt(n); int n2 = c2.getLessPt(n); @@ -113,27 +153,14 @@ public static int compare(Cons c1, Cons c2) { return 0; } - public void rm_common() { - for (int i = 0; i <= no; i++) { - Cons c = allcns[i]; - if (c == null) - continue; - for (int j = 0; j < i; j++) { - Cons c1 = allcns[j]; - if (c1 != null && c1.isEqual(c)) { - allcns[i] = null; - break; - } - } - } - } - + /** + * Reduces the constraints by replacing points. + */ public void reduce() { if (nd == null) return; int a = nd.p[0]; int b = nd.p[1]; - if (nd.type == Gib.NDG_NEQ || nd.type == Gib.NDG_NON_ISOTROPIC) { for (int i = 0; i <= no; i++) { Cons c = allcns[i]; @@ -145,18 +172,17 @@ public void reduce() { } } - public void reorder() { - for (int i = 0; i <= no; i++) { - Cons c = allcns[i]; - if (c == null) - continue; - c.reorder(); - } - } - + /** + * Constructs an empty NdgCs object. + */ public NdgCs() { } + /** + * Constructs a NdgCs object by copying another NdgCs object. + * + * @param c the NdgCs object to copy + */ public NdgCs(NdgCs c) { parent = c.parent; nd = c.nd; @@ -167,6 +193,11 @@ public NdgCs(NdgCs c) { } } + /** + * Gets the index of the last non-null child. + * + * @return the index of the last non-null child + */ public int getCSindex() { int a = -1; for (int d = 0; d < child.length; d++) { @@ -175,4 +206,4 @@ public int getCSindex() { } return a; } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/PLine.java b/src/main/java/gprover/PLine.java index c70b1fa4..016507fb 100644 --- a/src/main/java/gprover/PLine.java +++ b/src/main/java/gprover/PLine.java @@ -1,12 +1,8 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:33:19 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Constructs a Mnde object with default values. + */ public class PLine extends CClass { int lemma; Cond co; @@ -15,6 +11,12 @@ public class PLine extends CClass { PLine nx; + /** + * Constructs a PLine object with two lines. + * + * @param l1 the first line + * @param l2 the second line + */ public PLine(LLine l1, LLine l2) { this(); ln[0] = l1; @@ -22,6 +24,9 @@ public PLine(LLine l1, LLine l2) { no = 1; } + /** + * Constructs a PLine object with default values. + */ public PLine() { type = lemma = no = 0; co = null; diff --git a/src/main/java/gprover/Poly.java b/src/main/java/gprover/Poly.java index f9efef60..ba2f5210 100644 --- a/src/main/java/gprover/Poly.java +++ b/src/main/java/gprover/Poly.java @@ -1,6 +1,12 @@ package gprover; +/** + * The Poly class extends MathBase and provides implementations + * for various polynomial operations such as addition, subtraction, + * multiplication, division, and remainder computation. + * It also supports simplification and printing functionalities for polynomials. + */ public class Poly extends MathBase { /* initials */ public static int PRO_VEC = 330; @@ -16,24 +22,46 @@ public class Poly extends MathBase { int pro_type = 0; Var all_var, last_var; +/** + * Initializes the polynomial by setting up the initial variable. + */ void init_poly() { all_var = new Var(); last_var = all_var; all_var.nx = null; } + /** + * Constructs a Poly object and initializes it. + */ public Poly() { init_poly(); } + /** + * Creates a new XTerm object. + * + * @return a new XTerm object + */ XTerm get_x() { return (new XTerm()); } + /** + * Creates a new DTerm object. + * + * @return a new DTerm object + */ DTerm get_d() { return (new DTerm()); } + /** + * Creates a new XTerm object representing a number. + * + * @param n the number to represent + * @return a new XTerm object representing the number + */ XTerm get_n(long n) { XTerm p1; p1 = get_x(); @@ -42,6 +70,12 @@ XTerm get_n(long n) { return (p1); } + /** + * Creates a new XTerm object representing a number. + * + * @param n the number to represent + * @return a new XTerm object representing the number + */ XTerm get_num(long n) { XTerm p1; p1 = get_x(); @@ -50,6 +84,13 @@ XTerm get_num(long n) { return (p1); } + /** + * Creates a new XTerm object with a variable and a DTerm. + * + * @param v the variable + * @param dp1 the DTerm + * @return a new XTerm object + */ XTerm get_xt(Var v, DTerm dp1) { XTerm xp1; xp1 = get_x(); @@ -58,10 +99,12 @@ XTerm get_xt(Var v, DTerm dp1) { return (xp1); } - XTerm get_s(char[] ch) { - return (get_m(mk_svar(ch))); - } - + /** + * Creates a new XTerm object representing a monomial. + * + * @param vn the variable + * @return a new XTerm object representing the monomial + */ XTerm get_m(Var vn) { DTerm dp1; XTerm xp1; @@ -74,6 +117,14 @@ XTerm get_m(Var vn) { } } + /** + * Creates a new XTerm object representing a variable raised to a power. + * + * @param v the variable + * @param d the degree + * @param p the polynomial term + * @return a new XTerm object + */ XTerm get_v(Var v, int d, XTerm p) { DTerm dp1; XTerm xp1; @@ -88,7 +139,14 @@ else if (d == 0) } } - + /** + * Creates a new DTerm object. + * + * @param d the degree + * @param xp1 the XTerm + * @param dp1 the next DTerm + * @return a new DTerm object + */ DTerm get_dt(int d, XTerm xp1, DTerm dp1) { DTerm d1; d1 = get_d(); @@ -98,12 +156,27 @@ DTerm get_dt(int d, XTerm xp1, DTerm dp1) { return (d1); } + /** + * Placeholder method for handling DTerm objects. + * + * @param dpt the DTerm object + */ void put_d(DTerm dpt) { } + /** + * Placeholder method for handling XTerm objects. + * + * @param xpt the XTerm object + */ void put_x(XTerm xpt) { } + /** + * Handles the given XTerm object and its associated DTerm objects. + * + * @param p1 the XTerm object + */ void put_p(XTerm p1) { DTerm dp1, dp2; if (p1 != null) { @@ -122,6 +195,11 @@ void put_p(XTerm p1) { } } + /** + * Handles the given DTerm objects. + * + * @param dp0 the head of the DTerm list + */ void put_ps(DTerm dp0) { DTerm dp1; while (dp0 != null) { @@ -132,12 +210,24 @@ void put_ps(DTerm dp0) { } } -/* xtermnomials */ - + /** + * Checks if two numbers are equal. + * + * @param c1 the first number + * @param c2 the second number + * @return true if the numbers are equal, false otherwise + */ boolean num_eq(long c1, long c2) { return c1 == c2; } + /** + * Checks if two polynomial terms are equal. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return true if the polynomial terms are equal, false otherwise + */ boolean eq_poly(XTerm p1, XTerm p2) { if ((p1.var == null) && (p2.var == null)) return (num_eq(p1.c, p2.c)); @@ -147,6 +237,13 @@ else if (p1.var != p2.var) return (eq_pols(p1.ps, p2.ps)); } + /** + * Checks if two lists of polynomial terms are equal. + * + * @param dp1 the first list of polynomial terms + * @param dp2 the second list of polynomial terms + * @return true if the lists of polynomial terms are equal, false otherwise + */ boolean eq_pols(DTerm dp1, DTerm dp2) { while ((dp1 != null) && (dp2 != null)) { if ((dp1.deg != dp2.deg) || @@ -159,6 +256,12 @@ boolean eq_pols(DTerm dp1, DTerm dp2) { return (dp1 == dp2); } + /** + * Creates a copy of the given polynomial term. + * + * @param p1 the polynomial term to copy + * @return a copy of the polynomial term + */ XTerm cp_poly(XTerm p1) { if (p1.var == null) return (get_num(p1.c)); @@ -166,6 +269,12 @@ XTerm cp_poly(XTerm p1) { return (get_xt(p1.var, cp_pols(p1.ps))); } + /** + * Creates a copy of the given list of polynomial terms. + * + * @param dp1 the list of polynomial terms to copy + * @return a copy of the list of polynomial terms + */ DTerm cp_pols(DTerm dp1) { DTerm dt2, dp2; dt2 = new DTerm(); @@ -179,26 +288,35 @@ DTerm cp_pols(DTerm dp1) { return (dt2.nx); } + /** + * Creates a new XTerm object representing zero. + * + * @return a new XTerm object representing zero + */ XTerm pzero() { return (get_n(0L)); } -/* -int pclass(p) -xterm *p; -{ if (numberp(p)) return(0); - else return(p.var); -} */ - - int ldeg(XTerm p) -//xterm p; - { + /** + * Gets the leading degree of the polynomial term. + * + * @param p the polynomial term + * @return the leading degree of the polynomial term + */ + int ldeg(XTerm p) { DTerm dp1; if (p.var == null) return (0); dp1 = p.ps; return (dp1.deg); } + /** + * Gets the degree of the polynomial term with respect to a variable. + * + * @param p the polynomial term + * @param v the variable + * @return the degree of the polynomial term with respect to the variable + */ int pdeg(XTerm p, Var v) { int tem, md; DTerm dp1; @@ -215,6 +333,13 @@ int pdeg(XTerm p, Var v) { return (md); } + /** + * Gets the minimum degree of the polynomial term with respect to a variable. + * + * @param p the polynomial term + * @param v the variable + * @return the minimum degree of the polynomial term with respect to the variable + */ int mdeg(XTerm p, Var v) { int tem, md; DTerm ps1; @@ -235,7 +360,12 @@ int mdeg(XTerm p, Var v) { return (md); } - + /** + * Gets the leading coefficient of the polynomial term. + * + * @param p the polynomial term + * @return the leading coefficient of the polynomial term + */ long lcc(XTerm p) { DTerm dp1; while (p.var != null) { @@ -245,13 +375,24 @@ long lcc(XTerm p) { return (p.c); } - + /** + * Gets the first coefficient of the polynomial term. + * + * @param p the polynomial term + * @return the first coefficient of the polynomial term + */ long fcc(XTerm p) { return (lcc(p)); } static long lcc_p; + /** + * Computes the content (greatest common divisor) of the polynomial coefficients. + * + * @param p the polynomial term + * @return the content of the polynomial as an integer + */ int lcontent(XTerm p) { lcc_p = mk_num(0L); lcont1(p); @@ -259,6 +400,11 @@ int lcontent(XTerm p) { return (int) (lcc_p); } + /** + * Recursively computes and updates the content based on the polynomial's coefficients. + * + * @param p the polynomial term + */ void lcont1(XTerm p) { DTerm ps1; if (p.var == null) { @@ -272,6 +418,12 @@ void lcont1(XTerm p) { } } + /** + * Retrieves the initial term of the polynomial. + * + * @param p the polynomial term + * @return the initial term of the polynomial or null if not applicable + */ XTerm init(XTerm p) { DTerm dp1; if (p.var == null) return (null); @@ -279,6 +431,12 @@ XTerm init(XTerm p) { return (dp1.p); } + /** + * Retrieves a copy of the initial term of the polynomial. + * + * @param p the polynomial term + * @return a copy of the first term of the polynomial or null if not applicable + */ XTerm cp_init(XTerm p) { DTerm dp1; if (p.var == null) return (null); @@ -286,11 +444,25 @@ XTerm cp_init(XTerm p) { return (cp_poly(dp1.p)); } - + /** + * Initializes the polynomial with respect to the specified variable. + * + * @param p the polynomial term + * @param v the variable used for initialization + * @return the initialized polynomial term for the given variable + */ XTerm init_v(XTerm p, Var v) { return (pinit(p, v, pdeg(p, v))); } + /** + * Adjusts the polynomial by removing lower degree parts relative to the specified variable. + * + * @param p the polynomial term + * @param v the variable for initialization + * @param d the degree threshold + * @return the modified polynomial after initialization + */ XTerm pinit(XTerm p, Var v, int d) { DTerm dt, dp0, dp1, dp2; if (p.var == null) { @@ -337,12 +509,12 @@ XTerm pinit(XTerm p, Var v, int d) { return (psimp(p, dt.nx)); } - XTerm cp_rem(XTerm p) -//xterm p; - { - return (rem(cp_poly(p))); - } - + /** + * Computes the remainder of the polynomial by removing its first term. + * + * @param p the polynomial term + * @return the polynomial remainder as an XTerm + */ XTerm rem(XTerm p) //xterm p; { @@ -358,16 +530,12 @@ XTerm rem(XTerm p) return (psimp(p, dp2)); } - int mono_pol(XTerm p) { - DTerm ps; - while (p.var != null) { - ps = p.ps; - if (ps.nx != null) return (0); - p = ps.p; - } - return (1); - } - + /** + * Calculates the number of immediate terms in the polynomial. + * + * @param p the polynomial term + * @return the count of terms linked directly to the polynomial + */ int tlength(XTerm p) { DTerm dp1; int count = 0; @@ -383,17 +551,12 @@ int tlength(XTerm p) { return (count); } - int mlength(XTerm p) { - DTerm dp1; - int count = 0; - if (p.var != null) { - count++; - dp1 = p.ps; - p = dp1.p; - } - return (count); - } - + /** + * Computes the total number of subterms within the polynomial. + * + * @param p the polynomial term + * @return the total length of the polynomial, including nested subterms + */ int plength(XTerm p) { DTerm dp1; int count = 0; @@ -412,6 +575,12 @@ else if (p.var == null) return (count); } + /** + * Computes the length of the DTerm linked list representing differential terms. + * + * @param dp1 the head of the DTerm list + * @return the total number of DTerm nodes + */ int dlength(DTerm dp1) { int count = 0; while (dp1 != null) { @@ -421,26 +590,13 @@ int dlength(DTerm dp1) { return (count); } - boolean pless(XTerm p1, XTerm p2) { - if ((p1.var == null) && (p2.var == null)) - return (false); - else if (p1.var == null) - return (true); - else if (p2.var == null) - return (false); - else if (p1.var == p2.var) { - if (ldeg(p1) < ldeg(p2)) - return (true); - else if (ldeg(p1) > ldeg(p2)) - return (false); - else - return (plength(p1) < plength(p2)); - } else if (vless(p1.var, p2.var)) - return (true); - else - return (false); - } - + /** + * Compares two polynomial terms for ordering. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return true if the first polynomial is considered less than the second; false otherwise + */ boolean pls(XTerm p1, XTerm p2) { int k1, k2; if ((p1.var == null) && (p2.var == null)) @@ -466,6 +622,13 @@ else if (ldeg(p1) > ldeg(p2)) return (false); } + /** + * Simplifies the polynomial by updating its terms with the provided DTerm list. + * + * @param p1 the polynomial term to simplify + * @param dp0 the DTerm list used for simplification + * @return the simplified polynomial term + */ XTerm psimp(XTerm p1, DTerm dp0) { XTerm p; if (dp0 == null) { @@ -483,22 +646,15 @@ XTerm psimp(XTerm p1, DTerm dp0) { return (p1); } - - int bad_poly(XTerm p) { - DTerm ps; - if (p.var == null) return (bad_num(p.c)); - for (ps = p.ps; ps != null; ps = ps.nx) { - if (bad_poly(ps.p) != 0) return (1); - } - return (0); - } - - int bad_num(long n) { - return 0; - } - /* Polynomial Plus: destructive */ + /** + * Adds two polynomial terms. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return the sum of p1 and p2 as a new polynomial term + */ XTerm pplus(XTerm p1, XTerm p2) { DTerm dp1; XTerm xp1; @@ -533,6 +689,13 @@ XTerm pplus(XTerm p1, XTerm p2) { return (pcplus(p2, p1)); } + /** + * Merges two lists of polynomial terms represented as DTerm linked lists. + * + * @param dp1 the first DTerm list + * @param dp2 the second DTerm list + * @return the merged DTerm list representing the summed polynomial parts + */ DTerm pplus1(DTerm dp1, DTerm dp2) { DTerm firstd, dp0, dp3; @@ -572,7 +735,13 @@ DTerm pplus1(DTerm dp1, DTerm dp2) { return (firstd.nx); } - // c < p2 + /** + * Adds a constant polynomial term to a polynomial represented by a DTerm chain. + * + * @param c the constant polynomial term to add + * @param p2 the polynomial term (as an XTerm) to which to add the constant + * @return the resulting polynomial term after addition + */ XTerm pcplus(XTerm c, XTerm p2) { DTerm dp1, dp2; dp2 = new DTerm(); @@ -596,12 +765,25 @@ XTerm pcplus(XTerm c, XTerm p2) { /* Polynomial difference: destructive */ + /** + * Subtracts the second polynomial term from the first polynomial term destructively. + * + * @param p1 the polynomial term from which to subtract + * @param p2 the polynomial term to subtract + * @return the resulting polynomial term after subtraction + */ XTerm pminus(XTerm p1, XTerm p2) { XTerm q1; q1 = neg_poly(p2); return (pplus(p1, q1)); } + /** + * Negates a polynomial term destructively. + * + * @param p the polynomial term to negate + * @return the negated polynomial term + */ XTerm neg_poly(XTerm p) { DTerm dp1; if (p.var == null) { @@ -618,6 +800,13 @@ XTerm neg_poly(XTerm p) { /* polynomial times: destructive */ + /** + * Multiplies two polynomial terms destructively. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return the product polynomial term + */ XTerm ptimes(XTerm p1, XTerm p2) { DTerm dp1; if (p1.var == null) { @@ -648,6 +837,13 @@ XTerm ptimes(XTerm p1, XTerm p2) { return (pctimes(p2, p1)); } + /** + * Multiplies two DTerm polynomial parts and accumulates the result. + * + * @param dp1 the first DTerm list + * @param dp2 the second DTerm list + * @return the resulting DTerm list from the multiplication + */ DTerm ptimes1(DTerm dp1, DTerm dp2) //dterm dp1,dp2; { @@ -680,6 +876,13 @@ DTerm ptimes1(DTerm dp1, DTerm dp2) return (dp0); } + /** + * Multiplies a constant polynomial term with a polynomial represented as an XTerm. + * + * @param c the constant polynomial term + * @param p the polynomial term to multiply + * @return the resulting polynomial term after multiplication + */ XTerm pctimes(XTerm c, XTerm p) //xterm c,p; { @@ -693,6 +896,13 @@ XTerm pctimes(XTerm c, XTerm p) return (p); } + /** + * Raises a polynomial term to the specified integer power. + * + * @param p the polynomial term + * @param n the exponent + * @return the polynomial term raised to the power n + */ XTerm ppower(XTerm p, int n) { XTerm pp1 = get_n(1L); if (n <= 0) { @@ -711,6 +921,13 @@ XTerm ppower(XTerm p, int n) { return (ptimes(pp1, p)); } + /** + * Performs polynomial division when the divisor is a unit. + * + * @param p1 the dividend polynomial term + * @param p2 the divisor polynomial term + * @return the resulting polynomial term representing the remainder after division + */ XTerm ppdiv(XTerm p1, XTerm p2) { XTerm p3; if (unitp(p2)) return (p1); @@ -725,8 +942,14 @@ XTerm ppdiv(XTerm p1, XTerm p2) { /* polynomial division: destructive for p1 */ + /** + * Divides the first polynomial term by the second polynomial term destructively. + * + * @param p1 the dividend polynomial term + * @param p2 the divisor polynomial term + * @return the resulting polynomial term after division, or null if division is not possible + */ XTerm pdiv(XTerm p1, XTerm p2) -//xterm p1, p2; { DTerm dp1; @@ -768,9 +991,14 @@ XTerm pdiv(XTerm p1, XTerm p2) return (null); } - + /** + * Divides a polynomial term by a constant polynomial term. + * + * @param p the polynomial term to be divided + * @param c the constant polynomial term divisor + * @return the resulting polynomial term after division, or null if division is not possible + */ XTerm pcdiv(XTerm p, XTerm c) -//xterm p,c; { DTerm dp1; for (dp1 = p.ps; dp1 != null; dp1 = dp1.nx) { @@ -783,6 +1011,14 @@ XTerm pcdiv(XTerm p, XTerm c) return (p); } + /** + * Divides the polynomial represented by dp1 by dp2. + * Returns the quotient as a new DTerm or null if the division fails. + * + * @param dp1 the dividend polynomial as a DTerm structure + * @param dp2 the divisor polynomial as a DTerm structure + * @return the quotient polynomial as a DTerm, or null if division is not exact + */ DTerm pdiv1(DTerm dp1, DTerm dp2) { DTerm fird, qterm, dp0, dp3, dp4; XTerm lcf, qp; @@ -840,6 +1076,13 @@ DTerm pdiv1(DTerm dp1, DTerm dp2) { char init_deg; + /** + * Computes the polynomial remainder (prem) of p1 with respect to p2. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure + * @return the remainder polynomial as an XTerm, or a zero polynomial if p2 is null + */ XTerm prem(XTerm p1, XTerm p2) { init_deg = 0; if (p2.var == null) { @@ -852,6 +1095,14 @@ XTerm prem(XTerm p1, XTerm p2) { return (prem_var(p1, p2, p2.var)); } + /** + * Computes the polynomial remainder when both p1 and p2 share the same variable. + * Uses an evaluation-based approach. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure with the same variable as p1 + * @return the remainder polynomial as an XTerm, or null if the division is not exact + */ XTerm prem_ev(XTerm p1, XTerm p2) { DTerm dt1, dp1, dp2, dp3, dp4; XTerm ip1, ip2, pp1, pp2; @@ -926,6 +1177,14 @@ XTerm prem_ev(XTerm p1, XTerm p2) { return (null); } + /** + * Computes the polynomial remainder for p1 with respect to p2 when they have different variable orderings. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure + * @param v the variable used for division operations + * @return the remainder polynomial as an XTerm, or a zero polynomial if division is complete + */ XTerm prem_var(XTerm p1, XTerm p2, Var v) { XTerm ip0, ip1, ip2, u1, u2, v2; int deg1, deg2; @@ -970,57 +1229,45 @@ XTerm prem_var(XTerm p1, XTerm p2, Var v) { return (p1); } - void xerror(char ch) -//char *ch; - { - Cm.print("\n\n Syntax error:\n\n"); - // Cm.print(ch); - Cm.print("\n\n Please check your input.\n"); - } - -/* print polynomials */ - -// public void gprint(String s) -// { -// System.out.print(s); -// } - - void dprint(DTerm dp1) { - if (dp1 == null) - gprint("null\r\n"); - else { - while (dp1 != null) { - gprint("\r\n"); - print_ind(dp1.p); - gprint("\r\n"); - if (plength(dp1.p) < 20) pprint(dp1.p); - dp1 = dp1.nx; - } - } - } - + /** + * Prints the polynomial in a compact form. + * + * @param p1 the polynomial to be printed as an XTerm structure + */ final void xprint(XTerm p1) { print_p(p1, (char) 0); } + /** + * Prints the polynomial followed by a newline. + * + * @param p1 the polynomial to be printed as an XTerm structure + */ void pprint(XTerm p1) { print_p(p1, (char) 0); gprint("\r\n"); } - void eprint(XTerm p1) { - print_p(p1, (char) 0); - gprint("=0\r\n"); - } - static int char_no; - void print_p(XTerm p1, char mk) // print_pp1 + /** + * Prints the polynomial with a specified marker for formatting. + * + * @param p1 the polynomial to be printed as an XTerm structure + * @param mk the marker character to use during printing + */ + void print_p(XTerm p1, char mk) { char_no = 0; print_p1(p1, mk); } + /** + * Helper method that prints the polynomial in detailed format. + * + * @param p1 the polynomial to be printed as an XTerm structure + * @param mk the marker character used for formatting + */ void print_p1(XTerm p1, char mk) { DTerm dp1; XTerm xp1, xp2; @@ -1137,6 +1384,11 @@ else if (p1.var == null) { } + /** + * Prints the index information of the given polynomial. + * + * @param p the polynomial as an XTerm structure whose index is to be printed + */ void print_ind(XTerm p) { Var v; if (p == null) @@ -1161,44 +1413,40 @@ else if (pzerop(p)) { } - XTerm c_pplus(XTerm x, XTerm y) { - return pplus(cp_poly(x), cp_poly(y)); - } - - XTerm c_pminus(XTerm x, XTerm y) { - return pminus(cp_poly(x), cp_poly(y)); - } - - XTerm c_ptimes(XTerm x, XTerm y) { - return ptimes(cp_poly(x), cp_poly(y)); - } - - XTerm c_pdiv(XTerm x, XTerm y) { - return pdiv(cp_poly(x), y); - } - + /** + * Adds three polynomial terms. + * + * @param x the first polynomial term + * @param y the second polynomial term + * @param z the third polynomial term + * @return the sum of the three polynomial terms + */ XTerm pplus3(XTerm x, XTerm y, XTerm z) { return pplus(x, pplus(y, z)); } - XTerm ptimes3(XTerm x, XTerm y, XTerm z) { - return ptimes(x, ptimes(y, z)); - } - + /** + * Adds four polynomial terms. + * + * @param x the first polynomial term + * @param y the second polynomial term + * @param z the third polynomial term + * @param w the fourth polynomial term + * @return the sum of the four polynomial terms + */ XTerm pplus4(XTerm x, XTerm y, XTerm z, XTerm w) { return pplus(pplus(x, y), pplus(z, w)); } - XTerm ptimes4(XTerm x, XTerm y, XTerm z, XTerm w) { - return ptimes(ptimes(x, y), ptimes(z, w)); - } - -//----------------------------------------- -//-----------------------------------------var.cpp - - static Var svar = new Var(); + /** + * Compares two Var objects for equality based on their type and contents. + * + * @param v1 the first Var object + * @param v2 the second Var object + * @return true if the two variables are considered equal, false otherwise + */ boolean eq_var(Var v1, Var v2) { int i; if (v1.nm == 0 || v1.nm == 99) { @@ -1212,6 +1460,12 @@ boolean eq_var(Var v1, Var v2) { return (false); } + /** + * Creates a copy of the given Var object. + * + * @param v the Var object to copy + * @return a new Var object that is a copy of v + */ Var cp_var(Var v) { Var v1; int i; @@ -1225,6 +1479,12 @@ Var cp_var(Var v) { return (v1); } + /** + * Retrieves an existing Var object equal to the given one or adds a new one. + * + * @param v the Var object to add or look up + * @return an existing Var equal to v or a new copy if not found + */ Var ad_var(Var v) { Var v1; char i; @@ -1242,6 +1502,16 @@ Var ad_var(Var v) { return (v1); } + /** + * Constructs and adds a new Var object using the given parameters. + * + * @param nm the variable identifier + * @param p1 the first parameter + * @param p2 the second parameter + * @param p3 the third parameter + * @param p4 the fourth parameter + * @return the resulting Var object + */ Var mk_var(int nm, int p1, int p2, int p3, int p4) { svar.nm = nm; svar.pt[0] = p1; @@ -1251,22 +1521,13 @@ Var mk_var(int nm, int p1, int p2, int p3, int p4) { return (ad_var(svar)); } - Var mk_svar(char[] nm) { - char i; - for (i = 0; i < 9; i++) svar.p[i] = 0; - svar.nm = 0; - strcpy(svar.p, nm); - return (ad_var(svar)); - } - - Var mk_cvar(char[] nm) { - char i; - for (i = 0; i < 9; i++) svar.p[i] = 0; - strcpy(svar.p, nm); - svar.nm = 99; - return (ad_var(svar)); - } - + /** + * Creates a new "w" Var object by initializing its parameters to zero + * and setting its identifier based on the provided number. + * + * @param nm the input number determining the variable type + * @return the newly created Var object + */ Var mk_wvar(int nm) { for (int i = 0; i < 4; i++) svar.pt[i] = 0; if (nm > 0) @@ -1279,7 +1540,14 @@ Var mk_wvar(int nm) { return (ad_var(svar)); } - + /** + * Compares two integer arrays element-wise from index 0 to n. + * + * @param a1 the first integer array + * @param a2 the second integer array + * @param n the last index (inclusive) to compare + * @return 1 if the first differing element in a1 is less than in a2, otherwise 0 + */ int ials(int a1[], int a2[], int n) { char i; for (i = 0; i <= n; ++i) { @@ -1290,6 +1558,13 @@ int ials(int a1[], int a2[], int n) { return (0); } + /** + * Determines the maximum point value from a Var object's point array + * based on the variable type. + * + * @param v the Var object to evaluate + * @return the maximum value among the relevant point entries + */ int lpt(Var v) { int k = v.pt[0]; if (v.nm == 1) { @@ -1300,6 +1575,13 @@ int lpt(Var v) { return (k); } + /** + * Compares two Var objects for ordering based on type and point values. + * + * @param v1 the first Var object + * @param v2 the second Var object + * @return true if v1 is considered less than v2, false otherwise + */ boolean vless(Var v1, Var v2) { int m, l1, l2; @@ -1388,6 +1670,12 @@ else if (v1.nm < v2.nm) return (m != 0); } + /** + * Extracts a linked list of unique variables present in the given polynomial term. + * + * @param p the polynomial term represented as an XTerm + * @return the head of a linked list of distinct Var objects from p + */ XTerm vars_in_p(XTerm p) { DTerm ps1; XTerm p0, p1, p2; @@ -1432,14 +1720,12 @@ XTerm vars_in_p(XTerm p) { return (p0); } - - void print_vars(Var v, char mk) { - while (v != null) { - print_var(v, mk); - v = v.nx; - } - } - + /** + * Prints the variable using a specific format determined by its type and mode. + * + * @param v the Var object to print + * @param mk the mode flag determining the format + */ void print_var(Var v, int mk) { switch (v.nm) { case 0: @@ -1596,263 +1882,13 @@ void print_var(Var v, int mk) { } } -// void print_fang(int p1, int p2, int p3, int p4) -// { -// int p0; -// if (p1 == p4) -// { -// p0 = p4; -// p4 = p3; -// p3 = p0; -// } else if (p2 == p3) -// { -// p0 = p1; -// p1 = p2; -// p2 = p0; -// } else if (p2 == p4) -// { -// p0 = p1; -// p1 = p2; -// p2 = p0; -// p0 = p4; -// p4 = p3; -// p3 = p0; -// } -//// sprintf(txt, "%s[%s%s,%s%s]", Cm.s2078), -//// pt_name(p1), pt_name(p2), pt_name(p3), pt_name(p4)); -// gprint(Cm.s2078 + "["); -// } - + /** + * Prints a point identifier using the established naming conventions. + * + * @param p the point identifier + */ void print_pt(int p) { //sprintf(txt,"%s",pt_name(p)); gprint(pt_name(p)); } - -/////--------------------------------------------------getp.cpp - - static DTerm p_stk = new DTerm(); - public static int gno; - - public XTerm rd_pol(String sterm[]) { - - gno = 0; - int nterm = sterm.length; - DTerm ps1; - - p_stk.nx = null; - if (strcmp(sterm[gno], "-") == 0 || strcmp(sterm[gno], "+") == 0) { - p_stk.nx = get_dt(1, get_n(0L), p_stk.nx); - } - - - ps1 = p_stk.nx; - while (gno < nterm && strcmp(sterm[gno], ";") != 0 && - strcmp(sterm[gno], "=") != 0 && strcmp(sterm[gno], ".") != 0)// && (in_hyp == 0 || (ps1 != null && !(ps1.nx == null && ps1.deg == 1)))) - { - - if (strcmp(sterm[gno], "(") == 0) { - if (ps1 != null && ps1.deg == 1) { - do_it(6); - gno--; - } - p_stk.nx = get_dt(2, null, p_stk.nx); - gno++; - if (strcmp(sterm[gno], "-") == 0 || strcmp(sterm[gno], "+") == 0) { - p_stk.nx = get_dt(1, get_n(0L), p_stk.nx); - } - } else if (strcmp(sterm[gno], ")") == 0) { - do_it(3); - } else if (strcmp(sterm[gno], "+") == 0) { - do_it(4); - } else if (strcmp(sterm[gno], "-") == 0) { - do_it(5); - } else if (strcmp(sterm[gno], "*") == 0) { - do_it(6); - } else if (strcmp(sterm[gno], "/") == 0) { - do_it(7); - } else if (strcmp(sterm[gno], "^") == 0) { - do_it(8); - } else if (num_ch(sterm[gno])) { - if (ps1 != null && ps1.deg == 1) { - do_it(6); - } - p_stk.nx = get_dt(1, get_n(ch2num(sterm[gno])), p_stk.nx); - gno++; - } else { - if (ps1 != null && ps1.deg == 1) - do_it(6); - else - gno++; - p_stk.nx = get_dt(1, get_m(mk_svar(sterm[gno - 1].toCharArray())), p_stk.nx); - } - ps1 = p_stk.nx; - } - - if (gno > nterm) { - gerror(" expression error\n"); - return (null); - } - do_it(0); - return (ps1.p); - } - - - public void doother(String[] sterm) { - // if (strcmp(sterm[gno], Cm.s3000) == 0) { - //cannot dela with (RATIO B F F C)<- -// p_stk.nx = get_dt(1, trim_r(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else if (strcmp(sterm[gno], Cm.s3001) == 0) { -// //gao need -// p_stk.nx = get_dt(1, trim_f(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else if (strcmp(sterm[gno], Cm.s3002) == 0) { -// if (strcmp(sterm[gno + 4], ")") == 0) { -// p_stk.nx = get_dt(1, trim_a(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 3)), p_stk.nx); -// gno += 4; -// } else if (strcmp(sterm[gno + 5], ")") == 0) { -// p_stk.nx = get_dt(1, trim_a(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else -// gerror("area is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3008) == 0) { -// if (strcmp(sterm[gno + 4], ")") == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 2), fptno(gno + 3)), p_stk.nx); -// gno += 4; -// } else if (strcmp(sterm[gno + 5], ")") == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else -// gerror("py is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3003) == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 2), fptno(gno + 1)), p_stk.nx); -// gno += 3; -// } else if (strcmp(sterm[gno], Cm.s3004) == 0) { -// if (strcmp(sterm[gno + 2], ")") == 0) { -// p_stk.nx = get_dt(1, trim_vec(fptno(gno + 1), 0), p_stk.nx); -// gno += 2; -// } else if (strcmp(sterm[gno + 3], ")") == 0) { -// p_stk.nx = get_dt(1, trim_vec(fptno(gno + 1), fptno(gno + 2)), p_stk.nx); -// gno += 3; -// } else -// gerror("vector is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3009) == 0) { -// p_stk.nx = get_dt(1, trim_l(fptno(gno + 1), fptno(gno + 2)), p_stk.nx); -// gno += 3; -// } else if (strcmp(sterm[gno], Cm.s3005) == 0) { -// p_stk.nx = get_dt(1, -// ptimes(trim_r(fptno(gno + 3), fptno(gno + 1), fptno(gno + 3), fptno(gno + 2)), -// trim_r(fptno(gno + 4), fptno(gno + 2), fptno(gno + 4), fptno(gno + 1))), -// p_stk.nx); -// gno += 5; -// } else if (num_ch(sterm[gno])) { -// if (ps1 != null && ps1.deg == 1) { -// do_it(6); -// } -// p_stk.nx = get_dt(1, get_n(ch2num(sterm[gno])), p_stk.nx); -// gno++; -// } else { -// if (ps1 != null && ps1.deg == 1) -// do_it(6); -// else -// gno++; -// p_stk.nx = get_dt(1, get_m(mk_svar(sterm[gno - 1])), p_stk.nx); -// } - } - - void do_it(int op) { - DTerm ps1, ps2, ps3; - XTerm p1; - int deg; - - - ps1 = p_stk.nx; - if (ps1 == null) { - p_stk.nx = get_dt(op, null, p_stk.nx); - return; - } - - if (ps1.deg == 2) { - if (op == 3) { - p_stk.nx = ps1.nx; - put_d(ps1); - } else - p_stk.nx = get_dt(op, null, p_stk.nx); - gno++; - return; - } - - if (ps1.deg != 1) gerror("expresion error 13"); - ps2 = ps1.nx; - while (ps2 != null && ps2.deg >= op) { - ps3 = ps2.nx; - if (ps3 == null) { - if (ps2.deg != 2) gerror("expression error 14"); - ps1.nx = ps2.nx; - put_d(ps2); - } else if (ps3.deg == 2) { - if (ps2.deg == 4) - ps1.p = neg_poly(ps1.p); - else if (ps2.deg != 3) gerror("expression error15"); - ps1.nx = ps3.nx; - put_d(ps3); - put_d(ps2); - } else if (ps2.deg == 4) { - ps1.p = pplus(ps1.p, ps3.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 5) { - ps1.p = pminus(ps3.p, ps1.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 6) { - ps1.p = ptimes(ps1.p, ps3.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 8) { - p1 = ps1.p; - if (p1.var != null) gerror("expression error"); - deg = num_int(p1.c); - ps1.p = ppower(ps3.p, deg); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else { - gerror("expression error 99"); - return; - } - ps2 = ps1.nx; - } - if (op == 3) { - if (ps2 == null || ps2.deg != 2) gerror("expression error 17"); - ps1.nx = ps2.nx; - put_d(ps2); - gno++; - } else if (op > 3) { - p_stk.nx = get_dt(op, null, p_stk.nx); - gno++; - } - - } - - - boolean num_ch(String sn) { - byte[] ch = sn.getBytes(); - int i = 0; - if (ch[i] == '-') - i++; - else if (ch[i] == '+') i++; - while (i < ch.length && ch[i] != '\0') { - if (ch[i] < '0' || ch[i] > '9') return (false); - i++; - } - return (true); - } - - long ch2num(String sn) { - return Integer.parseInt(sn); - } } diff --git a/src/main/java/gprover/Polygon.java b/src/main/java/gprover/Polygon.java index 316529da..ef69e7f5 100644 --- a/src/main/java/gprover/Polygon.java +++ b/src/main/java/gprover/Polygon.java @@ -1,11 +1,7 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 6, 2006 - * Time: 10:22:42 PM - * To change this template use File | Settings | File Templates. + * Represents a polygon in a geometric construction. */ public class Polygon extends CClass { int lemma; @@ -16,10 +12,19 @@ public class Polygon extends CClass { Polygon nx; + /** + * Constructs a Polygon object with default values. + */ public Polygon() { lemma = o = 0; co = null; } + + /** + * Constructs a Polygon object with a specified type. + * + * @param t the type of the polygon + */ public Polygon(int t) { qtype = t; lemma = o = 0; diff --git a/src/main/java/gprover/ProPoint.java b/src/main/java/gprover/ProPoint.java index 92a00c61..b5e16c31 100644 --- a/src/main/java/gprover/ProPoint.java +++ b/src/main/java/gprover/ProPoint.java @@ -1,12 +1,14 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-15 - * Time: 14:18:38 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Represents a point used in geometric constructions. + *+ * This class stores geometric properties including coordinates, + * auxiliary data, and arrays that represent point states. + * It provides methods for setting point attributes and retrieving + * coordinate information. + *
+ */ public class ProPoint { final public static int MAX_GEO = 30; @@ -30,10 +32,6 @@ public ProPoint(int t) { type = t; } - public int getAux() { - return aux; - } - void setPS(int value, int index) { if (type1 == 0) { if (ps.length <= index) { @@ -60,30 +58,6 @@ void setType(int t) { type1 = t; } - void set(int Type, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - if (type == 0) { - type = Type; - ps[0] = p1; - ps[1] = p2; - ps[2] = p3; - ps[3] = p4; - ps[4] = p5; - ps[5] = p6; - ps[6] = p7; - ps[7] = p8; - } else { - type1 = Type; - ps[0] = p1; - ps[1] = p2; - ps[2] = p3; - ps[3] = p4; - ps[4] = p5; - ps[5] = p6; - ps[6] = p7; - ps[7] = p8; - } - } - public ProPoint(int t, String s) { type = t; name = s; @@ -147,17 +121,11 @@ public String getName() { return name; } + @Override public String toString() { return name; } - public void add_nd(Cond c) { - if (co == null) - co = c; - c.nx = co; - co = c; - } - public String getText() { return text; } diff --git a/src/main/java/gprover/Prover.java b/src/main/java/gprover/Prover.java index 4f4958e2..21ee9c18 100644 --- a/src/main/java/gprover/Prover.java +++ b/src/main/java/gprover/Prover.java @@ -2,20 +2,36 @@ import java.util.Vector; - +/** + * The Prover class provides static methods for performing geometric proofs and computations. + * It manages the state of geometric terms and interacts with the geometric database. + * + *This class is not instantiable.
+ */ public class Prover { private static GDDBc db = null; private static Full dbfull = null; private static GTerm gt = null; private static boolean aux = false; + /** + * Private constructor to prevent instantiation. + */ private Prover() { } + /** + * Sets the global geometric term. + * + * @param g the geometric term to set + */ public static void set_gterm(GTerm g) { gt = g; } + /** + * Resets the internal database and state. + */ public static void reset() { db = null; dbfull = null; @@ -23,29 +39,55 @@ public static void reset() { aux = false; } + /** + * Executes a fixpoint computation on the current geometric term. + */ public static void run() { fixpoint(gt); } + /** + * Retrieves the name of the point corresponding to the specified identifier. + * + * @param t the point identifier + * @return the point name, or "null" if the database is not initialized + */ public static String get_pt_name(int t) { if (db == null) return "null"; return db.ANAME(t); } + /** + * Retrieves the identifier of the point corresponding to the specified name. + * + * @param s the point name + * @return the point identifier, or 0 if the database is not initialized + */ public static int get_pt_id(String s) { if (db == null) return 0; return db.SPT(s); } + /** + * Retrieves the total number of properties in the database. + * + * @return the number of properties, or 0 if the database is not initialized + */ public static int getNumberofProperties() { if (db == null) return 0; return db.getNumberofProperties(); } + /** + * Initializes the database and performs a fixpoint computation using the provided geometric term. + * + * @param gt the geometric term used for the computation + * @return true if the fixpoint computation is successful, false otherwise + */ public static boolean fixpoint(GTerm gt) { try { db = new GDDBc(); @@ -61,6 +103,11 @@ public static boolean fixpoint(GTerm gt) { return true; } + /** + * Attempts to prove the current geometric term. + * + * @return true if the proof is successful, false otherwise + */ public static boolean prove() { try { aux = false; @@ -88,11 +135,22 @@ public static boolean prove() { } } + /** + * Retrieves the constructed auxiliary point if one was created during the proof. + * + * @return the auxiliary point if available, or null otherwise + */ public static AuxPt getConstructedAuxPoint() { if (!aux) return null; return db.axptc; } + /** + * Attempts to prove the provided geometric condition. + * + * @param co the condition to prove + * @return true if the condition is successfully proved, false otherwise + */ public static boolean prove(Cond co) { try { if (db == null) @@ -111,19 +169,27 @@ public static boolean prove(Cond co) { } } - public static boolean isfixed() { - return db != null; - } - + /** + * Retrieves the current geometric database. + * + * @return the current GDDBc instance + */ public static GDDBc get_gddbase() { return db; } + /** + * Sets the global database to the full geometric base. + */ public static void setGIB() { db = dbfull; } - + /** + * Returns the head of the proof condition. + * + * @return the current proof condition head as a Cond object, or null if the database is not initialized. + */ public static Cond getProveHead() { try { if (db != null) { @@ -139,23 +205,46 @@ public static Cond getProveHead() { } + /** + * Retrieves the next proof head in the given list. + * + * @param ls the current list of proof heads + * @return the next LList proof head from the database + */ public static LList getProveHead_ls(LList ls) { return db.get_next_ls_prove_head(ls); } + /** + * Searches for a fact matching the provided criteria. + * + * @param t the type of fact to search for + * @param s1 the first search parameter + * @param s2 the second search parameter + * @param s3 the third search parameter + * @return a Vector of matching facts + */ public static Vector search_a_fact(int t, String s1, String s2, String s3) { return db.search_a_fact(t, s1, s2, s3); } -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - + /** + * Retrieves and displays the full conclusion from the geometric term. + * + * @return the full conclusion as a Cond object + */ public static Cond getFullconc() { Cond co = gt.getConc(); dbfull.show_pred(co); return co; } + /** + * Proves the full angle expression for the specified geometric term. + * + * @param gt the geometric term to prove + * @return the GrTerm representing the full angle proof head, or null if proof fails + */ public static GrTerm proveFull(GTerm gt) { try { @@ -178,6 +267,16 @@ public static GrTerm proveFull(GTerm gt) { } } + /** + * Retrieves all nondiscussed geometric statements and stores them in the provided vectors. + * + * @param gt the geometric term to process + * @param v1 vector to store the first group of statements + * @param v2 vector to store the second group of statements + * @param v3 vector to store the third group of statements + * @param v4 vector to store the fourth group of statements + * @return true if the nondiscussed statements were successfully retrieved; false otherwise + */ public static boolean getAllNdgs(GTerm gt, Vector v1, Vector v2, Vector v3, Vector v4) { try { Prover.gt = gt; @@ -195,10 +294,11 @@ public static boolean getAllNdgs(GTerm gt, Vector v1, Vector v2, Vector v3, Vect } } - public static boolean isFullAngleProvedTrue() { - return dbfull.isProvedTrue(); - } - + /** + * Returns the result of the full angle proof. + * + * @return 0 if the proof is successful, 1 if it fails, or 2 if it cannot be expressed as a full angle expression + */ public static int getPFullResult() { if (dbfull.isProvedTrue()) { return 0; // true @@ -207,48 +307,21 @@ public static int getPFullResult() { else return 2; // can not be expressed as full angle expression. } + /** + * Retrieves the error type code from the full angle proof. + * + * @return an integer representing the error type + */ public static int getErrorType() { return dbfull.getErrorType(); } - public static void showFullPred(Cond co) { - try { - Cond c = new Cond(co); - dbfull.conc = c; - if (dbfull.docc()) - dbfull.show_fproof(); - dbfull.print_prooftext(); - return; - } catch (Exception e) { - System.out.println("Exception on gprover.Prover: \n" + e.getMessage()); - return; - } - } - - public static int getAngleNum() { - if (dbfull == null) return 0; - return dbfull.getvarNum(); - } - - public static int getLnNum() { - if (dbfull == null) return 0; - return dbfull.getlnNum(); - } - + /** + * Displays the condition text for the given proof condition. + * + * @param co the condition to be displayed + */ public static void showCondTextF(Cond co) { dbfull.show_pred(co); } - - public static void showCondText(Cond co) { - if (db != null) - db.show_pred(co); - } - - public static GrTerm proveArea(Vector v) { - return null; - } - - ///////////////////////////////////////////////////// - /// angle deduction. - } diff --git a/src/main/java/gprover/RatioSeg.java b/src/main/java/gprover/RatioSeg.java index 973cb986..4b6c11c5 100644 --- a/src/main/java/gprover/RatioSeg.java +++ b/src/main/java/gprover/RatioSeg.java @@ -1,12 +1,8 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:50 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Represents a ratio segment in a geometric construction. + */ public class RatioSeg extends CClass { // int type; int lemma; @@ -14,18 +10,16 @@ public class RatioSeg extends CClass { public int[] r; RatioSeg nx; + /** + * The Prover class provides static methods for performing geometric proofs and computations. + * It manages the state of geometric terms and interacts with the geometric database. + * + *This class is not instantiable.
+ */ public RatioSeg() { type = lemma = 0; co = null; r = new int[MAX_GEO]; nx = null; } - - public void cp_ratio(RatioSeg ra) { - lemma = ra.lemma; - for (int i = 0; i <= 8; i++) - r[i] = ra.r[i]; - } - - } diff --git a/src/main/java/gprover/Rule.java b/src/main/java/gprover/Rule.java index b48abb62..289f2362 100644 --- a/src/main/java/gprover/Rule.java +++ b/src/main/java/gprover/Rule.java @@ -1,38 +1,69 @@ package gprover; +/** + * Represents a rule in a geometric construction. + */ public class Rule extends CClass { + /** Constant for split angle type. */ public final static int SPLIT_ANGLE = 0; + + /** Constant for P angle type. */ public final static int P_ANGLE = 1; + + /** Constant for T angle type. */ public final static int T_ANGLE = 2; + + /** Constant for external angle type. */ public final static int EX_ANGLE = 3; - public final static int EQ_ANGLE = 4; + /** Constant for equal angle type. */ + public final static int EQ_ANGLE = 4; + /** The type of the rule. */ int type; + + /** The number associated with the rule. */ int no; + + /** Array of Mnde objects associated with the rule. */ public Mnde[] mr1 = new Mnde[5]; - public Mnde mr; + /** The main Mnde object associated with the rule. */ + public Mnde mr; + /** Reference to the next Rule object. */ Rule nx; + + /** + * Constructs a Rule object with a specified type. + * + * @param t the type of the rule + */ public Rule(int t) { type = t; nx = null; mr = null; } - public void cp_rule(Rule r) - { + /** + * Copies the properties of another Rule object to this Rule object. + * + * @param r the Rule object to copy from + */ + public void cp_rule(Rule r) { type = r.type; no = r.no; - for(int i=0; i <5 ; i++) + for (int i = 0; i < 5; i++) mr1[i] = r.mr1[i]; } - public String toString() - { + /** + * Returns a string representation of the rule. + * + * @return a string representation of the rule + */ + public String toString() { return " because " + text; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Rules.java b/src/main/java/gprover/Rules.java index 3da2f90f..8050b273 100644 --- a/src/main/java/gprover/Rules.java +++ b/src/main/java/gprover/Rules.java @@ -1,5 +1,11 @@ package gprover; +/** + * Rules class holds the translated geometric rules and full angle definitions. + * The arrays defined in this class provide language-specific translations for + * geometric construction rules and full angle definitions. These translations are + * integrated with a gettext-based internationalization system. + */ public class Rules { // All of these translations are now in the keys.pot and *.po files in the gettext system. diff --git a/src/main/java/gprover/STris.java b/src/main/java/gprover/STris.java index b226f5cd..ce826ca0 100644 --- a/src/main/java/gprover/STris.java +++ b/src/main/java/gprover/STris.java @@ -1,11 +1,6 @@ package gprover; - /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 23, 2006 - * Time: 10:45:54 AM - * To change this template use File | Settings | File Templates. + * Constructs a SimTri object with default values. */ public class STris extends CClass { static int MAX_TRI = 300; @@ -18,6 +13,9 @@ public class STris extends CClass { STris nx; + /** + * Constructs an STris object with default values. + */ public STris() { type = 0; dr = new int[300]; diff --git a/src/main/java/gprover/SimTri.java b/src/main/java/gprover/SimTri.java index 14105e58..94e9cff7 100644 --- a/src/main/java/gprover/SimTri.java +++ b/src/main/java/gprover/SimTri.java @@ -1,12 +1,11 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:25 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Rules class holds the translated geometric rules and full angle definitions. + * The arrays defined in this class provide language-specific translations for + * geometric construction rules and full angle definitions. These translations are + * integrated with a gettext-based internationalization system. + */ public class SimTri extends CClass { int lemma; Cond co; @@ -18,6 +17,9 @@ public class SimTri extends CClass { SimTri nx; + /** + * Constructs a SimTri object with default values. + */ public SimTri() { type = lemma = 0; co = null; diff --git a/src/main/java/gprover/TLine.java b/src/main/java/gprover/TLine.java index 82539a98..e6aca36c 100644 --- a/src/main/java/gprover/TLine.java +++ b/src/main/java/gprover/TLine.java @@ -1,23 +1,28 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:33:44 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Constructs an STris object with default values. + */ public class TLine extends CClass { int lemma; Cond co; public LLine l1, l2; TLine nx; + /** + * Constructs a TLine object with specified line segments. + * + * @param l1 the first line segment + * @param l2 the second line segment + */ public TLine(LLine l1, LLine l2) { this.l1 = l1; this.l2 = l2; } + /** + * Constructs a TLine object with default values. + */ public TLine() { type = lemma = 0; co = null; diff --git a/src/main/java/gprover/Var.java b/src/main/java/gprover/Var.java index 1fa309c8..3376d229 100644 --- a/src/main/java/gprover/Var.java +++ b/src/main/java/gprover/Var.java @@ -1,12 +1,5 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-14 - * Time: 13:31:19 - * To change this template use File | Settings | File Templates. - */ public class Var { int nm; char[] p = new char[9]; @@ -15,10 +8,20 @@ public class Var { String sd = null; - public Var() { - - } - + /** + * Constructs a Var object with default values. + */ + public Var() { } + + /** + * Constructs a Var object with specified values. + * + * @param n the name of the variable + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ public Var(int n, int p1, int p2, int p3, int p4) { nm = n; pt[0] = p1; @@ -27,28 +30,19 @@ public Var(int n, int p1, int p2, int p3, int p4) { pt[3] = p4; } - public void revert() { - int k = pt[0]; - pt[0] = pt[2]; - pt[2] = k; - - k = pt[1]; - pt[1] = pt[3]; - pt[3] = k; - } - - public Var(Var v) { - nm = v.nm; - pt[0] = v.p[0]; - pt[1] = v.p[1]; - pt[2] = v.p[2]; - pt[3] = v.p[3]; - } - + /** + * Returns the string representation of the variable. + * + * @return the string representation of the variable + */ + @Override public String toString() { return sd; } + /** + * Constructs a TLine object with default values. + */ public void setString(String s) { sd = s; } diff --git a/src/main/java/gprover/Wu.java b/src/main/java/gprover/Wu.java deleted file mode 100644 index 6c68e612..00000000 --- a/src/main/java/gprover/Wu.java +++ /dev/null @@ -1,895 +0,0 @@ -package gprover; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Jan 9, 2007 - * Time: 12:08:27 PM - * To change this template use File | Settings | File Templates. - */ -public class Wu extends Poly { - static boolean div_factor = true; - static boolean del_linear = false; - static char pri_ind; - static XTerm[] inits; - DTerm l_set, div_set, tri_set, conc_set, conc_cp; - boolean print_pind; - int max_termp, max_term, vec_co = 0; - - - void prove_wu() { - DTerm dp1, dp2; - - get_divs(); - l_set.nx = null; - lt_set(); - tri_set.nx = prem_ps_asc(tri_set.nx, l_set.nx); - dp1 = conc_set.nx; - while (dp1 != null) { - dp1.p = prem_asc(dp1.p, l_set.nx); - dp1 = dp1.nx; - } - - dp1 = tri_set.nx; - while (dp1 != null) { - dp1.p = cprim(dp1.p); - dp1 = dp1.nx; - } - dp1 = conc_set.nx; - while (dp1 != null) { - dp1.p = cprim(dp1.p); - dp1 = dp1.nx; - } - - if (print_pind && l_set.nx != null) { -// gprint(Cm.s2830); -// dprint(l_set.nx); -// gprint(Cm.s2831); -// dprint(tri_set.nx); -// gprint(Cm.s2832); -// dprint(conc_set.nx); - } - - pri_ind = 1; - if (print_pind) { -// gprint(Cm.s2833)); - } - - - dp1 = conc_set.nx; - if (print_pind) { - print_ind(dp1.p); - gprint("\r\n"); - } - for (; dp1 != null; dp1 = dp1.nx) { - dp1.deg = 1; - dp2 = prem_asc_p(dp1.p, tri_set.nx); - dp1.p = null; - if (dp2 == null) { - dp1.deg = 1; - } else { - dp1.deg = 0; - put_ps(dp2); - } - } - show_conc(); - } - - void show_conc() { - DTerm dp1 = conc_set.nx; - int count = 1; - while (dp1 != null) { - if (dp1.deg == 0) count = 0; - dp1 = dp1.nx; - } - //gprint("\n***************The results****************\n"); - if (count != 0) { -// pro_result = 1; -// gprint("\r\n"); -// gprint(Cm.s2050)); - } else { -// pro_result = -1; -// gprint("\r\n"); -// if (irr_thm()) -// gprint(Cm.s2056)); -// else -// gprint(Cm.s2051)); - - } - } - - - void get_divs() { - char i, k; - DTerm dp1, dp2; - - for (i = 0; i < 50; i++) inits[i] = null; - k = 2; - dp1 = tri_set.nx; - if (dp1 == null) return; - dp2 = dp1.nx; - while (dp2 != null) { - if ((dp1.deg == 1) && (dp2.deg == 2)) { - inits[++k] = cp_init(dp1.p); - dp2.deg = k; - } else - dp2.deg = 0; - dp1 = dp2; - dp2 = dp2.nx; - } - } - - void lt_set() { - DTerm dp1, dp2, dp3; - dp1 = tri_set; - dp2 = dp1.nx; - l_set.nx = null; - dp3 = l_set; - while (dp2 != null) { - if (del_linear && (ldeg(dp2.p) == 1) && (numberp(init(dp2.p)))) { - dp1.nx = dp2.nx; - dp3.nx = dp2; - dp3 = dp3.nx; - dp2 = dp1.nx; - } else if (plength(dp2.p) > 2) { - dp1 = dp2; - dp2 = dp1.nx; - } else if (ldeg(dp2.p) != 1) { - dp1 = dp2; - dp2 = dp1.nx; - } else { - dp1.nx = dp2.nx; - dp3.nx = dp2; - dp3 = dp2; - dp2 = dp1.nx; - } - } - dp3.nx = null; - } - - XTerm prem_asc(XTerm p, DTerm asc) { - DTerm dp1; - for (dp1 = asc; dp1 != null; dp1 = dp1.nx) { - p = cprim(prem(p, dp1.p)); - } - return (p); - } - - DTerm prem_ps_asc(DTerm ps, DTerm asc) { - DTerm dt1, dp1, dp2; - if (asc == null) return (ps); - - dt1 = new DTerm(); - dt1.nx = ps; - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - dp2.p = mv_nfact(prem_asc(dp2.p, asc)); - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } - return (dt1.nx); - } - -/* prem-asc_p: the branching version */ - DTerm prem_asc_p(XTerm p, DTerm asc) -//xterm p; -//dterm asc; - { - XTerm a1, p1, p2; - DTerm dt1, dp1, dp2, dp3; - int tem; - - if (p == null) return (null); - if (pzerop(p)) { - put_p(p); - return (null); - } else if (p.var == null) { - return (get_dt(0, p, null)); - } - - dt1 = new DTerm(); - dt1.nx = get_dt(1, p, null); - /*at.deg=0; at.nx=asc; asc0= &at; */ - for (; asc != null; asc = asc.nx) { - a1 = asc.p; -// pprint(a1);gprint(" 1\r\n"); - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - p1 = dp2.p; - //pprint(p1);gprint(" 2\r\n"); - //sprintf(txt,"(%d)(%d)\r\n",a1->var,p1->var); - //gprint(txt); - if (pzerop(p1)) { - dp1.nx = dp2.nx; - put_x(p1); - put_d(dp2); - dp2 = dp1.nx; - } else if (p1.var == null) { - dp1 = dp2; - dp2 = dp1.nx; - } else if (p1.var == a1.var) { - /*printf("prem-asc-p1(%d)\n",plength(p1)); */ - p2 = prem_ev(p1, a1); - /*printf("prem-asc-p2(%d)\n",plength(p2)); */ - dp2.p = cprim(p2); - /*printf("prem-asc-p3(%d)\n",plength(dp2->p)); */ - /*dp2->p=cprim(prem_ev(p1,a1)); */ - /* printf("prem-asc-p1\n"); pprint(dp2->p);pprint(a1); */ - if (print_pind && dp2.deg == 1) { - if (pzerop(dp2.p)) { - if (pri_ind == 1) { - print_ind(dp2.p); - gprint("\r\n"); - pri_ind = 0; - } - } else { - print_ind(dp2.p); - gprint("\r\n"); - } - } - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - if (max_termp > 0) { - tem = plength(dp2.p); - if (tem > max_term) max_term = tem; - } - if (div_factor && asc.deg > 2) { -/* printf("1111(%d)\n",asc->deg); pprint(inits[asc->deg]); */ - p2 = mv_mfact(prem_asc(cp_poly(inits[asc.deg]), l_set.nx)); - dp2.p = ppdiv(dp2.p, p2); - put_p(p2); - } - dp1 = dp2; - dp2 = dp1.nx; - } - } else if (vless(a1.var, p1.var)) { - dp3 = p1.ps; - dp3.deg = 1; - while (dp3.nx != null) { - dp3 = dp3.nx; - dp3.deg = 1; - } - dp3.nx = dp2.nx; - dp1.nx = p1.ps; - put_d(dp2); - dp2 = dp1.nx; - put_x(p1); - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } /* dp2= null */ - /*asc0=asc; */ - } /*asc=null */ - return (dt1.nx); - } - - DTerm nonzerops(DTerm dp) { - DTerm dt1, dp1, dp2; - dt1 = new DTerm(); - dt1.nx = dp; - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } - return (dt1.nx); - } - -/* remove all the numerical factors */ - - XTerm cprim(XTerm p1) { - XTerm pp1; - int i; - if (pzerop(p1)) - return (p1); - else if (p1.var == null) { - put_p(p1); - return (get_n(1L)); - } else { /*printf("cp1(%d)\n",plength(p1)); */ - i = lcontent(p1); - /*printf("cp2(%d)(%d)\n",type_of(i),fix(i)); */ - if (num_unit(i)) return (p1); - if (num_nunit(i)) { - p1 = ptimes(get_n(-1L), p1); - return (p1); - } - { - pp1 = get_num(i); - p1 = pcdiv(p1, pp1); - put_x(pp1); - return (p1); - } - } - } - - XTerm mv_mfact(XTerm p1) { - XTerm pp1; - if (pzerop(p1)) - return (p1); - else if (p1.var == null) { - put_p(p1); - return (get_n(1L)); - } else { - pp1 = cprim(cp_init(p1)); - if (pp1.var != null) p1 = ppdiv(p1, pp1); - put_p(pp1); - p1 = cprim(p1); - return (p1); - } - } - - XTerm mv_nfact(XTerm p) { - XTerm p1, p2; - int d1; - int c; - if (pzerop(p)) - return (p); - else if (p.var == null) { - put_p(p); - return (get_n(1L)); - } - p1 = vars_in_p(init(p)); - while (p1 != null) { - d1 = mdeg(p, p1.var); - if (d1 > 0) { - p2 = get_v(p1.var, d1, get_n(1L)); - p = pdiv(p, p2); - put_p(p2); - } - p2 = p1; - p1 = p1.p; - put_x(p2); - } - c = lcontent(p); - if (num_nunit(c)) { - p1 = get_num(c); - p = ptimes(p, p1); - } else if (!num_unit(c)) { - p1 = get_num(c); - p = pcdiv(p, p1); - put_x(p1); - } - return (p); - } - - XTerm gq2co(XTerm p) { - Var v; - XTerm p1 = new XTerm(); - v = p.var; - while (v != null && v.nm > 0 && v.nm < 100) { - switch (v.nm) { - case 1: - if (xperp(1, 2, v.pt[0], v.pt[1])) - p1 = pminus(ptimes(get_m(v), pminus(yw(v.pt[3]), yw(v.pt[2]))), - pminus(yw(v.pt[1]), yw(v.pt[0]))); - else - p1 = pminus(ptimes(get_m(v), pminus(xw(v.pt[3]), xw(v.pt[2]))), - pminus(xw(v.pt[1]), xw(v.pt[0]))); - break; - case 2: - p1 = pminus(ptimes(get_m(v), get_n(2)), - pminus(carea(v.pt[0], v.pt[1], v.pt[3]), - carea(v.pt[2], v.pt[1], v.pt[3]))); - break; - case 3: - p1 = pminus(get_m(v), - pminus(pplus(cdis(v.pt[0], v.pt[1]), cdis(v.pt[2], v.pt[3])), - pplus(cdis(v.pt[1], v.pt[2]), cdis(v.pt[3], v.pt[0])))); - break; - case 4: - if (v.pt[1] == 0 && vec_co == 1) { - p1 = pminus(get_m(v), xw(v.pt[0])); - } else if (v.pt[1] == 0) { - p1 = pminus(get_m(v), yw(v.pt[0])); - } else if (vec_co == 1) { - p1 = pminus(get_m(v), pminus(xw(v.pt[1]), xw(v.pt[0]))); - } else { - p1 = pminus(get_m(v), pminus(yw(v.pt[1]), yw(v.pt[0]))); - } - break; - default: - gerror("gq2co"); - } - p = prem_var(p, p1, v); - put_p(p1); - v = p.var; - } - return (p); - } - - - XTerm cdis(int n1, int n2) -//int n1,n2; - { - if (n1 == n2) - return (get_n(0L)); - else - return (pplus(ppower(pminus(xw(n1), xw(n2)), 2), - ppower(pminus(yw(n1), yw(n2)), 2))); - } - - XTerm carea(int n1, int n2, int n3) -//int n1,n2,n3; - { - return (pplus3(pminus(ptimes(xw(n1), yw(n2)), ptimes(xw(n2), yw(n1))), - pminus(ptimes(xw(n2), yw(n3)), ptimes(xw(n3), yw(n2))), - pminus(ptimes(xw(n3), yw(n1)), ptimes(xw(n1), yw(n3))))); - } - - -/* */ - - void eq_l(XTerm q1) { - DTerm dp1; - XTerm pp1; - XTerm p1 = cp_poly(q1); - - pp1 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(pp1)) { - dp1 = tri_set.nx; - tri_set.nx = get_dt(0, mv_mfact(rem(p1)), dp1); - } else { - dp1 = tri_set.nx; - tri_set.nx = get_dt(0, mv_mfact(p1), dp1); - } - put_p(pp1); - } - - void eq_ll(XTerm q1, XTerm q2) { - XTerm p3, p4; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); -/* - printf("\eqll1(%ld)(%ld)\n",p1->var,p2->var); - printf("\neqll2(%d)\n",p1->var==p2->var); - pprint(p1);pprint(p2); -*/ - if (p1.var == p2.var) { - if (pls(p2, p1)) { - p3 = p1; - p1 = p2; - p2 = p3; - } - p4 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p4)) { - p1 = prem(p1, p2); - if (pzerop(p1)) { - gerror("eq_ll: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p2), tri_set.nx); - } else { - p2 = prem(p2, p1); - if (pzerop(p2)) { - gerror("eq_ll: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - } - put_p(p4); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_lq(XTerm q1, XTerm q2) { - XTerm p3; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - if (p1.var == p2.var) { - p3 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p3)) { - p1 = rem(p1); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } else { - p2 = prem(p2, p1); - if (pzerop(p2)) { - gerror("eq_lq: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - } - put_p(p3); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_lq1(XTerm q1, XTerm q2, int pt) { - XTerm p3, pp1; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - if (p1.var == p2.var) { - p3 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p3)) { - p1 = rem(p1); - p2 = prem(p2, p1); - pp1 = pminus(get_m(p2.var), yw(pt)); - } else { - p2 = prem(p2, p1); - pp1 = pminus(get_m(p2.var), xw(pt)); - } - p2 = pdiv(p2, pp1); - put_p(pp1); - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - put_p(p3); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_qq(XTerm q1, XTerm q2) { - XTerm pp1; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - pp1 = pminus(p2, cp_poly(p1)); - p2 = prem(p1, pp1); - tri_set.nx = get_dt(2, p2, tri_set.nx); - tri_set.nx = get_dt(1, pp1, tri_set.nx); - } - - void eq_qq1(XTerm q1, XTerm q2, int pt) { - XTerm pp1, pp2; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - pp1 = pminus(p2, cp_poly(p1)); - p2 = prem(p1, pp1); - pp2 = pminus(get_m(p2.var), xw(pt)); - p2 = pdiv(p2, pp2); - put_p(pp2); - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(pp1), tri_set.nx); - } - -// PP eq_lq4(xterm p1, xterm p2, int pt) { -// xterm pp1; -// PP pp; -// if (p1.var == p2.var) { -// p2 = prem(p2, p1); -// pp1 = pminus(get_m(p2.var), xw(pt)); -// p2 = pdiv(p2, pp1); -// put_p(pp1); -// pp.p1 = mv_mfact(p2); -// pp.p2 = mv_mfact(p1); -// } else if (vless(p2.var, p1.var)) { -// pp.p1 = mv_mfact(p2); -// pp.p2 = mv_mfact(p1); -// } else { -// pp.p1 = mv_mfact(p1); -// pp.p2 = mv_mfact(p2); -// } -// return (pp); -// } - - void init_wu() { - int i; - tri_set.nx = null; - l_set.nx = null; - conc_set.nx = null; - div_set.nx = null; - for (i = 1; i < 100; i++) { -// hyp_set[i].p1 = null; -// hyp_set[i].p2 = null; - } - for (i = 0; i < 50; i++) inits[i] = null; - } - - void free_wu() { - DTerm ps1, ps2; - int i; - - put_ps(tri_set.nx); - put_ps(l_set.nx); - ps1 = conc_set.nx; - while (ps1 != null) { - if (ps1.p != null) put_p(ps1.p); - ps2 = ps1.nx; - put_d(ps1); - ps1 = ps2; - } - tri_set.nx = null; - l_set.nx = null; - conc_set.nx = null; - - if (pro_type == PRO_WU) { - for (i = 0; i < 50; i++) { /*printf("(%d)\n", inits[i]); */ - if (inits[i] != null) { - put_p(inits[i]); - inits[i] = null; - } - } - } - if (pro_type == PRO_GB) { - ps1 = div_set.nx; - while (ps1 != null) { - ps2 = ps1; - ps1 = ps1.nx; - put_p(ps2.p); - put_d(ps2); - } - div_set.nx = null; - } -// for (i = 1; i < 100; i++) { -// if (hyp_set[i].p1) put_p(hyp_set[i].p1); -// if (hyp_set[i].p2) put_p(hyp_set[i].p2); -// hyp_set[i].p1 = null; -// hyp_set[i].p2 = null; -// } - } - - - boolean irr_thm() { - int[] p = new int[10]; - - - int j; - boolean th_p = false; - for (int ptn = 1; ptn <= cons_no; ptn++) { - for (j = 0; j <= 5; j++) p[j + 1] = APTS(ptn, j); - switch (ATYPE(ptn)) { - case C_I_LC: - if (p[2] == p[4] || p[1] == p[4]) { - th_p = true; - break; - } - break; - case C_I_PC: - case C_I_TC: - if (p[1] == p[5]) { - th_p = true; - break; - } - break; - case C_I_CC: - if (p[2] != p[4]) { - th_p = true; - break; - } - break; - case C_I_LR: - case C_I_CR: - case C_I_RR: - th_p = true; - break; - } - } - return th_p; - } - - - /////////////////////////////////////////////////////////////////////// - //from eqs.cpp - - XTerm coll(int p1, int p2, int p3) { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p3), yw(p1)), pminus(xw(p2), xw(p1))), - ptimes(pminus(xw(p3), xw(p1)), pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm para(int p1, int p2, int p3, int p4) { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p4), yw(p3)), - pminus(xw(p2), xw(p1))), - ptimes(pminus(xw(p4), xw(p3)), - pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm perp(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - XTerm xp1; - xp1 = pplus(ptimes(pminus(yw(p4), yw(p3)), - pminus(yw(p2), yw(p1))), - ptimes(pminus(xw(p4), xw(p3)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm yratio(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) -//int p1,p2,p3,p4,p5,p6,p7,p8; - { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p4), yw(p3)), - pminus(yw(p6), yw(p5))), - ptimes(pminus(yw(p8), yw(p7)), - pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm xratio(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) -//int p1,p2,p3,p4,p5,p6,p7,p8; - { - XTerm xp1; - xp1 = pminus(ptimes(pminus(xw(p4), xw(p3)), - pminus(xw(p6), xw(p5))), - ptimes(pminus(xw(p8), xw(p7)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm eqptx(int p1, int p2) { - XTerm xp1; - xp1 = pminus(xw(p1), xw(p2)); - return (xp1); - } - - XTerm eqpty(int p1, int p2) -//int p1,p2; - { - XTerm xp1; - xp1 = pminus(yw(p1), yw(p2)); - return (xp1); - } - - XTerm midx(int p1, int p2, int p3) -//int p1,p2,p3; - { - XTerm xp1; - xp1 = pminus(pplus(xw(p2), xw(p3)), ptimes(get_n(2L), xw(p1))); - return (xp1); - } - - XTerm midy(int p1, int p2, int p3) -//int p1,p2,p3; - { - XTerm xp1; - xp1 = pminus(pplus(yw(p2), yw(p3)), ptimes(get_n(2L), yw(p1))); - return (xp1); - } - - XTerm dist(int p1, int p2) { - XTerm xp1; - xp1 = pplus(ptimes(pminus(yw(p2), yw(p1)), - pminus(yw(p2), yw(p1))), - ptimes(pminus(xw(p2), xw(p1)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm cong(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - XTerm xp1; - xp1 = pminus(dist(p1, p2), dist(p3, p4)); - return (xp1); - } - - XTerm acong(int p1, int p2, int p3, int p4, int p5, int p6) -//int p1,p2,p3,p4,p5,p6; - { - XTerm xp1; - xp1 = pminus(ptimes(para(p3, p2, p1, p2), perp(p6, p5, p4, p5)), - ptimes(para(p6, p5, p4, p5), perp(p3, p2, p1, p2))); - return (xp1); - } - - XTerm tcc(int o1, int p1, int o2, int p2) -//int o1,p1,o2,p2; - { - XTerm xp1, rp1, rp2; - rp1 = ptimes(dist(o1, p1), dist(o1, p1)); - rp2 = ptimes(dist(o2, p2), dist(o2, p2)); - rp1 = pplus(rp1, rp2); - xp1 = ptimes(dist(o1, o2), dist(o1, o2)); - xp1 = pplus(rp1, xp1); - - rp1 = ptimes(dist(o1, p1), dist(o2, p2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - rp1 = ptimes(dist(o1, p1), dist(o1, o2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - rp1 = ptimes(dist(o2, p2), dist(o1, o2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - return (xp1); - } - - XTerm pratiox(int y, int w, int u, int v, XTerm p1, XTerm p2) -//int y,w,u,v; -//xterm *p1,*p2; - { - return (pminus(ptimes(p2, pminus(xw(y), xw(w))), - ptimes(p1, pminus(xw(v), xw(u))))); - } - - XTerm pratioy(int y, int w, int u, int v, XTerm p1, XTerm p2) -//int y,w,u,v; -//xterm *p1,*p2; - { - return (pminus(ptimes(p2, pminus(yw(y), yw(w))), - ptimes(p1, pminus(yw(v), yw(u))))); - } - - -// xterm tratioc(int y, int w, int u, int v, xterm p1, xterm p2) -////int y,w,u,v; -////xterm *p1,*p2; -// { -// xterm p0; -// //xterm *trim_a(), *trim_g(); -// p0 = pminus(ptimes3(get_n(4L), p2, trim_a(y, u, w, v)), -// ptimes(p1, trim_g(u, u, v, v))); -// return (p0); -// } - - void print_coor() { - } - - int cx(int n) { - int k; - if (pro_type == PRO_GB && ATYPE(n) == C_POINT) { - if (n == 2) k = -1; else k = -2 * (n - 2); - } else if (pro_type == PRO_GB && ATYPE(n) == C_O_C) { - k = -2 * (n - 2); - } else { - if (n == 2) k = 1; else k = 2 * (n - 2); - } - return (k); - } - - int cy(int n) { - int k; - if (pro_type == PRO_GB && ATYPE(n) == C_POINT) { - k = -2 * (n - 2) - 1; - } else { - k = 2 * (n - 2) + 1; - } - return (k); - } - - XTerm xw(int n) { - if (n == 1) return (get_n(0L)); - return (get_m(mk_wvar(cx(n)))); - } - - XTerm yw(int n) { - if (n == 1 || n == 2) return (get_n(0L)); - return (get_m(mk_wvar(cy(n)))); - } - -} diff --git a/src/main/java/gprover/XTerm.java b/src/main/java/gprover/XTerm.java index b27d221b..89a8bf67 100644 --- a/src/main/java/gprover/XTerm.java +++ b/src/main/java/gprover/XTerm.java @@ -1,11 +1,8 @@ package gprover; + /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-4 - * Time: 11:32:50 - * To change this template use File | Settings | File Templates. + * Constructs a Var object with default values. */ public class XTerm { public Var var; // variable @@ -14,6 +11,9 @@ public class XTerm { XTerm p; String sd; + /** + * Constructs an XTerm object with default values. + */ public XTerm() { var = null; c = 0; @@ -21,20 +21,39 @@ public XTerm() { p = null; } + /** + * Returns the value of the prefix term. + * + * @return the value of the prefix term + */ public long getPV() { if (ps == null || ps.p == null) return 0; return ps.p.c; } + /** + * Returns the string representation of the term. + * + * @return the string representation of the term + */ + @Override public String toString() { return sd; } + /** + * Removes the leading '+' character from the string representation of the term. + */ public void cutMark() { if (sd != null && sd.trim().startsWith("+")) sd = sd.trim().substring(1); } + /** + * Returns the trimmed string representation of the term without the leading '+' character. + * + * @return the trimmed string representation of the term + */ public String getString() { if (sd == null) return null; String t = sd.trim(); @@ -43,6 +62,11 @@ public String getString() { return t; } + /** + * Returns the number of terms in the linked list of terms. + * + * @return the number of terms in the linked list of terms + */ public int getTermNumber() { XTerm t = this; int n = 0; From c5384a7993b0b191be01d6987d1daae38300ec41 Mon Sep 17 00:00:00 2001 From: Philip Hallwirth <37780428+Traumlos@users.noreply.github.com> Date: Fri, 28 Mar 2025 00:37:17 +0100 Subject: [PATCH 04/10] partial superficial refactor and added java doc to wprover folder --- src/main/java/wprover/AboutDialog.java | 10 +- src/main/java/wprover/AllSolutionDialog.java | 48 +- src/main/java/wprover/AnimateC.java | 21 - src/main/java/wprover/AnimatePanel.java | 8 - src/main/java/wprover/AttrToCondDialog.java | 16 +- src/main/java/wprover/CAngle.java | 53 - src/main/java/wprover/CArrow.java | 7 +- src/main/java/wprover/CBoolean.java | 7 +- src/main/java/wprover/CClass.java | 79 +- src/main/java/wprover/CCoBox.java | 17 +- src/main/java/wprover/CDialogProve.java | 36 +- src/main/java/wprover/CDistance.java | 9 +- src/main/java/wprover/CLine.java | 573 ++- src/main/java/wprover/CMisc.java | 8 +- src/main/java/wprover/CPoint.java | 278 +- src/main/java/wprover/CPolygon.java | 541 ++- src/main/java/wprover/CProperty.java | 217 +- src/main/java/wprover/CProveBarPanel.java | 38 +- src/main/java/wprover/CProveField.java | 360 +- src/main/java/wprover/CProveText.java | 494 ++- src/main/java/wprover/CStyleDialog.java | 109 +- src/main/java/wprover/CTMark.java | 79 +- src/main/java/wprover/CText.java | 272 +- src/main/java/wprover/CTextValue.java | 184 +- src/main/java/wprover/CTrace.java | 188 +- src/main/java/wprover/Cedmark.java | 18 +- src/main/java/wprover/Circle.java | 113 +- src/main/java/wprover/ColorButtonPanel.java | 48 +- src/main/java/wprover/ColorComboRender.java | 36 +- src/main/java/wprover/ColorMenu.java | 87 +- src/main/java/wprover/ConcDialog.java | 294 +- src/main/java/wprover/ConcPanel.java | 238 +- src/main/java/wprover/Constraint.java | 1374 ++++--- src/main/java/wprover/DPanel.java | 157 +- src/main/java/wprover/DiagramUpdater.java | 12 +- src/main/java/wprover/DialogProperty.java | 12 +- src/main/java/wprover/DialogPsProperty.java | 40 +- src/main/java/wprover/DrawBase.java | 736 +++- src/main/java/wprover/DrawData.java | 164 +- src/main/java/wprover/DrawProcess.java | 3384 +++++++++++------- src/main/java/wprover/DrawTextProcess.java | 591 ++- src/main/java/wprover/DrawType.java | 87 +- src/main/java/wprover/FactFinderDialog.java | 38 +- src/main/java/wprover/FloatableToolBar.java | 65 +- src/main/java/wprover/GExpert.java | 128 +- src/main/java/wprover/GeoPoly.java | 681 +++- 46 files changed, 8085 insertions(+), 3870 deletions(-) diff --git a/src/main/java/wprover/AboutDialog.java b/src/main/java/wprover/AboutDialog.java index cc85c2cc..c0104e87 100644 --- a/src/main/java/wprover/AboutDialog.java +++ b/src/main/java/wprover/AboutDialog.java @@ -9,16 +9,12 @@ import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; - /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-8-19 - * Time: 11:35:20 - * To change this template use File | Settings | File Templates. + * The `AboutDialog` class represents a custom popup dialog that displays information about the application. + * It extends `JPopupMenu` and implements `MouseListener` to handle mouse events. + * The dialog includes labels, panels, and a text pane with information about the application and its authors. */ public class AboutDialog extends JPopupMenu implements MouseListener { - JLabel b2; Color color = new Color(206, 223, 242); GExpert gx; diff --git a/src/main/java/wprover/AllSolutionDialog.java b/src/main/java/wprover/AllSolutionDialog.java index 5500cf3b..8a1d9ee6 100644 --- a/src/main/java/wprover/AllSolutionDialog.java +++ b/src/main/java/wprover/AllSolutionDialog.java @@ -10,15 +10,6 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.Vector; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-8-3 - * Time: 18:30:46 - * To change this template use File | Settings | File Templates. - */ - /** * The `AllSolutionDialog` class provides a dialog for displaying and interacting with * all possible solutions of a given problem within the GExpert application. @@ -297,27 +288,60 @@ public void setVisible(boolean b) { gxInstance.d.repaint(); } + /** + * Invoked when a window has been opened. + * + * @param e the event to be processed + */ public void windowOpened(WindowEvent e) { } + /** + * Invoked when the user attempts to close the window from the window's system menu. + * + * @param e the event to be processed + */ public void windowClosing(WindowEvent e) { } + /** + * Invoked when a window has been closed. + * + * @param e the event to be processed + */ public void windowClosed(WindowEvent e) { } + /** + * Invoked when a window is changed from a normal to a minimized state. + * + * @param e the event to be processed + */ public void windowIconified(WindowEvent e) { } + /** + * Invoked when a window is changed from a minimized to a normal state. + * + * @param e the event to be processed + */ public void windowDeiconified(WindowEvent e) { } + /** + * Invoked when a window is activated. + * + * @param e the event to be processed + */ public void windowActivated(WindowEvent e) { } + /** + * Invoked when a window is deactivated. + * + * @param e the event to be processed + */ public void windowDeactivated(WindowEvent e) { } -} - - +} \ No newline at end of file diff --git a/src/main/java/wprover/AnimateC.java b/src/main/java/wprover/AnimateC.java index 7d400561..0aaeed68 100644 --- a/src/main/java/wprover/AnimateC.java +++ b/src/main/java/wprover/AnimateC.java @@ -3,15 +3,6 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.DataInputStream; - -/** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-14 - * Time: 13:37:42 - * To change this template use File | Settings | File Templates. - */ - /** * The `AnimateC` class represents the animation control for a geometric object in the GExpert application. * It provides methods to animate a point along a line, circle, or trace path. @@ -255,12 +246,6 @@ public int getInitValue() { return (int) gap; } - public void valueChanged(int v) { - if (onType == 1 || onType == 2) { - gap = v + delta; - } - } - AnimateC(CPoint p, Object obj, double width, double height) { pA = p; onObj = obj; @@ -432,12 +417,6 @@ public boolean onTimer() { return r; } - public void onFailed() { - if (onType == 2) { - sia = -sia; - } - } - /** * Saves the current state of the animation to an output stream. * diff --git a/src/main/java/wprover/AnimatePanel.java b/src/main/java/wprover/AnimatePanel.java index be6d8594..36f49094 100644 --- a/src/main/java/wprover/AnimatePanel.java +++ b/src/main/java/wprover/AnimatePanel.java @@ -292,14 +292,6 @@ public void setStatus() { } } - /** - * Handles window opened events (empty implementation). - * - * @param e the window event - */ - public void windowOpened(WindowEvent e) { - } - /** * Sets the visibility of this panel. * diff --git a/src/main/java/wprover/AttrToCondDialog.java b/src/main/java/wprover/AttrToCondDialog.java index 551d19cd..22e7e125 100644 --- a/src/main/java/wprover/AttrToCondDialog.java +++ b/src/main/java/wprover/AttrToCondDialog.java @@ -10,11 +10,9 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 26, 2006 - * Time: 5:52:40 PM - * To change this template use File | Settings | File Templates. + * AttrToCondDialog is a dialog class that allows users to select geometric attributes + * and convert them into conditions for geometric proofs. + * It provides a graphical interface for selecting points, lines, angles, and triangles. */ public class AttrToCondDialog extends JBaseDialog { final private static int ROW = 5; @@ -149,6 +147,11 @@ public Dimension getPreferredSize() { addComp(); } + /** + * Constructor for creating an AttrToCondDialog for parallel lines. + * @param gx GExpert instance + * @param pn PLine instance + */ public AttrToCondDialog(GExpert gx, PLine pn) { this(gx, "Please select two lines"); @@ -162,6 +165,9 @@ public Dimension getPreferredSize() { addComp(); } + /** + * Adds components to the content pane and sets the dialog properties. + */ public void addComp() { Window gx = this.getOwner(); contentPane.add(topPane); diff --git a/src/main/java/wprover/CAngle.java b/src/main/java/wprover/CAngle.java index e01d7e58..92fa6ed6 100644 --- a/src/main/java/wprover/CAngle.java +++ b/src/main/java/wprover/CAngle.java @@ -8,14 +8,6 @@ import gprover.Cm; -/** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-15 - * Time: 11:22:15 - * To change this template use File | Settings | File Templates. - */ - /** * Class representing an angle in a geometric construction. */ @@ -121,19 +113,6 @@ public boolean isSame(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return false; } - /** - * Checks if two sets of points are the same. - * - * @param p1 The first point of the first set. - * @param p2 The second point of the first set. - * @param p3 The first point of the second set. - * @param p4 The second point of the second set. - * @return {@code true} if the two sets of points are the same, {@code false} otherwise. - */ - public boolean isSame_m(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return false; - } - /** * Constructs a CAngle object with specified lines and points. @@ -311,16 +290,6 @@ public int getRadius() { return radius; } - /** - * Sets the name of the angle. - * - * @param s the name of the angle - */ - public void setAngleName(String s) { - if (ptext != null) - ptext.setText(s); - } - /** * Gets the text associated with the angle. * @@ -358,15 +327,6 @@ public String TypeString() { return m_name; } - /** - * Gets the common intersection point of the two lines forming the angle. - * - * @return the intersection point - */ - public CPoint CrossPoint() { - return CLine.commonPoint(this.lstart, this.lend); - } - /** * Gets the description of the angle. @@ -391,19 +351,6 @@ public CPoint getVertex() { return CLine.commonPoint(this.lstart, this.lend); } - /** - * Gets the common line between two angles if they share a common line. - * - * @param g1 the first angle - * @param g2 the second angle - * @return the common line, or null if there is none - */ - public static CLine getCrossLine(CAngle g1, CAngle g2) { - if (g1.lstart == g2.lstart || g1.lstart == g2.lend) return g1.lstart; - if (g1.lend == g2.lstart || g1.lend == g2.lend) return g1.lend; - return null; - } - /** * Checks if two angles can be considered equal based on their common points and lines. * diff --git a/src/main/java/wprover/CArrow.java b/src/main/java/wprover/CArrow.java index 5e780741..f989eedb 100644 --- a/src/main/java/wprover/CArrow.java +++ b/src/main/java/wprover/CArrow.java @@ -7,11 +7,8 @@ import java.io.DataInputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2009-12-13 - * Time: 13:43:52 - * To change this template use File | Settings | File Templates. + * Represents an arrow in a geometric drawing. + * The arrow is defined by its starting and ending points, angle, and length. */ public class CArrow extends CClass { public static int ANGLE = 30; diff --git a/src/main/java/wprover/CBoolean.java b/src/main/java/wprover/CBoolean.java index 2ad788d9..b5d46bd3 100644 --- a/src/main/java/wprover/CBoolean.java +++ b/src/main/java/wprover/CBoolean.java @@ -1,11 +1,8 @@ package wprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-9-20 - * Time: 11:16:25 - * To change this template use File | Settings | File Templates. + * Represents a boolean value that can be modified. + * This class is used to encapsulate a boolean value and provide methods to get and set its value. */ public class CBoolean { diff --git a/src/main/java/wprover/CClass.java b/src/main/java/wprover/CClass.java index cbda76b2..b158150c 100644 --- a/src/main/java/wprover/CClass.java +++ b/src/main/java/wprover/CClass.java @@ -7,14 +7,9 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-8 - * Time: 16:00:08 - * To change this template use File | Settings | File Templates. - * This class serves as the base class for all geometry items. + * CClass is an abstract class representing a geometric object with various properties and methods. + * It serves as a base class for different types of geometric objects. */ -// class as the baseclass for all the geometry item. abstract public class CClass { @@ -317,19 +312,6 @@ void setDrawSelect(Graphics2D g2) { g2.setColor(c); } - /** - * Sets the drawing style for a selected geometry item with a specified width. - * - * @param g2 the Graphics2D object - * @param w the width - */ - void setDrawSelect(Graphics2D g2, int w) { -// float w = (float) drawData.getWidth(m_width); - g2.setStroke(new BasicStroke(w + 5)); - Color c = CMisc.SelectObjectColor; - g2.setColor(c); - } - /** * Sets the drawing style for the geometry item. * @@ -358,63 +340,6 @@ void setDraw(Graphics2D g2) { g2.setPaint(c); } - /** - * Writes a string to the data output stream. - * - * @param out the data output stream - * @param s the string to write - * @throws IOException if an I/O error occurs - */ - public static void WriteString(DataOutputStream out, String s) throws IOException { - out.writeInt(s.length()); - out.writeChars(s); - } - - /** - * Writes the font to the data output stream. - * - * @param out the data output stream - * @param f the font to write - * @throws IOException if an I/O error occurs - */ - public void WriteFont(DataOutputStream out, Font f) throws IOException { - String s = f.getName(); - WriteString(out, s); - out.writeInt(f.getStyle()); - out.writeInt(f.getSize()); - } - - /** - * Reads a string from the data input stream. - * - * @param in the data input stream - * @return the string read from the input stream - * @throws IOException if an I/O error occurs - */ - public static String ReadString(DataInputStream in) throws IOException { - int size = in.readInt(); - if (size == 0) return new String(""); - String s = new String(); - for (int i = 0; i < size; i++) - s += in.readChar(); - return s; - } - - /** - * Reads a font from the data input stream. - * - * @param in the data input stream - * @return the font read from the input stream - * @throws IOException if an I/O error occurs - */ - public Font ReadFont(DataInputStream in) throws IOException { - String name = ReadString(in); - int stye = in.readInt(); - int size = in.readInt(); - - return new Font(name, stye, size); - } - /** * Saves the geometry item to a PostScript file. * diff --git a/src/main/java/wprover/CCoBox.java b/src/main/java/wprover/CCoBox.java index 9d569af2..acd84f2d 100644 --- a/src/main/java/wprover/CCoBox.java +++ b/src/main/java/wprover/CCoBox.java @@ -5,12 +5,8 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-4 - * Time: 14:25:06 - * To change this template use File | Settings | File Templates. - * This class represents a custom JComboBox for color selection. + * CCoBox is a custom JComboBox that displays color options. + * It allows for the creation of multiple instances and provides methods to manage them. */ public class CCoBox extends JComboBox { private static Vector instanceList = new Vector(); @@ -56,15 +52,6 @@ public void setSelectedIndex(int index) { super.setSelectedIndex(index); } - /** - * Sets the default selected index of the combo box. - * - * @param index the default index - */ - public void setDefaultIndex(int index) { - defaultindex = index; - } - /** * Regenerates all instances of CCoBox. */ diff --git a/src/main/java/wprover/CDialogProve.java b/src/main/java/wprover/CDialogProve.java index f27b5203..9394fecc 100644 --- a/src/main/java/wprover/CDialogProve.java +++ b/src/main/java/wprover/CDialogProve.java @@ -12,13 +12,7 @@ import java.io.File; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-4 - * Time: 14:25:06 - * To change this template use File | Settings | File Templates. - * - * This class represents a dialog for proving geometric statements. + * This class represents a dialog for proving geometric terms. */ public class CDialogProve extends JBaseDialog { ProvePane m_cp; @@ -35,16 +29,6 @@ public CDialogProve(GExpert owner) { this.setSize(650, 230); } - /** - * Shows the dialog with the given CProveText. - * - * @param cp the CProveText to display in the dialog - */ - void showDialog(CProveText cp) { - m_cp.setValue(cp); - this.setVisible(true); - } - /** * Sets the selected items in the dialog. * @@ -53,15 +37,6 @@ void showDialog(CProveText cp) { public void setSelect(Vector v) { m_cp.setSelect(v); } - - /** - * Sets the CProveField in the dialog. - * - * @param cpv the CProveField to set - */ - public void setProveField(CProveField cpv) { - m_cp.setProveField(cpv); - } } /** @@ -120,15 +95,6 @@ public Dimension getMaximumSize() { add(createAddressDisplay()); } - /** - * Sets the CProveField for this panel. - * - * @param cpv the CProveField to set - */ - public void setProveField(CProveField cpv) { - Cpv = cpv; - } - /** * Sets the rule list for this panel. */ diff --git a/src/main/java/wprover/CDistance.java b/src/main/java/wprover/CDistance.java index 879589df..624daa17 100644 --- a/src/main/java/wprover/CDistance.java +++ b/src/main/java/wprover/CDistance.java @@ -7,13 +7,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-19 - * Time: 10:16:32 - * To change this template use File | Settings | File Templates. - * - * This class represents a geometric distance between two points. + * Represents a distance measurement between two points in a geometric context. + * This class extends CClass and provides methods for drawing, saving, and loading distance measurements. */ public class CDistance extends CClass { diff --git a/src/main/java/wprover/CLine.java b/src/main/java/wprover/CLine.java index 420c07a2..d056dda8 100644 --- a/src/main/java/wprover/CLine.java +++ b/src/main/java/wprover/CLine.java @@ -9,11 +9,7 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:25:19 - * To change this template use File | Settings | File Templates. + * Represents a geometric line with various properties and methods. */ public class CLine extends CClass { final public static int LLine = 0; @@ -45,6 +41,12 @@ public class CLine extends CClass { final static int Height = 2000; // should be modified here. +/** + * Draws the line on the given graphics context. + * + * @param g2 the graphics context + * @param selected whether the line is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -84,17 +86,30 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Draws the line on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Returns the type of the line as a string. + * + * @return the type of the line + */ public String TypeString() { if (m_name == null) return GExpert.getLanguage("Line"); - // String st = Language.getLs(40, "line"); - // if (m_name == null) return st; return GExpert.getTranslationViaGettext("Line {0}", m_name); } + /** + * Returns the simple name of the line. + * + * @return the simple name of the line + */ public String getSimpleName() { CPoint pl[] = this.getTowSideOfLine(); @@ -112,22 +127,40 @@ public String getSimpleName() { return s; } + /** + * Returns the description of the line. + * + * @return the description of the line + */ public String getDescription() { String s = this.getSimpleName(); - // String st = Language.getLs(40, "line "); return GExpert.getTranslationViaGettext("Line {0}", s); - // return st + s; } + /** + * Sets the extent of the line. + * + * @param n the extent to set + */ public void setExtent(int n) { extent = n; } + /** + * Returns the extent of the line. + * + * @return the extent of the line + */ public int getExtent() { return extent; } - /////////////////////////////////////////////////////////////////////////////// + /** + * Draws an ALine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawALine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -138,6 +171,12 @@ public static void drawALine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws an ABLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawABLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -148,6 +187,12 @@ public static void drawABLine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws a TCLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawTCLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -158,6 +203,12 @@ public static void drawTCLine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws a BLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawBLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -173,6 +224,12 @@ public static void drawBLine(CLine line, Graphics2D g2) { drawXLine(x, y, k, g2); } + /** + * Draws a CCLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawCCLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -217,6 +274,12 @@ public static void drawCCLine(CLine line, Graphics2D g2) { g2.drawLine((int) xa, (int) ya, (int) xb, (int) yb); } + /** + * Draws an SLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawSLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -233,6 +296,14 @@ public static void drawSLine(CLine line, Graphics2D g2) { } + /** + * Draws a line given a point and a slope. + * + * @param x0 the x-coordinate of the point + * @param y0 the y-coordinate of the point + * @param k the slope of the line + * @param g2 the graphics context + */ public static void drawXLine(double x0, double y0, double k, Graphics2D g2) { if (Math.abs(1 / k) < CMisc.ZERO) { double x = x0; @@ -250,6 +321,12 @@ public static void drawXLine(double x0, double y0, double k, Graphics2D g2) { } } + /** + * Draws a TLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawTLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -263,6 +340,12 @@ public static void drawTLine(CLine line, Graphics2D g2) { drawXLine(p.getx(), p.gety(), -1 / k, g2); } + /** + * Draws a PLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawPLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -278,6 +361,12 @@ public static void drawPLine(CLine line, Graphics2D g2) { drawXLine(p.getx(), p.gety(), l.getK(), g2); } + /** + * Draws an LLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawLLine(CLine line, Graphics2D g2) { CPoint[] pl = line.getMaxMinPoint(); @@ -305,8 +394,13 @@ public static void drawLLine(CLine line, Graphics2D g2) { } } - /// ///////////////////////////////////// - + /** + * Draws a parallel line to the given line through the specified point. + * + * @param line the line to which the parallel line is drawn + * @param pt the point through which the parallel line passes + * @param g2 the graphics context + */ public static void drawPParaLine(CLine line, CPoint pt, Graphics2D g2) { if (line.isVertical()) { double x = pt.getx(); @@ -324,6 +418,13 @@ public static void drawPParaLine(CLine line, CPoint pt, Graphics2D g2) { } } + /** + * Draws a perpendicular line to the given line through the specified point. + * + * @param line the line to which the perpendicular line is drawn + * @param pt the point through which the perpendicular line passes + * @param g2 the graphics context + */ public static void drawTPerpLine(CLine line, CPoint pt, Graphics2D g2) { if (line.isHorizonal()) { double x = pt.getx(); @@ -344,6 +445,11 @@ public static void drawTPerpLine(CLine line, CPoint pt, Graphics2D g2) { } ///////////////////////////////////////////// + /** + * Returns the names of all points on the line. + * + * @return a string containing the names of all points on the line + */ public String getAllPointName() { String s = new String(); for (int i = 0; i < points.size(); i++) { @@ -356,6 +462,12 @@ public String getAllPointName() { return s; } + /** + * Returns the second point on the line that is not the given point. + * + * @param t the point to exclude + * @return the second point on the line, or null if there is no such point + */ public CPoint getSecondPoint(CPoint t) { CPoint p = null; @@ -369,6 +481,11 @@ else if (p != null && p.x1.xindex > pt.x1.xindex && pt != t) return p; } + /** + * Returns the first point on the line. + * + * @return the first point on the line, or null if there is no such point + */ public CPoint getfirstPoint() { CPoint p = null; @@ -383,6 +500,12 @@ else if (p.x1.xindex > pt.x1.xindex) } + /** + * Returns a point on the line that is not the given point. + * + * @param t the point to exclude + * @return a point on the line that is not the given point, or null if there is no such point + */ public CPoint getAPointBut(CPoint t) { for (int i = 0; i < points.size(); i++) { CPoint pt = (CPoint) points.get(i); @@ -391,6 +514,11 @@ public CPoint getAPointBut(CPoint t) { return null; } + /** + * Returns the point on the line with the maximum x-coordinate. + * + * @return the point on the line with the maximum x-coordinate, or null if there is no such point + */ public CPoint getMaxXPoint() { CPoint p = null; @@ -404,6 +532,11 @@ else if (p.getx() < pt.getx()) return p; } + /** + * Checks if the line has two free points at its ends. + * + * @return true if the line has two free points at its ends, false otherwise + */ public boolean isTwoEndFreePoints() { CPoint p1, p2; p1 = p2 = null; @@ -423,48 +556,12 @@ else if (p.x1.xindex < p1.x1.xindex) { return p1.isAFreePoint() && p2.isAFreePoint(); } - public boolean isParallel(CLine line) { - if (type != PLine) - return false; - for (int i = 0; i < cons.size(); i++) { - Constraint cs = (Constraint) cons.get(i); - if (cs.GetConstraintType() != Constraint.PARALLEL) - continue; - CLine line1 = (CLine) cs.getelement(0); - CLine line2 = (CLine) cs.getelement(1); - if (line2 == this) { - CLine l = line1; - line1 = line2; - line2 = l; - } - if (line2 == line) - return true; - if (line2.type == CLine.PLine) - return line2.isParallel(line); - } - return false; - } - - public boolean isVertical(CLine line) { - for (int i = 0; i < cons.size(); i++) { - Constraint cs = (Constraint) cons.get(i); - if (cs.GetConstraintType() != Constraint.PERPENDICULAR) - continue; - CLine line1 = (CLine) cs.getelement(0); - CLine line2 = (CLine) cs.getelement(1); - if (line2 == this) { - CLine l = line1; - line1 = line2; - line2 = l; - } - if (line2 == line && line1 == this) - return true; - return false; - } - - return false; - } - + /** + * Returns the point on the line with the smallest x-index that is not the given point. + * + * @param px the point to exclude + * @return the point on the line with the smallest x-index that is not the given point, or null if there is no such point + */ public CPoint get_Lpt1(CPoint px) { if (px == null) return null; CPoint p1 = null; @@ -478,6 +575,14 @@ else if (p != px && p.x1.xindex < p1.x1.xindex) return p1; } + /** + * Returns the point on the line that forms a vector with the given point and coordinates. + * + * @param px the point to exclude + * @param x the x-coordinate of the vector + * @param y the y-coordinate of the vector + * @return the point on the line that forms a vector with the given point and coordinates, or null if there is no such point + */ public CPoint get_Lptv(CPoint px, double x, double y) { // Vector (x,y),px == (x,y),p if (px == null) return null; CPoint p1 = null; @@ -494,6 +599,11 @@ else if (p != px && p.x1.xindex < p1.x1.xindex) return p1; } + /** + * Returns the two points on the line with the smallest and largest x-index. + * + * @return an array containing the two points on the line with the smallest and largest x-index, or null if there are not enough points + */ public CPoint[] getTowSideOfLine() { CPoint p1, p2; p1 = p2 = null; @@ -516,17 +626,32 @@ else if (p.x1.xindex < p1.x1.xindex) { return pl; } + /** + * Returns the description of the line. + * + * @return the description of the line + */ public String getDiscription() { CPoint[] s = this.getTowSideOfLine(); if (s == null) return m_name; return s[0].m_name + s[1].m_name; } - + /** + * Returns the maximum and minimum points of the line. + * + * @return an array containing the maximum and minimum points, or null if there are less than 2 points + */ public CPoint[] getMaxMinPoint() { return getMaxMinPoint(true); } + /** + * Returns the maximum and minimum points of the line, optionally considering visibility. + * + * @param ckv whether to consider visibility of points + * @return an array containing the maximum and minimum points, or null if there are less than 2 points + */ public CPoint[] getMaxMinPoint(boolean ckv) { if (points.size() < 2) return null; @@ -576,12 +701,24 @@ public CPoint[] getMaxMinPoint(boolean ckv) { return pl; } + /** + * Returns the constraint at the specified index. + * + * @param i the index of the constraint + * @return the constraint at the specified index, or null if the index is out of bounds + */ public Constraint getcons(int i) { if (i >= 0 && i < cons.size()) return (Constraint) cons.get(i); return null; } + /** + * Returns the first constraint of the specified type. + * + * @param t the type of the constraint + * @return the first constraint of the specified type, or null if no such constraint exists + */ public Constraint getconsByType(int t) { for (int i = 0; i < cons.size(); i++) { Constraint c = (Constraint) cons.get(i); @@ -590,28 +727,52 @@ public Constraint getconsByType(int t) { return null; } + /** + * Checks if the line contains the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line contains both points, false otherwise + */ public boolean containPTs(CPoint p1, CPoint p2) { return points.contains(p1) && points.contains(p2); } + /** + * Checks if the line contains the specified point. + * + * @param p the point + * @return true if the line contains the point, false otherwise + */ public boolean containPT(CPoint p) { return points.contains(p); } - public int getconsSize() { - return cons.size(); - } - + /** + * Returns the number of points in the line. + * + * @return the number of points in the line + */ public int getPtsSize() { return points.size(); } + /** + * Returns the point at the specified index. + * + * @param n the index of the point + * @return the point at the specified index, or null if the index is out of bounds + */ public CPoint getPoint(int n) { if (n < 0 || n >= points.size()) return null; return (CPoint) points.get(n); } - + /** + * Checks if the line is vertical. + * + * @return true if the line is vertical, false otherwise + */ public boolean isVertical() { if (points.size() >= 2) { CPoint p1 = (CPoint) points.get(0); @@ -651,6 +812,11 @@ public boolean isVertical() { } + /** + * Checks if the line is horizontal. + * + * @return true if the line is horizontal, false otherwise + */ public boolean isHorizonal() { if (this.type == CLine.LLine) { CPoint p1 = (CPoint) points.get(0); @@ -682,6 +848,11 @@ public boolean isHorizonal() { return false; } + /** + * Calculates the slope (k) of the line. + * + * @return the slope of the line + */ public double getK() { if (points.size() >= 2) { CPoint p1 = (CPoint) points.get(0); @@ -800,6 +971,14 @@ else if (k2 < -CMisc.MAX_SLOPE) return 0.0; } + /** + * Calculates the slope (k) for a line defined by three other lines. + * + * @param ln1 the first line + * @param ln2 the second line + * @param ln3 the third line + * @return the calculated slope + */ public static double getALineK(CLine ln1, CLine ln2, CLine ln3) { CPoint lp1[] = ln1.getTowSideOfLine(); CPoint lp2[] = ln2.getTowSideOfLine(); @@ -807,6 +986,17 @@ public static double getALineK(CLine ln1, CLine ln2, CLine ln3) { return getALineK(lp1[0], lp1[1], lp2[0], lp2[1], lp3[0], lp3[1]); } + /** + * Calculates the slope (k) for a line defined by six points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + * @return the calculated slope + */ public static double getALineK(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { double x1 = p1.getx(); double y1 = p1.gety(); @@ -825,6 +1015,11 @@ public static double getALineK(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoin return t1 / t2; } + /** + * Adds a point to the line. + * + * @param a the point to add + */ public void addApoint(CPoint a) { if (a == null) return; for (int i = 0; i < points.size(); i++) @@ -833,25 +1028,33 @@ public void addApoint(CPoint a) { points.add(a); } + /** + * Adds a constraint to the line. + * + * @param cs the constraint to add + */ public void addconstraint(Constraint cs) { if (cs == null) return; if (!cons.contains(cs)) cons.add(cs); } - public void clearpoints() { - points.clear(); - } - - public void setColorType(String c) { - String str = new String(c); - } - + /** + * Constructs a CLine with a specified type. + * + * @param type the type of the line + */ public CLine(int type) { super(CClass.LINE); this.type = type; } + /** + * Constructs a CLine with a specified point and type. + * + * @param A the point + * @param type the type of the line + */ public CLine(CPoint A, int type) { super(CClass.LINE); @@ -859,6 +1062,13 @@ public CLine(CPoint A, int type) { this.type = type; } + /** + * Constructs a CLine with two points and a specified type. + * + * @param A the first point + * @param B the second point + * @param Type the type of the line + */ public CLine(CPoint A, CPoint B, int Type) { super(CClass.LINE); this.addApoint(A); @@ -866,12 +1076,25 @@ public CLine(CPoint A, CPoint B, int Type) { type = Type; } + /** + * Constructs a CLine with two points. + * + * @param A the first point + * @param B the second point + */ public CLine(CPoint A, CPoint B) { super(CClass.LINE); this.addApoint(A); this.addApoint(B); } + /** + * Constructs a CLine with two points and a specified color. + * + * @param A the first point + * @param B the second point + * @param color the color of the line + */ public CLine(CPoint A, CPoint B, String color) { super(CClass.LINE); // this.color = color; @@ -879,6 +1102,13 @@ public CLine(CPoint A, CPoint B, String color) { this.addApoint(B); } + /** + * Constructs a CLine with a name and two points. + * + * @param name the name of the line + * @param A the first point + * @param B the second point + */ public CLine(String name, CPoint A, CPoint B) { super(CClass.LINE); this.m_name=name; @@ -886,7 +1116,13 @@ public CLine(String name, CPoint A, CPoint B) { this.addApoint(B); } - + /** + * Checks if two points are on the same line. + * + * @param A the first point + * @param B the second point + * @return true if both points are on the same line, false otherwise + */ public boolean sameLine(CPoint A, CPoint B) { CPoint p = new CPoint(); int counter = 0; @@ -903,18 +1139,23 @@ public boolean sameLine(CPoint A, CPoint B) { } } + /** + * Checks if a point is on the line. + * + * @param p the point to check + * @return true if the point is on the line, false otherwise + */ public boolean pointOnLine(CPoint p) { return points.contains(p); } - public boolean pointOnLineN(CPoint p) { - return this.distance(p.getx(), p.gety()) < CMisc.ZERO; - } - - public boolean pointOnLine(double x, double y) { - return this.distance(x, y) < CMisc.ZERO; - } - + /** + * Checks if two points are equal. + * + * @param A the first point + * @param B the second point + * @return true if both points are equal, false otherwise + */ public boolean isEqual(CPoint A, CPoint B) { if (A.x1.xindex == B.x1.xindex && A.y1.xindex == B.y1.xindex) return true; @@ -922,17 +1163,17 @@ public boolean isEqual(CPoint A, CPoint B) { return false; } - public CPoint getSideMostPoint(CPoint p, int x, int y) { - CPoint pp = null; - for (int i = 0; i < points.size(); i++) { - CPoint tp = (CPoint) points.get(i); - if ((x - tp.getx()) * (p.getx() - tp.getx()) > 0 || (y - tp.gety()) * (p.gety() - tp.gety()) > 0 - && (pp == null || pp.x1.xindex > tp.x1.xindex)) - pp = tp; - } - return pp; - } - + /** + * Checks if the mouse is on the line. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @param x1 the x-coordinate of the first point of the line + * @param y1 the y-coordinate of the first point of the line + * @param x2 the x-coordinate of the second point of the line + * @param y2 the y-coordinate of the second point of the line + * @return true if the mouse is on the line, false otherwise + */ public static boolean mouse_on_line(double x, double y, double x1, double y1, double x2, double y2) { double k = -(y2 - y1) / (x2 - x1); @@ -943,6 +1184,14 @@ public static boolean mouse_on_line(double x, double y, double x1, double y1, do return len < CMisc.PIXEPS; } + /** + * Calculates the distance from a point to a line. + * + * @param ln the line + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to the line + */ public static double distanceToPoint(CLine ln, double x, double y) { int n = ln.getPtsSize(); @@ -999,12 +1248,16 @@ public static double distanceToPoint(CLine ln, double x, double y) { } - - public static double distanceToPoint(CPoint p, CPoint p1, CPoint p2) { - return distanceToPoint(p.getx(), p.gety(), (p1.getx() - p2.getx()) / (p1.gety() - p2.gety()), p1.getx(), p1.gety()); - - } - + /** + * Calculates the distance from a point to a line given the slope. + * + * @param x1 the x-coordinate of the first point of the line + * @param y1 the y-coordinate of the first point of the line + * @param k the slope of the line + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to the line + */ public static double distanceToPoint(double x1, double y1, double k, double x, double y) { k = -k; @@ -1016,6 +1269,13 @@ public static double distanceToPoint(double x1, double y1, double k, double x, d } + /** + * Checks if a point is inside the line segment. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the point is inside the line segment, false otherwise + */ public boolean inside(double x, double y) { if (this.ext_type == ET_ENDLESS) return true; @@ -1060,6 +1320,14 @@ public boolean inside(double x, double y) { return (e1 <= 0 && e2 <= 0); } + /** + * Checks if a point is inside the line segment within a given tolerance. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param eps the tolerance + * @return true if the point is inside the line segment within the tolerance, false otherwise + */ public boolean inside(double x, double y, double eps) { if (this.ext_type == ET_ENDLESS) return true; @@ -1105,10 +1373,24 @@ public boolean inside(double x, double y, double eps) { return (e1 <= 0 && e2 <= 0); } + /** + * Checks if a point is near the line. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the point is near the line, false otherwise + */ public boolean nearline(double x, double y) { // is the point near the line return distanceToPoint(this, x, y) < CMisc.PIXEPS; } + /** + * Selects the line if a point is near it. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the line is selected, false otherwise + */ public boolean select(double x, double y) { if (!visible) return false; @@ -1120,25 +1402,23 @@ public boolean select(double x, double y) { return false; } + /** + * Calculates the distance from a point to this line. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to this line + */ public double distance(double x, double y) { return distanceToPoint(this, x, y); } - public boolean isOnMiddle(double x, double y) { - if (points.size() != 2) - return false; - CPoint p1 = (CPoint) points.get(0); - CPoint p2 = (CPoint) points.get(1); - - double dx = (p1.getx() + p2.getx()) / 2; - double dy = (p1.gety() + p2.gety()) / 2; - if (Math.abs(p1.getx() - p2.getx()) < CMisc.PIXEPS && - Math.abs(p1.gety() - p2.gety()) < CMisc.PIXEPS) - return false; - - return Math.abs(x - dx) < CMisc.PIXEPS && Math.abs(y - dy) < CMisc.PIXEPS; - } - + /** + * Checks if the given point is on the middle of the line. + * + * @param pt the point to check + * @return true if the point is on the middle of the line, false otherwise + */ public boolean pointonMiddle(CPoint pt) { if (points.size() != 2) return false; @@ -1157,6 +1437,11 @@ public boolean pointonMiddle(CPoint pt) { return true; } + /** + * Sets the location of the given point to be on this line. + * + * @param pt the point to set on the line + */ public void pointonline(CPoint pt) { //set the location of the point to line if (this.type == CCLine) return; @@ -1212,6 +1497,13 @@ public void pointonline(CPoint pt) { //set the location of the point to lin } + /** + * Finds the common points between a line and a circle. + * + * @param ln the line + * @param c the circle + * @return an array of common points between the line and the circle + */ public static CPoint[] commonPoint(CLine ln, Circle c) { CPoint t1, t2; t1 = t2 = null; @@ -1243,6 +1535,13 @@ else if (t2 == null) { } } + /** + * Finds the common point between two lines. + * + * @param line0 the first line + * @param line1 the second line + * @return the common point between the two lines, or null if there is no common point + */ public static CPoint commonPoint(CLine line0, CLine line1) { for (int i = 0; i < line0.points.size(); i++) { CPoint p1 = (CPoint) line0.points.get(i); @@ -1256,6 +1555,12 @@ public static CPoint commonPoint(CLine line0, CLine line1) { return null; } + /** + * Checks if this line is the same as another line. + * + * @param line2 the other line to compare + * @return true if the lines are the same, false otherwise + */ public boolean sameLine(CLine line2) { if (line2 == null) return false; if (this.points.size() != line2.points.size()) return false; @@ -1263,6 +1568,15 @@ public boolean sameLine(CLine line2) { return this.points.containsAll(line2.points); } + /** + * Calculates the intersection point of two line segments. + * + * @param p1 the first point of the first line segment + * @param p2 the second point of the first line segment + * @param p3 the first point of the second line segment + * @param p4 the second point of the second line segment + * @return an array containing the x and y coordinates of the intersection point, or null if there is no intersection + */ public static double[] Intersect(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { double result[] = new double[2]; if (Math.abs(p1.getx() - p2.getx()) < CMisc.ZERO) { @@ -1289,10 +1603,23 @@ public static double[] Intersect(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return result; } + /** + * Checks if a slope is considered vertical. + * + * @param r the slope to check + * @return true if the slope is vertical, false otherwise + */ public static boolean isVerticalSlop(double r) { return Math.abs(r) > CMisc.MAX_SLOPE; } + /** + * Checks if two lines are perpendicular. + * + * @param line0 the first line + * @param line1 the second line + * @return true if the lines are perpendicular, false otherwise + */ public static boolean isPerp(CLine line0, CLine line1) { if (line0 == null || line1 == null) return false; @@ -1306,6 +1633,13 @@ public static boolean isPerp(CLine line0, CLine line1) { return Math.abs(k0 * k1 + 1) < CMisc.ZERO; } + /** + * Calculates the intersection point of two lines. + * + * @param line0 the first line + * @param line1 the second line + * @return an array containing the x and y coordinates of the intersection point, or null if there is no intersection + */ public static double[] Intersect(CLine line0, CLine line1) { if (line0 == null || line1 == null) return null; @@ -1350,6 +1684,13 @@ public static double[] Intersect(CLine line0, CLine line1) { return result; } + /** + * Saves the line to a PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -1362,7 +1703,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } - + /** + * Saves the line to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); @@ -1384,6 +1730,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(extent); } + /** + * Loads the line from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { m_id = in.readInt(); diff --git a/src/main/java/wprover/CMisc.java b/src/main/java/wprover/CMisc.java index fa166bf4..41639363 100644 --- a/src/main/java/wprover/CMisc.java +++ b/src/main/java/wprover/CMisc.java @@ -9,11 +9,9 @@ import java.net.URL; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-8 - * Time: 18:57:22 - * To change this template use File | Settings | File Templates. + * This class contains configuration and utility methods for the application. + * It manages properties such as screen size, background color, font settings, + * and other application-specific settings. */ public class CMisc { final public static double version = 0.053; diff --git a/src/main/java/wprover/CPoint.java b/src/main/java/wprover/CPoint.java index 41f2ae82..37b805f6 100644 --- a/src/main/java/wprover/CPoint.java +++ b/src/main/java/wprover/CPoint.java @@ -10,11 +10,9 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:22:43 - * To change this template use File | Settings | File Templates. + * CPoint class represents a point in a 2D space with x and y coordinates. + * It extends the CClass class and implements various methods for drawing, + * saving, and loading the point's properties. */ public class CPoint extends CClass { private int type = 0; @@ -26,22 +24,45 @@ public class CPoint extends CClass { CText ptext; + /** + * Default constructor for the CPoint class. + * Initializes the point with default values and sets the text position. + */ public CPoint() { super(CClass.POINT); ptext = new CText(this, 5, -20, CText.NAME_TEXT); } + /** + * Retrieves the first constraint associated with this point. + * + * @return the first Constraint object, or null if no constraints are present + */ public Constraint getConstraint() { if (cons.size() == 0) return null; return (Constraint) cons.get(0); } + /** + * Constructor for the CPoint class with specified type and coordinates. + * + * @param type the type of the point + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(int type, Param X, Param Y) { super(type); x1 = X; y1 = Y; } + /** + * Constructor for the CPoint class with specified name and coordinates. + * + * @param Name the name of the point + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(String Name, Param X, Param Y) { super(CClass.POINT); m_name = Name; @@ -50,7 +71,12 @@ public CPoint(String Name, Param X, Param Y) { ptext = new CText(this, 7, -24, CText.NAME_TEXT); } - + /** + * Constructor for the CPoint class with specified coordinates. + * + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(Param X, Param Y) { super(CClass.POINT); x1 = X; @@ -58,6 +84,11 @@ public CPoint(Param X, Param Y) { ptext = new CText(this, 7, -24, CText.NAME_TEXT); } + /** + * Retrieves the text associated with this point. + * + * @return the CText object associated with this point + */ public CText getPText() { if (ptext == null) { return new CText(this, 7, -24, CText.NAME_TEXT); @@ -66,9 +97,14 @@ public CText getPText() { } } + /** + * Checks if this point is equal to another object based on the name. + * + * @param obj the object to compare with + * @return true if the names are equal, false otherwise + */ public boolean equals(Object obj) { if (obj == null) { - // CMisc.print("A point without name"); return false; } if (m_name == null || m_name.length() == 0) { @@ -77,13 +113,20 @@ public boolean equals(Object obj) { return m_name.equals(obj.toString()); } + /** + * Stops the flashing effect for this point and its associated text. + */ public void stopFlash() { super.stopFlash(); if (ptext != null) ptext.stopFlash(); - //mode = 0; } + /** + * Sets the flashing state for this point and its associated text. + * + * @param flash true to enable flashing, false to disable + */ public void setInFlashing(boolean flash) { super.setInFlashing(flash); if (ptext != null) { @@ -95,19 +138,41 @@ public void setInFlashing(boolean flash) { } } +/** + * Checks if this point is a fixed point. + * + * @return true if both x and y coordinates are solved, false otherwise + */ public boolean isAFixedPoint() { return x1.Solved && y1.Solved; } + /** + * Checks if this point is a free point. + * + * @return true if both x and y coordinates are not solved, false otherwise + */ public boolean isAFreePoint() { return !x1.Solved && !y1.Solved; } + /** + * Sets the color of this point. + * + * @param c the color to set + */ public void setColor(int c) { super.setColor(c); this.hasSetColor = true; } + /** + * Selects this point if the given coordinates are within a certain distance. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the point is selected, false otherwise + */ public boolean select(double x, double y) { if (visible == false) { return false; @@ -120,13 +185,13 @@ public boolean select(double x, double y) { return false; } - public boolean selectText(int x, int y) { - return false; - - } - + /** + * Draws this point on the given graphics context. + * + * @param g2 the graphics context + * @param selected true if the point is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { - int radius = getRadius(); setDrawSelect(g2); int x = (int) getx(); @@ -134,32 +199,56 @@ public void draw(Graphics2D g2, boolean selected) { g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); } - + /** + * Gets the default radius of the point. + * + * @return the default radius of the point + */ public int POINT_RADIUS = CMisc.getPointRadius(); + /** + * Gets the radius of the point. If the radius is not set, it returns the default radius + * based on whether the application is running as an applet or a standalone application. + * + * @return the radius of the point + */ public int getRadius() { int radius = m_radius; -// if (radius < 0) -// radius = CMisc.getPointRadius(); if (radius < 0) { if (CMisc.isApplication()) radius = CMisc.getPointRadius(); else - radius = POINT_RADIUS; //APPLET ONLY + radius = POINT_RADIUS; // APPLET ONLY } return radius; } +/** + * Gets the radius value of the point. + * + * @return the radius value of the point + */ public int getRadiusValue() { return m_radius; } + /** + * Sets the radius of the point. If the given radius is less than or equal to 0, + * it sets the radius to the default value. + * + * @param r the new radius of the point + */ public void setRadius(int r) { if (r <= 0) m_radius = -1; m_radius = r; } + /** + * Draws the point on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { if (!isdraw()) { return; @@ -179,13 +268,15 @@ public void draw(Graphics2D g2) { g2.setColor(new Color(0, 0, 0)); g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); - -// g2.setColor(g2.getBackground()); -// g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); setDraw(g2); g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); } + /** + * Draws the point with a specific style on the given graphics context. + * + * @param g2 the graphics context + */ public void drawA0(Graphics2D g2) { if (!isdraw()) { return; @@ -200,6 +291,11 @@ public void drawA0(Graphics2D g2) { g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); } +/** + * Draws the point and its text on the given graphics context. + * + * @param g2 the graphics context + */ public void draw_wt(Graphics2D g2) { this.drawA0(g2); if (ptext != null) { @@ -207,6 +303,11 @@ public void draw_wt(Graphics2D g2) { } } + /** + * Draws the point with a custom style on the given graphics context. + * + * @param g2 the graphics context + */ public void draw_ct(Graphics2D g2) { int x = (int) getx(); int y = (int) gety(); @@ -220,14 +321,13 @@ public void draw_ct(Graphics2D g2) { g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); radius -= 3; g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); - - } - - public double distanceTo(CPoint pt) - { - return Math.sqrt(Math.pow(this.getx() - pt.getx(), 2) + Math.pow(this.gety() - pt.gety(), 2)); } + /** + * Returns the type of the point as a string. + * + * @return the type of the point + */ public String TypeString() { String s1 = Language.getLs("Point"); @@ -238,6 +338,11 @@ public String TypeString() { return GExpert.getTranslationViaGettext("Point {0}", m_name); } + /** + * Returns a description of the point. + * + * @return the description of the point + */ public String getDescription() { if (this.isAFreePoint()) { String s1 = Language.getLs("Free Point"); @@ -250,6 +355,9 @@ public String getDescription() { ////////////////////////////////////////////////////// + /** + * Sets the default color of the point based on its solved state. + */ public void setColorDefault() { if (this.hasSetColor) { return; @@ -263,12 +371,24 @@ public void setColorDefault() { } } +/** + * Adds a constraint to the point if it is not already present. + * + * @param cs the constraint to add + */ public void addcstoPoint(Constraint cs) { if (cs != null && !cons.contains(cs)) { cons.add(cs); } } + /** + * Checks if the given x and y coordinates are valid based on the constraints. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the coordinates are valid, false otherwise + */ public boolean check_xy_valid(double x, double y) { for (int i = 0; i < cons.size(); i++) { Constraint cs = (Constraint) cons.get(i); @@ -278,8 +398,13 @@ public boolean check_xy_valid(double x, double y) { return true; } + /** + * Checks if this point is equal to another point based on their coordinates. + * + * @param p the point to compare with + * @return true if the points have the same coordinates, false otherwise + */ public boolean isEqual(CPoint p) { - if ((p.x1 == this.x1) && (p.y1 == this.y1)) { return true; } else { @@ -287,6 +412,13 @@ public boolean isEqual(CPoint p) { } } + /** + * Checks if this point is equal to given coordinates based on their indices. + * + * @param x the x-coordinate index to compare + * @param y the y-coordinate index to compare + * @return true if the indices match this point's indices, false otherwise + */ public boolean isEqual(int x, int y) { if ((x == this.x1.xindex) && (y == this.y1.xindex)) { return true; @@ -295,6 +427,13 @@ public boolean isEqual(int x, int y) { } } + /** + * Checks if the given location is the same as this point's location. + * + * @param x the x-coordinate to compare + * @param y the y-coordinate to compare + * @return true if the location matches this point's location, false otherwise + */ public boolean isSame_Location(double x, double y) { if (Math.abs(x - this.getx()) < CMisc.ZERO && Math.abs(y - this.gety()) < CMisc.ZERO) { @@ -303,6 +442,11 @@ public boolean isSame_Location(double x, double y) { return false; } + /** + * Gets the x-coordinate of this point. + * + * @return the x-coordinate of this point + */ public double getx() { if (x1 == null) { CMisc.print("CPoint error,x1 undefined"); @@ -311,14 +455,29 @@ public double getx() { return x1.value; } + /** + * Gets the x-coordinate of the point's text. + * + * @return the x-coordinate of the point's text + */ public int getTx() { return ptext.getX(); } + /** + * Gets the y-coordinate of the point's text. + * + * @return the y-coordinate of the point's text + */ public int getTy() { return ptext.getY(); } + /** + * Gets the y-coordinate of this point. + * + * @return the y-coordinate of this point + */ public double gety() { if (y1 == null) { CMisc.print("CPoint error,y1 undefined"); @@ -327,14 +486,30 @@ public double gety() { return y1.value; } + /** + * Checks if this point is frozen. + * + * @return true if the point is frozen, false otherwise + */ public boolean isFreezed() { return freezed; } + /** + * Sets the frozen state of this point. + * + * @param r the new frozen state + */ public void setFreezed(boolean r) { freezed = r; } + /** + * Sets the x and y coordinates of this point. + * + * @param x the new x-coordinate + * @param y the new y-coordinate + */ public void setXY(double x, double y) { if (true) { x1.value = x; @@ -342,21 +517,36 @@ public void setXY(double x, double y) { } } + /** + * Sets the fill color of this point. + * + * @param index the color index to set + */ public void setFillColor(int index) { this.m_color = index; } + /** + * Returns the string representation of this point. + * + * @return the name of this point + */ public String toString() { return m_name; } + /** + * Saves the PostScript definition of this point to a file. + * + * @param fp the file output stream to write to + * @throws IOException if an I/O error occurs + */ public void SavePS_Define_Point(FileOutputStream fp) throws IOException { String st = m_name; if (st.length() == 0 || st.trim().length() == 0) st = "POINT" + m_id; - String s = '/' + st + " {"; fp.write(s.getBytes()); @@ -366,11 +556,16 @@ public void SavePS_Define_Point(FileOutputStream fp) throws IOException { fp.write(((x1) + " ").getBytes()); - fp.write(((-y1) + - "} def \n").getBytes()); - + fp.write(((-y1) + "} def \n").getBytes()); } + /** + * Saves the PostScript representation of this point to a file. + * + * @param fp the file output stream to write to + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (visible == false) { return; @@ -390,6 +585,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { fp.write(s.getBytes()); } + /** + * Saves the original PostScript representation of this point to a file. + * + * @param fp the file output stream to write to + * @throws IOException if an I/O error occurs + */ public void SavePsOringinal(FileOutputStream fp) throws IOException { if (visible == false) { return; @@ -410,6 +611,12 @@ public void SavePsOringinal(FileOutputStream fp) throws IOException { fp.write(s.getBytes()); } + /** + * Saves the state of this point to a data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(type); @@ -429,6 +636,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(freezed); } + /** + * Loads the state of this point from a data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process to use for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { m_id = in.readInt(); diff --git a/src/main/java/wprover/CPolygon.java b/src/main/java/wprover/CPolygon.java index be37c5d1..0eb0d4fe 100644 --- a/src/main/java/wprover/CPolygon.java +++ b/src/main/java/wprover/CPolygon.java @@ -8,11 +8,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-25 - * Time: 20:24:52 - * To change this template use File | Settings | File Templates. + * CPolygon class represents a polygon or circle shape. + * It extends the CClass class and provides methods for drawing, manipulating, and checking properties of the shape. */ public class CPolygon extends CClass { int ftype = 0; // 0: polygon, 1:circle. @@ -29,6 +26,19 @@ public class CPolygon extends CClass { private double area; +/** + * Draws the polygon on the given graphics context with various options. + * + * @param g2 the graphics context + * @param selected true if the polygon is selected, false otherwise + * @param overlap true if the polygon should be drawn with overlap, false otherwise + * @param dx the x-offset for drawing + * @param dy the y-offset for drawing + * @param rotate true if the polygon should be rotated, false otherwise + * @param x the x-coordinate for rotation + * @param y the y-coordinate for rotation + * @param ang the angle of rotation in radians + */ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, double dy, boolean rotate, double x, double y, double ang) { if (!isdraw()) return; @@ -75,7 +85,6 @@ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, do this.setDraw(g2); - Composite ac = null; if (overlap) { ac = g2.getComposite(); @@ -125,16 +134,32 @@ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, do g2.setComposite(ac); } + /** + * Retrieves the element at the specified index in the point list. + * + * @param n the index of the element + * @return the element at the specified index, or null if the index is out of bounds + */ public CClass getElement(int n) { if (n < 0 || n >= pointlist.size()) return null; return (CClass) pointlist.get(n); } + /** + * Retrieves the area of the polygon. + * + * @return the area of the polygon + */ public double getArea() { return area; } + /** + * Checks if all points in the polygon are free points. + * + * @return true if all points are free points, false otherwise + */ public boolean isAllPointsFree() { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -144,10 +169,28 @@ public boolean isAllPointsFree() { return true; } + /** + * Calculates the signed area of a triangle given its vertex coordinates. + * + * @param x1 the x-coordinate of the first vertex + * @param y1 the y-coordinate of the first vertex + * @param x2 the x-coordinate of the second vertex + * @param y2 the y-coordinate of the second vertex + * @param x3 the x-coordinate of the third vertex + * @return the signed area of the triangle + */ public static double signArea(int x1, int y1, int x2, int y2, int x3, int y3) { return ((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2)) / 2; } + /** + * Calculates the area of a polygon given its vertex coordinates. + * + * @param xPoints the x-coordinates of the vertices + * @param yPoints the y-coordinates of the vertices + * @param nPoints the number of vertices + * @return the area of the polygon + */ public static double area(int xPoints[], int yPoints[], int nPoints) { if (nPoints < 4) return 0.0; @@ -158,6 +201,12 @@ public static double area(int xPoints[], int yPoints[], int nPoints) { return r; } + /** + * Checks if this polygon is equal to the given circle. + * + * @param c the circle to compare with + * @return true if the polygon is equal to the circle, false otherwise + */ public boolean isEqual(Circle c) { if (c == null) return false; if (ftype != 1) return false; @@ -168,55 +217,62 @@ public boolean isEqual(Circle c) { return c.o == pointlist.get(0) && ((pp[0] == pointlist.get(1) && pp[1] == pointlist.get(2)) || (pp[0] == pointlist.get(2) && pp[1] == pointlist.get(1))); - - } - public void drawAreaText(Graphics2D g2, int xPoints[], int yPoints[], int nPoints) { - if (nPoints < 4) return; - double r = area(xPoints, yPoints, nPoints); - r = Math.abs(r); - - int x, y; - x = y = 0; - - for (int i = 0; i <= nPoints - 2; i++) { - x += xPoints[i]; - y += yPoints[i]; - } - x = x / (nPoints - 1); - y = y / (nPoints - 1); - g2.drawString("Area = " + r, x, y); - } - - public void setShowArea(boolean r) { - showArea = r; - } - - + /** + * Draws the polygon on the given graphics context with the selected option. + * + * @param g2 the graphics context + * @param selected true if the polygon is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { draw(g2, selected, true, 0, 0, false, 0, 0, 0); } + /** + * Draws the polygon on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { this.draw(g2, false); } + /** + * Retrieves the number of points in the polygon. + * + * @return the number of points in the polygon + */ public int getPtn() { return pointlist.size(); } + /** + * Retrieves the point at the specified index in the point list. + * + * @param n the index of the point + * @return the point at the specified index + */ public CPoint getPoint(int n) { return (CPoint) pointlist.get(n); } + /** + * Default constructor for the CPolygon class. + * Initializes the polygon with default values. + */ public CPolygon() { super(CClass.POLYGON); pt1 = pt2 = null; pdx = pdy = 0; - //m_color =drawData. } + /** + * Constructor for the CPolygon class with a specified circle. + * Initializes the polygon as a circle with the given circle's properties. + * + * @param c the circle to initialize the polygon with + */ public CPolygon(Circle c) { this(); this.ftype = 1; @@ -227,6 +283,14 @@ public CPolygon(Circle c) { pointlist.add(c.o); } +/** + * Sets the dragged points and their offsets. + * + * @param p1 the first dragged point + * @param p2 the second dragged point + * @param x the x-offset + * @param y the y-offset + */ public void setDraggedPoints(CPoint p1, CPoint p2, double x, double y) { pt1 = p1; pt2 = p2; @@ -234,6 +298,9 @@ public void setDraggedPoints(CPoint p1, CPoint p2, double x, double y) { pdy = y; } + /** + * Resets the dragged points and their offsets to null and clears the vector list. + */ public void setDraggedPointsNull() { pt1 = null; pt2 = null; @@ -242,6 +309,11 @@ public void setDraggedPointsNull() { vtrlist.clear(); } + /** + * Copies the properties of the given polygon to this polygon. + * + * @param c the polygon to copy from + */ public void copy(CPolygon c) { super.copy(c); grid = c.grid; @@ -249,19 +321,40 @@ public void copy(CPolygon c) { this.type = c.type; } + /** + * Adds a pair of dragged points to the vector list. + * + * @param p1 the first point + * @param p2 the second point + */ public void addDraggedPoints(CPoint p1, CPoint p2) { vtrlist.add(p1); vtrlist.add(p2); } + /** + * Checks if all points have been dragged. + * + * @return true if all points have been dragged, false otherwise + */ public boolean allDragged() { return vtrlist.size() == (pointlist.size() - 1) * 2; } + /** + * Retrieves the vector list of dragged points. + * + * @return the vector list of dragged points + */ public Vector getDraggedPoints() { return vtrlist; } + /** + * Retrieves the transformed points based on the dragged points. + * + * @return the vector list of transformed points + */ public Vector getTransformedPoints() { Vector vlist = new Vector(); @@ -283,6 +376,12 @@ public Vector getTransformedPoints() { return vlist; } + /** + * Retrieves the polygon type as a string. + * + * @return the polygon type string + * @deprecated Use {@link #getPolygonTypeString(String)} instead. + */ @Deprecated public String getPolygonTypeString() { String ds; @@ -303,9 +402,14 @@ else if (size == 6) } else { return Language.getLs("Circle"); } - } + /** + * Retrieves the polygon type as a string with a specified format. + * + * @param s the format string + * @return the formatted polygon type string + */ public String getPolygonTypeString(String s) { String ds; @@ -325,23 +429,36 @@ else if (size == 6) } else { return GExpert.getTranslationViaGettext("Circle {0}", s); } - } + /** + * Retrieves the polygon type as a string. + * + * @return the polygon type string + * @deprecated Use {@link #getPolygonTypeString(String)} instead. + */ @Deprecated public String TypeString() { return getPolygonTypeString(); } + /** + * Retrieves the polygon type as a string with a specified format. + * + * @param s the format string + * @return the formatted polygon type string + */ public String TypeString(String s) { return getPolygonTypeString(s); } - public boolean containPnt(CPoint p) { - return pointlist.contains(p); - } - - public boolean check_rdeq(Vector v) { // n --- n-1; + /** + * Checks if the polygon is equal to another polygon by comparing their points in a rotated manner. + * + * @param v the vector of points to compare with + * @return true if the polygons are equal, false otherwise + */ + public boolean check_rdeq(Vector v) { if (!visible) return false; int n = pointlist.size(); @@ -369,21 +486,15 @@ public boolean containPnt(CPoint p) { return false; } + /** + * Checks if the polygon is equal to another polygon by comparing their points. + * + * @param v the vector of points to compare with + * @return true if the polygons are equal, false otherwise + */ public boolean check_eq(Vector v) { int n = pointlist.size(); if (n != v.size()) return false; - /* - n--; - int i, j; - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - if (pointlist.get(i) != v.get((j + i) % n)) - break; - } - if (j == n) - return true; - } */ for (int i = 0; i < n; i++) { if (pointlist.get(i) != v.get(i)) @@ -391,174 +502,210 @@ public boolean check_eq(Vector v) { } return true; } -//////////////////////////////////////////////////////////// - void setType(int type) { - this.type = type; - } - - - int getType() { - return type; - } +/** + * Sets the type of the polygon. + * + * @param type the type of the polygon + */ +void setType(int type) { + this.type = type; +} - void setGrid(int grid) { - this.grid = grid; - } +/** + * Gets the type of the polygon. + * + * @return the type of the polygon + */ +int getType() { + return type; +} - void setSlope(int s) { - this.slope = s; - } +/** + * Sets the grid size for the polygon. + * + * @param grid the grid size + */ +void setGrid(int grid) { + this.grid = grid; +} +/** + * Sets the slope for the polygon. + * + * @param s the slope value + */ +void setSlope(int s) { + this.slope = s; +} - public void setPoints(Vector v) { - pointlist.clear(); - pointlist.addAll(v); - return; - } +/** + * Sets the points of the polygon. + * + * @param v the vector containing the points + */ +public void setPoints(Vector v) { + pointlist.clear(); + pointlist.addAll(v); + return; +} - public boolean addAPoint(CPoint p) { - if (p == null) return false; - if (pointlist.size() > 1 && p == pointlist.get(0)) { - pointlist.add(p); - return true; - } else if (pointlist.contains(p)) - return false; - else - pointlist.add(p); +/** + * Adds a point to the polygon. + * + * @param p the point to add + * @return true if the point was added, false if the point was already in the list or null + */ +public boolean addAPoint(CPoint p) { + if (p == null) return false; + if (pointlist.size() > 1 && p == pointlist.get(0)) { + pointlist.add(p); + return true; + } else if (pointlist.contains(p)) return false; - } - - - public boolean select(double x, double y) { - if (visible == false) return false; - - if (ftype == 0) { - Polygon poly = new Polygon(); + else + pointlist.add(p); + return false; +} - for (int i = 0; i < pointlist.size(); i++) { - CPoint pt = (CPoint) pointlist.get(i); - poly.addPoint((int) pt.getx(), (int) pt.gety()); - } +/** + * Selects the polygon if the given coordinates are within its bounds. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the polygon is selected, false otherwise + */ +public boolean select(double x, double y) { + if (visible == false) return false; - return poly.contains(x, y); - } else { - CPoint p1 = (CPoint) pointlist.get(0); - CPoint p2 = (CPoint) pointlist.get(1); - CPoint p3 = (CPoint) pointlist.get(2); - double r = (Math.pow(p2.getx() - p3.getx(), 2) + Math.pow(p2.gety() - p3.gety(), 2)); + if (ftype == 0) { + Polygon poly = new Polygon(); - return Math.pow(x - p1.getx(), 2) + Math.pow(y - p1.gety(), 2) < r; + for (int i = 0; i < pointlist.size(); i++) { + CPoint pt = (CPoint) pointlist.get(i); + poly.addPoint((int) pt.getx(), (int) pt.gety()); } - } + return poly.contains(x, y); + } else { + CPoint p1 = (CPoint) pointlist.get(0); + CPoint p2 = (CPoint) pointlist.get(1); + CPoint p3 = (CPoint) pointlist.get(2); + double r = (Math.pow(p2.getx() - p3.getx(), 2) + Math.pow(p2.gety() - p3.gety(), 2)); - public CPoint getPreviousePoint(CPoint p) { - for (int i = 0; i < pointlist.size() - 1; i++) { - if (p == pointlist.get(i + 1)) - return (CPoint) pointlist.get(i); - } - return null; + return Math.pow(x - p1.getx(), 2) + Math.pow(y - p1.gety(), 2) < r; } +} - public CPoint getNextPoint(CPoint p) { - for (int i = 1; i < pointlist.size(); i++) { - if (p == pointlist.get(i - 1)) - return (CPoint) pointlist.get(i); - } - return null; +/** + * Gets the previous point in the polygon. + * + * @param p the current point + * @return the previous point, or null if not found + */ +public CPoint getPreviousePoint(CPoint p) { + for (int i = 0; i < pointlist.size() - 1; i++) { + if (p == pointlist.get(i + 1)) + return (CPoint) pointlist.get(i); } + return null; +} - public void draw(Graphics2D g2, CPoint p) { - if (visible == false) return; - - if (pointlist.size() == 0) return; - - int n = pointlist.size() + 2; - int[] xpoints = new int[n]; - int[] ypoints = new int[n]; - - for (int i = 0; i < pointlist.size(); i++) { - CPoint pt = (CPoint) pointlist.get(i); - xpoints[i] = (int) pt.getx(); - ypoints[i] = (int) pt.gety(); - } - xpoints[n - 2] = (int) p.getx(); - ypoints[n - 2] = (int) p.gety(); - - CPoint pt = (CPoint) pointlist.get(0); - xpoints[n - 1] = (int) pt.getx(); - ypoints[n - 1] = (int) pt.gety(); - - this.setDraw(g2); - +/** + * Gets the next point in the polygon. + * + * @param p the current point + * @return the next point, or null if not found + */ +public CPoint getNextPoint(CPoint p) { + for (int i = 1; i < pointlist.size(); i++) { + if (p == pointlist.get(i - 1)) + return (CPoint) pointlist.get(i); + } + return null; +} - if (type == 0) - g2.fillPolygon(xpoints, ypoints, n); - else - drawGrid(g2, xpoints, ypoints, n, 0, type); +/** + * Draws the polygon with an additional point on the given graphics context. + * + * @param g2 the graphics context + * @param p the additional point to draw + */ +public void draw(Graphics2D g2, CPoint p) { + if (visible == false) return; - g2.setColor(super.getColor().darker().darker()); + if (pointlist.size() == 0) return; + int n = pointlist.size() + 2; + int[] xpoints = new int[n]; + int[] ypoints = new int[n]; - g2.drawPolygon(xpoints, ypoints, n); + for (int i = 0; i < pointlist.size(); i++) { + CPoint pt = (CPoint) pointlist.get(i); + xpoints[i] = (int) pt.getx(); + ypoints[i] = (int) pt.gety(); + } + xpoints[n - 2] = (int) p.getx(); + ypoints[n - 2] = (int) p.gety(); - g2.drawLine(xpoints[0], ypoints[0], (int) p.getx(), (int) p.gety()); - g2.drawLine(xpoints[n - 1], ypoints[n - 1], (int) p.getx(), (int) p.gety()); + CPoint pt = (CPoint) pointlist.get(0); + xpoints[n - 1] = (int) pt.getx(); + ypoints[n - 1] = (int) pt.gety(); + this.setDraw(g2); - } + if (type == 0) + g2.fillPolygon(xpoints, ypoints, n); + else + drawGrid(g2, xpoints, ypoints, n, 0, type); - public double getCentroidX() { - Vector v = pointlist; + g2.setColor(super.getColor().darker().darker()); - double dx1 = 0; - int n = v.size(); - for (int i = 0; i < n; i++) { - CPoint pt = (CPoint) v.get(i); - dx1 += pt.getx(); - } - dx1 /= n; - return dx1; - } + g2.drawPolygon(xpoints, ypoints, n); - public double getCentroidY() { - Vector v = pointlist; - double dy1 = 0; - int n = v.size(); - for (int i = 0; i < n; i++) { - CPoint pt = (CPoint) v.get(i); - dy1 += pt.gety(); - } - dy1 /= n; - return dy1; - } + g2.drawLine(xpoints[0], ypoints[0], (int) p.getx(), (int) p.gety()); + g2.drawLine(xpoints[n - 1], ypoints[n - 1], (int) p.getx(), (int) p.gety()); +} - public String getDescription() { - String s = new String(); - if (pointlist.size() < 4) return ""; +/** + * Gets the description of the polygon. + * + * @return the description of the polygon + */ +public String getDescription() { + String s = new String(); + if (pointlist.size() < 4) return ""; - int size = pointlist.size() - 1; + int size = pointlist.size() - 1; - for (int i = 0; i < size; i++) { - CClass cc = (CClass) pointlist.get(i); - s += cc.m_name; - } - if (ftype == 0) - return TypeString(s); - else return TypeString("(" + s + ")"); + for (int i = 0; i < size; i++) { + CClass cc = (CClass) pointlist.get(i); + s += cc.m_name; } + if (ftype == 0) + return TypeString(s); + else return TypeString("(" + s + ")"); +} - public Vector drawGrid(Graphics2D g2, int[] xpoints, int[] ypoints, int n, int dtype, int gtype) // type 0: draw ; 1: print ps - { +/** + * Draws a grid pattern on the given graphics context based on the specified points and grid type. + * + * @param g2 the graphics context + * @param xpoints the x-coordinates of the points + * @param ypoints the y-coordinates of the points + * @param n the number of points + * @param dtype the draw type (0: draw, 1: print ps) + * @param gtype the grid type (1: vertical, 2: horizontal, 3: both) + * @return a vector of points if dtype is 1, otherwise null + */ + public Vector drawGrid(Graphics2D g2, int[] xpoints, int[] ypoints, int n, int dtype, int gtype) { Vector vpl = null; if (dtype == 1) vpl = new Vector(); if (n <= 3) return vpl; - double k = Math.tan(slope * Math.PI / 180); int step = this.grid; @@ -707,6 +854,14 @@ else if (dtype == 1) { return vpl; } + /** + * Adds a value to a sorted array and returns the new size of the array. + * + * @param a the value to add + * @param b the array to add the value to + * @param n the current size of the array + * @return the new size of the array + */ private int add_sort(double a, double[] b, int n) { for (int i = 0; i < n; i++) { if (a < b[i]) { @@ -718,9 +873,15 @@ private int add_sort(double a, double[] b, int n) { } b[n] = a; return n + 1; - } + /** + * Saves the polygon as a PostScript file. + * + * @param fp the file output stream + * @param stype the save type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (visible == false) return; @@ -739,10 +900,8 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { ypoints[i] = (int) pt.gety(); } - String s = ""; - if (type == 0) { for (int i = 0; i < pointlist.size() - 1; i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -782,10 +941,14 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { fp.write(st.getBytes()); this.saveSuper(fp); } - } - + /** + * Saves the polygon data to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeBoolean(showArea); @@ -801,6 +964,13 @@ public void Save(DataOutputStream out) throws IOException { } } + /** + * Loads the polygon data from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); @@ -838,9 +1008,6 @@ else if (m_color == 7) int d = in.readInt(); pointlist.add(dp.getPointById(d)); } - - } } - } diff --git a/src/main/java/wprover/CProperty.java b/src/main/java/wprover/CProperty.java index 052b0bf6..ce2fe514 100644 --- a/src/main/java/wprover/CProperty.java +++ b/src/main/java/wprover/CProperty.java @@ -12,11 +12,8 @@ import java.util.EventObject; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-2-10 - * Time: 19:38:34 - * To change this template use File | Settings | File Templates. + * CProperty is a JPanel that displays property panels for different geometric objects. + * It allows users to modify properties such as color, line type, and line width. */ public class CProperty extends JPanel implements ActionListener { @@ -36,6 +33,13 @@ public class CProperty extends JPanel implements ActionListener { private Panel_arrow parrow; + /** + * Constructor for the CProperty class. + * Initializes the property panels and sets up the layout. + * + * @param dd the DPanel instance + * @param lan the Language instance + */ public CProperty(DPanel dd, Language lan) { d = dd; this.lan = lan; @@ -58,12 +62,24 @@ public CProperty(DPanel dd, Language lan) { this.add(label); } + /** + * Retrieves the language string for the given key. + * + * @param s the key for the language string + * @return the language string + * @deprecated Use {@link GExpert#getLanguage(String)} instead. + */ @Deprecated public String getLanguage(String s) { return GExpert.getLanguage(s); } - + /** + * Sets the panel type based on the given CClass object. + * Updates the layout and adds the appropriate property panel. + * + * @param obj the CClass object + */ public void SetPanelType(CClass obj) { if (obj == null) return; @@ -161,24 +177,30 @@ public void SetPanelType(CClass obj) { this.revalidate(); } + /** + * Handles action events. + * + * @param e the ActionEvent + */ public void actionPerformed(ActionEvent e) { } - public void setPropertyChanged() { - - } - + /** + * Creates a JButton with an icon from the specified image name. + * + * @param imageName the name of the image file + * @return the created JButton + */ public static JButton CreateIconButton(String imageName) { String imgLocation = "images/" + imageName; URL imageURL = GExpert.class.getResource(imgLocation); JButton button = new JButton(); - - if (imageURL != null) { //image found + if (imageURL != null) { // image found button.setIcon(new ImageIcon(imageURL)); - } else { //no image found + } else { // no image found button.setText(imageName); } button.setMaximumSize(new Dimension(20, 18)); @@ -187,6 +209,13 @@ public static JButton CreateIconButton(String imageName) { return button; } + /** + * Creates a JTable with the specified objects. + * + * @param obj1 the first object + * @param obj2 the second object + * @return the created JTable + */ public static JTable createTable(Object obj1, Object obj2) { Object data[][] = {{obj1, obj2}}; String[] sname = {"", ""}; @@ -205,6 +234,9 @@ public static JTable createTable(Object obj1, Object obj2) { } + /** + * Panel for the color, line type and line width properties. + */ class Panel_CS extends JPanel implements ActionListener { DPanel d; @@ -352,6 +384,9 @@ public void paintComponent(Graphics g) { } } + /** + * Panel for the polygon properties. + */ class Panel_Line extends JPanel implements TableModelListener, ActionListener, ChangeListener { DPanel d; CLine line; @@ -473,6 +508,9 @@ else if (line.ext_type == 1) } + /** + * Panel for the circle properties. + */ class Panel_Circle extends JPanel implements TableModelListener { DPanel d; @@ -529,6 +567,9 @@ public void setVariable(Circle c) { } + /** + * Panel for the point properties. + */ class Panel_Point extends JPanel implements TableModelListener { DPanel d; @@ -608,6 +649,9 @@ public void paintComponent(Graphics g) { } } + /** + * Panel for the angle properties. + */ class Panel_Angle extends JPanel implements ActionListener, TableModelListener { DPanel d; JComboBox bcolor; @@ -759,6 +803,9 @@ public void setAgTabel(int n) { } + /** + * Base class for all property panels. + */ class Panel_Base extends JPanel { protected DPanel d; protected TitledBorder border; @@ -776,6 +823,9 @@ public void setBorder(CClass c) { } } + /** + * Panel for the text properties. + */ class Panel_text extends Panel_Base implements TableModelListener { CText tx; JTable table, table1, table2; @@ -886,6 +936,9 @@ public void setVariable(CText t) { } + /** + * Panel for the trace properties. + */ class Panel_trace extends Panel_Base implements TableModelListener { CTrace ts; JTable table, table1; @@ -942,6 +995,9 @@ public void setVariable(CTrace tc) { } } + /** + * Panel for the equation mark properties. + */ class Panel_eqmark extends Panel_Base implements TableModelListener { Cedmark mk; JTable table; @@ -982,6 +1038,9 @@ public void setVariable(Cedmark mc) { } } + /** + * Panel for the polygon properties. + */ class Panel_Polygon extends JPanel implements TableModelListener { DPanel d; @@ -1076,6 +1135,9 @@ public void setVariable(CPolygon c) { } + /** + * Panel for the arrow properties. + */ class Panel_arrow extends Panel_Base implements TableModelListener { CArrow arrow; JTable table; @@ -1116,48 +1178,9 @@ public void setVariable(CArrow mc) { } } - - class DefaultTableModel extends AbstractTableModel { - private Object[][] data; - - public DefaultTableModel(Object[][] o) { - data = o; - } - - public int getColumnCount() { - return 2; - } - - public int getRowCount() { - return data.length; - } - - public String getColumnName(int col) { - return ""; - } - - public Object getValueAt(int row, int col) { - return data[row][col]; - } - - public Class getColumnClass(int c) { - return getValueAt(0, c).getClass(); - } - - public boolean isCellEditable(int row, int col) { - if (col < 1) { - return false; - } else { - return true; - } - } - - public void setValueAt(Object value, int row, int col) { - data[row][col] = value; - fireTableCellUpdated(row, col); - } - } - + /** + * Table model for the property table. + */ class propertyTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = null; @@ -1205,6 +1228,9 @@ public void setValueAt(Object value, int row, int col) { } + /** + * Table model for the point properties. + */ class PointTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1249,6 +1275,9 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Table model for the line properties. + */ class LineTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1294,7 +1323,9 @@ public void setValueAt(Object value, int row, int col) { } } - + /** + * Table model for the circle properties. + */ class CircleTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1340,6 +1371,9 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Table model for the polygon properties. + */ class PolygonTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1381,73 +1415,14 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Rounds a double to two decimal places. + * + * @param r the double to round + * @return the rounded double + */ private double round(double r) { int t = (int) (100 * r); return t / 100.0; } - - class CPropertyTableCellRender implements TableCellRenderer { - TableCellRenderer deditor; - - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - return deditor.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - } - - } - - class CPropertyTableCellEditor implements TableCellEditor { - DefaultCellEditor editor; - DefaultCellEditor booleanEditor; - DefaultCellEditor selected; - - public CPropertyTableCellEditor() { - selected = editor = new DefaultCellEditor(new JTextField()); - booleanEditor = new DefaultCellEditor(new JCheckBox()); - } - - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, - int row, int column) { - if (value instanceof Boolean) { - selected = booleanEditor; - return booleanEditor.getTableCellEditorComponent(table, value, isSelected, row, column); - } - selected = editor; - return editor.getTableCellEditorComponent(table, value, isSelected, row, column); - } - - public void setEditorAt(int row, TableCellEditor editor) { - - } - - public Object getCellEditorValue() { - return selected.getCellEditorValue(); - } - - public boolean stopCellEditing() { - return selected.stopCellEditing(); - } - - public void cancelCellEditing() { - selected.cancelCellEditing(); - } - - public boolean isCellEditable(EventObject anEvent) { - return selected.isCellEditable(anEvent); - } - - public void addCellEditorListener(CellEditorListener l) { - selected.addCellEditorListener(l); - } - - public void removeCellEditorListener(CellEditorListener l) { - selected.removeCellEditorListener(l); - } - - public boolean shouldSelectCell(EventObject anEvent) { - return selected.shouldSelectCell(anEvent); - } - } } \ No newline at end of file diff --git a/src/main/java/wprover/CProveBarPanel.java b/src/main/java/wprover/CProveBarPanel.java index 2710bdca..ccec0f63 100644 --- a/src/main/java/wprover/CProveBarPanel.java +++ b/src/main/java/wprover/CProveBarPanel.java @@ -10,13 +10,9 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-27 - * Time: 13:25:17 - * To change this template use File | Settings | File Templates. + * CProveBarPanel is a custom panel that contains a toolbar for controlling the proof process. + * It includes buttons for stepping through the proof, playing the animation, and adjusting the speed. */ - public class CProveBarPanel extends FloatableToolBar { ProveBar bar; @@ -24,10 +20,6 @@ public CProveBarPanel(GExpert gx) { this.add(bar = new ProveBar(gx)); } - public void Enable(boolean r) { - bar.Enable(r); - } - public void setValue(int n) { bar.setValue(n); } @@ -58,6 +50,10 @@ public boolean isStepAtEnd() { } } +/** + * ProveBar is a custom toolbar that provides controls for stepping through a proof process. + * It includes buttons for stepping, playing, pausing, and stopping the proof animation. + */ class ProveBar extends JToolBar implements ActionListener, ChangeListener { private GExpert gxInstance; @@ -81,28 +77,10 @@ public ProveBar(GExpert gex) { init(); } - public ProveBar(GExpert gex, DPanel dd, DrawTextProcess dp, PanelProve pproof) { - super(); - gxInstance = gex; - this.dpane = dd; - this.dp = dp; - this.pproof = pproof; - init(); - } - public boolean isRunning() { return timer != null && timer.isRunning(); } - public void Enable(boolean r) { - bx1.setEnabled(r); - bx2.setEnabled(r); - bx3.setEnabled(r); - bx4.setEnabled(r); - bx5.setEnabled(r); - slider.setEnabled(r); - } - public void stop() { if (timer != null) { timer.stop(); @@ -330,10 +308,6 @@ public void adjustSpeed() { dp.setTimerDelay(v); } - public int getTimeDelay() { - return this.getInterval(); - } - public int getInterval() { int v = slider.getValue(); return 300 - v; diff --git a/src/main/java/wprover/CProveField.java b/src/main/java/wprover/CProveField.java index 77da26f1..e0fa847d 100644 --- a/src/main/java/wprover/CProveField.java +++ b/src/main/java/wprover/CProveField.java @@ -10,11 +10,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-25 - * Time: 19:19:11 - * To change this template use File | Settings | File Templates. + * CProveField is a class that represents a field for proving mathematical theorems. + * It handles the display and manipulation of proof steps and conditions. */ public class CProveField { private boolean HEAD = false; @@ -30,78 +27,41 @@ public class CProveField { int rstep = -1; int rmid = 0; + /** + * Default constructor for `CProveField`. + * Initializes the point and vectors for proof steps and conditions. + */ public CProveField() { pt = new Point(20, 20); clist = new Vector(); vlist = new Vector(); } + /** + * Sets the x and y coordinates of the point. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void setXY(int x, int y) { pt.setLocation(x, y); } + /** + * Drags the selected proof text by the specified delta values. + * + * @param dx the change in x-coordinate + * @param dy the change in y-coordinate + */ public void drag(double dx, double dy) { if (pselect == null) return; pt.setLocation((int) (pt.getX() + dx), (int) (pt.getY() + dy)); } - public void setCaptain(String sname) { - if (sname == null) return; - if (sname.endsWith(".gex")) - sname = sname.substring(0, sname.length() - 4); - cpname.setMessage(sname); - } - - public CProveField(DrawProcess dp) //undolist; - { - - pt = new Point(20, 20); - - cpname = new CProveText("", "theorem"); - cpname.setFont(new Font("Dialog", Font.PLAIN, 18)); - cpname.setMessageColor(Color.black); - - - clist = new Vector(); - vlist = new Vector(); - pselect = null; - - - Vector vnlist = dp.undolist; - if (vnlist.size() == 0) return; - - int i = 0; - - for (i = 0; i < vnlist.size(); i++) { - UndoStruct un = (UndoStruct) vnlist.get(i); - if (un.m_type == UndoStruct.T_TO_PROVE_NODE) { - CProveText cp = new CProveText(un, GExpert.getTranslationViaGettext("To Prove:") + " "); - vlist.add(cp); - break; - } - - CProveText cp; - if (i == 0) - cp = new CProveText(un, GExpert.getTranslationViaGettext("Given:") + " "); - else - cp = new CProveText(un); - clist.add(cp); - } - int index = 0; - - - i++; - for (; i < vnlist.size(); i++) { - UndoStruct un = (UndoStruct) vnlist.get(i); - CProveText cp = new CProveText(un, index); - vlist.add(cp); - index++; - } - - HEAD = true; - expandAll(); - } - + /** + * Regenerates the index for the proof steps. + * Sets the visibility and index of each proof step based on the `HEAD` flag. + */ public void reGenerateIndex() { if (HEAD) { @@ -130,6 +90,13 @@ public void reGenerateIndex() { } + /** + * Constructor for `CProveField` with a vector of conditions and a head flag. + * Initializes the point, vectors, and proof text based on the head flag. + * + * @param v the vector of conditions + * @param head the head flag indicating the type of proof field + */ public CProveField(Vector v, boolean head) { pt = new Point(20, 20); clist = new Vector(); @@ -168,56 +135,12 @@ public CProveField(Vector v, boolean head) { } - public CProveField(Cond co, boolean head) { - pt = new Point(20, 20); - clist = new Vector(); - vlist = new Vector(); - HEAD = head; - if (head) { - cpname = new CProveText("", "theorem"); - cpname.setFont(new Font("Dialog", Font.PLAIN, 18)); - cpname.setMessageColor(Color.black); - pselect = null; - } - - int i = -1; - CProveText ct = null; - while (co != null) { - if (head && i == -1) - ct = new CProveText(co, GExpert.getLanguage("To Prove:") + " "); - else - ct = new CProveText(null, co, i, true); - i++; - vlist.add(ct); - co = co.nx; - } - this.expandAll(); - - } - - public void genProve(Cond co) { - int i = 0; - CProveText ct = null; - while (co != null) { - ct = new CProveText(null, co, i, false); - i++; - vlist.add(ct); - co = co.nx; - } - } - - public void genCondition(Vector v) { - CProveText ct = null; - for (int i = 0; i < v.size(); i++) { - String s = (String) v.get(i); - if (i == 0) - ct = new CProveText(GExpert.getLanguage("Given:") + " ", s); - else - ct = new CProveText(s); - clist.add(ct); - } - } - + /** + * Constructor for `CProveField` with a vector of undo structures. + * Initializes the point and vectors for proof steps and conditions. + * + * @param ulist the vector of undo structures + */ public CProveField(Vector ulist) { pt = new Point(20, 20); @@ -230,6 +153,10 @@ public CProveField(Vector ulist) { } } + /** + * Expands all proof steps and conditions. + * Sets the visibility of each proof text to expanded. + */ public void expandAll() { for (int i = 0; i < clist.size(); i++) { @@ -244,28 +171,21 @@ public void expandAll() { } - public CProveText getFirstProveNode() { - return (CProveText) clist.get(0); - } - - - public CProveText createANewCommentNode() { - CProveText cp = new CProveText("", "Click to edit here"); - return cp; - } - + /** + * Draws the proof steps on the specified `Graphics2D` context. + * + * @param g2 the `Graphics2D` context to draw on + */ public void draw(Graphics2D g2) { Point p = new Point((int) pt.getX(), (int) pt.getY()); draw(g2, p); } - public int getFontSize() { - if (clist.size() == 0) return 14; - - CProveText cp = (CProveText) clist.get(0); - return cp.getFont().getSize(); - } - + /** + * Sets the font size for all proof texts. + * + * @param size the font size to set + */ public void setFontSize(int size) { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -278,10 +198,21 @@ public void setFontSize(int size) { this.pselect = null; } + /** + * Gets the currently selected proof text. + * + * @return the selected `CProveText` object + */ public CProveText getSelect() { return pselect; } + /** + * Undoes the proof steps to the head. + * + * @param dp the `DrawProcess` context + * @return true if the undo operation was successful + */ public boolean undo_to_head(DrawProcess dp) { if (HEAD) { if (vlist.size() == 0) return false; @@ -324,6 +255,12 @@ public boolean undo_to_head(DrawProcess dp) { return true; } + /** + * Runs the proof steps to the beginning. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean run_to_begin(DrawProcess dp) { if (HEAD) { // if (vlist.size() == 0) return false; @@ -362,6 +299,12 @@ public boolean run_to_begin(DrawProcess dp) { return true; } + /** + * Undoes the default action for the proof steps. + * + * @param dp the `DrawProcess` context + * @return true if the undo operation was successful + */ public boolean undo_default(DrawProcess dp) { if (HEAD) { if (vlist.size() == 0) return false; @@ -390,6 +333,12 @@ public boolean undo_default(DrawProcess dp) { return true; } + /** + * Runs the proof to the end. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean run_to_end(DrawProcess dp) { while (true) { if (!this.next_prove_step(dp)) { @@ -398,22 +347,12 @@ public boolean run_to_end(DrawProcess dp) { } } - - public void reGenerateAll() { - if (HEAD) - this.reGenerateIndex(); - - for (int i = 0; i < clist.size(); i++) { - CProveText cp = (CProveText) clist.get(i); - cp.regenerateAll(); - } - - for (int i = 0; i < vlist.size(); i++) { - CProveText cp = (CProveText) vlist.get(i); - cp.regenerateAll(); - } - } - + /** + * Redoes the invisible head step for the proof. + * + * @param dp the `DrawProcess` context + * @return the `CProveText` object that was redone, or null if none was found + */ public CProveText redo_invisible_head(DrawProcess dp) { if (vlist.size() == 0) return null; CProveText ct = (CProveText) vlist.get(0); @@ -424,10 +363,12 @@ public CProveText redo_invisible_head(DrawProcess dp) { return null; } - public void resetStep() { - rstep = rmid; - } - + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean next(DrawProcess dp) { CProveText ct = fd_text(++this.rstep); if (ct != null) { @@ -442,6 +383,12 @@ public boolean next(DrawProcess dp) { return true; } + /** + * Finds the `CProveText` object at the specified index. + * + * @param index the index to search for + * @return the `CProveText` object at the specified index, or null if none was found + */ public CProveText fd_text(int index) { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -457,6 +404,9 @@ public CProveText fd_text(int index) { return null; } + /** + * Sets the default step row for the proof steps. + */ public void setStepRowDefault() { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -469,6 +419,12 @@ public void setStepRowDefault() { } } + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean next_prove_step(DrawProcess dp) { if (HEAD) { CBoolean find = new CBoolean(false); @@ -489,7 +445,12 @@ public boolean next_prove_step(DrawProcess dp) { return true; } - + /** + * Sets the selected undo step for the proof. + * + * @param u the `UndoStruct` object to set + * @param dp the `DrawProcess` context + */ public void setSelectedUndo(UndoStruct u, DrawProcess dp) { CProveText ct = pselect = findPText(u); Vector vl = new Vector(); @@ -503,6 +464,12 @@ public void setSelectedUndo(UndoStruct u, DrawProcess dp) { } } + /** + * Finds the `CProveText` object for the specified undo structure. + * + * @param un the `UndoStruct` object to search for + * @return the `CProveText` object for the specified undo structure, or null if none was found + */ public CProveText findPText(UndoStruct un) { if (un == null) return null; @@ -530,7 +497,14 @@ public CProveText findPText(UndoStruct un) { return null; } - + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @param cpt the current `CProveText` object + * @param find a boolean indicating whether the step was found + * @return the next `CProveText` object, or null if none was found + */ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) { for (int i = 0; i < clist.size(); i++) { @@ -549,7 +523,12 @@ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) return null; } - + /** + * Draws the proof steps. + * + * @param g2 the `Graphics2D` context to draw on + * @param p the current position to draw at + */ public void draw(Graphics2D g2, Point p) { int dx = (int) p.getX(); int dy = (int) p.getY(); @@ -631,10 +610,23 @@ public void draw(Graphics2D g2, Point p) { } } + /** + * Moves the proof steps by the specified x and y coordinates. + * + * @param x the x-coordinate to move by + * @param y the y-coordinate to move by + */ public void move(double x, double y) { pt.setLocation(pt.getX() + (int) x, pt.getY() + (int) y); } + /** + * Handles mouse movement events and returns the `CProveText` object at the specified coordinates. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @return the `CProveText` object at the specified coordinates, or null if none is found + */ public CProveText mouseMove(double x, double y) { CProveText fd = null; for (int i = 0; i < clist.size(); i++) { @@ -654,6 +646,14 @@ public CProveText mouseMove(double x, double y) { return fd; } + /** + * Selects the `CProveText` object at the specified coordinates. + * + * @param x the x-coordinate of the selection + * @param y the y-coordinate of the selection + * @param on_select a boolean indicating whether the selection is active + * @return the selected `CProveText` object, or null if none is found + */ public CProveText select(double x, double y, boolean on_select) { CProveText sel = null; @@ -683,14 +683,9 @@ public CProveText select(double x, double y, boolean on_select) { return sel; } - public void expandProveNode(double x, double y) { - CProveText cpt = this.select(x, y, true); - - if (cpt != null) { - cpt.expand(); - } - } - + /** + * Clears the selection of all `CProveText` objects. + */ public void clearSelection() { for (int i = 0; i < clist.size(); i++) { CProveText ct = (CProveText) clist.get(i); @@ -704,6 +699,13 @@ public void clearSelection() { } + /** + * Draws a single step of the proof for the specified `CProveText` object. + * + * @param cp the `CProveText` object to draw + * @param p the current position to draw at + * @param g2 the `Graphics2D` context to draw on + */ public void drawAStep(CProveText cp, Point p, Graphics2D g2) { if (!cp.getVisible()) return; @@ -723,13 +725,13 @@ public void drawAStep(CProveText cp, Point p, Graphics2D g2) { } } - public void removeNode(Vector v) { - } - - public boolean removeLast() { - return true; - } - + /** + * Saves the proof text as a PostScript file. + * + * @param fp the `FileOutputStream` to write to + * @param stype the type of save operation + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (HEAD) { fp.write("%draw proof text\n".getBytes()); @@ -765,7 +767,14 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } - /////////////////////////////////////////////////////////// + /** + * Saves the proof text to a `DataOutputStream`. + * + * @param out the `DataOutputStream` to write to + * @param space the amount of space to use for formatting + * @return true if the save operation was successful + * @throws IOException if an I/O error occurs + */ public boolean saveText(DataOutputStream out, int space) throws IOException { if (HEAD) { for (int i = 0; i < vlist.size(); i++) { @@ -782,6 +791,12 @@ public boolean saveText(DataOutputStream out, int space) throws IOException { return true; } + /** + * Saves the state of the `CProveField` to a `DataOutputStream`. + * + * @param out the `DataOutputStream` to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(HEAD); @@ -806,6 +821,13 @@ public void Save(DataOutputStream out) throws IOException { } + /** + * Loads the state of the `CProveField` from a `DataInputStream`. + * + * @param in the `DataInputStream` to read from + * @param dp the `DrawProcess` context + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { HEAD = in.readBoolean(); @@ -835,6 +857,4 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { int py = in.readInt(); pt = new Point(px, py); } - - } diff --git a/src/main/java/wprover/CProveText.java b/src/main/java/wprover/CProveText.java index 0f696fea..69bf1c99 100644 --- a/src/main/java/wprover/CProveText.java +++ b/src/main/java/wprover/CProveText.java @@ -11,11 +11,8 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-23 - * Time: 21:54:51 - * To change this template use File | Settings | File Templates. + * CProveText is a class that represents a proof text in a graphical user interface. + * It contains methods for drawing the text, handling mouse events, and saving/loading data. */ public class CProveText { final private static int HSpace = 4; @@ -54,51 +51,77 @@ public class CProveText { private String bidx = ""; - - public static void setArrowImage(Image ico) { - arrow = ico; - } - - public static void setDrawPanel(JPanel panel) { - d = panel; - } - + /** + * Sets the expanded state of the proof text. + * + * @param exp true to expand, false to collapse + */ public void setExpanded(boolean exp) { isexpand = exp; } + /** + * Checks if the proof text is expanded. + * + * @return true if expanded, false otherwise + */ public boolean isExpanded() { return isexpand; } + /** + * Retrieves the condition associated with this proof text. + * + * @return the condition + */ public Cond getcond() { return m_co; } + /** + * Default constructor for the CProveText class. + */ public CProveText() { } + /** + * Resets the row counter to zero. + */ public static void resetRow() { D_ROW = 0; } + /** + * Retrieves the current row counter value. + * + * @return the current row counter value + */ public static int getRow() { return D_ROW; } + /** + * Constructor for the CProveText class with specified header and message. + * + * @param s1 the header text + * @param s2 the message text + */ public CProveText(String s1, String s2) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); head = s1; msg = s2; - } + /** + * Constructor for the CProveText class with an undo structure and header. + * + * @param un the undo structure + * @param s the header text + */ public CProveText(UndoStruct un, String s) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -106,11 +129,16 @@ public CProveText(UndoStruct un, String s) { msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Constructor for the CProveText class with a specified message. + * + * @param s the message text + */ public CProveText(String s) { rule = ""; rpath = ""; @@ -119,19 +147,26 @@ public CProveText(String s) { msg = s; } - + /** + * Constructor for the CProveText class with a condition and header. + * + * @param co the condition + * @param s the header text + */ public CProveText(Cond co, String s) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); head = s; msg = co.getText(); - //m_undo = un; } + /** + * Constructor for the CProveText class with an undo structure. + * + * @param un the undo structure + */ public CProveText(UndoStruct un) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -139,14 +174,21 @@ public CProveText(UndoStruct un) { msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Constructor for the CProveText class with a vector, condition, index, and a boolean flag. + * + * @param vl the vector + * @param co the condition + * @param index the index + * @param gc the boolean flag + */ public CProveText(Vector vl, Cond co, int index, boolean gc) { m_co = co; - rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -208,7 +250,6 @@ public CProveText(Vector vl, Cond co, int index, boolean gc) { } if (nco > 1) { - //dix += ")"; bidx = " " + dix; msg += bidx; } @@ -217,6 +258,12 @@ public CProveText(Vector vl, Cond co, int index, boolean gc) { } } + /** + * Constructor for the CProveText class with an undo structure and index. + * + * @param un the undo structure + * @param index the index + */ public CProveText(UndoStruct un, int index) { rule = ""; rpath = ""; @@ -224,104 +271,212 @@ public CProveText(UndoStruct un, int index) { head = (index + 1) + ": "; msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { - cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Sets the font size for the proof text. + * + * @param size the font size to set + */ public void setFontSize(int size) { font = new Font(font.getName(), font.getStyle(), size); if (cpfield != null) cpfield.setFontSize(size); } - + /** + * Sets the index for the proof text. + * + * @param index the index to set + */ public void setIndex(int index) { head = (index + 1) + ": "; if (cpfield != null) cpfield.reGenerateIndex(); } + /** + * Sets the visibility of the proof text. + * + * @param v true to make visible, false to hide + */ public void setVisible(boolean v) { visible = v; } + /** + * Checks if the proof text is visible. + * + * @return true if visible, false otherwise + */ public boolean getVisible() { return visible; } + /** + * Retrieves the undo structure associated with this proof text. + * + * @return the undo structure + */ public UndoStruct getUndoStruct() { return m_undo; } + /** + * Retrieves the rectangle representing the bounds of this proof text. + * + * @return the rectangle representing the bounds + */ public Rectangle getRectangle() { return new Rectangle((int) x, (int) y, (int) w, (int) height); } + /** + * Retrieves the color of the caption. + * + * @return the caption color + */ public Color getCaptainColor() { return chead; } + /** + * Sets the rule associated with this proof text. + * + * @param r the rule to set + */ public void setRule(String r) { rule = r; } + /** + * Retrieves the rule associated with this proof text. + * + * @return the rule + */ public String getRule() { return rule; } + /** + * Sets the path to the rule file. + * + * @param path the path to set + */ public void setRulePath(String path) { rpath = path; } + /** + * Retrieves the path to the rule file. + * + * @return the rule path + */ public String getRulePath() { return rpath; } + /** + * Sets the color of the caption. + * + * @param c the color to set + */ public void setCaptainColor(Color c) { chead = c; } + /** + * Retrieves the color of the message. + * + * @return the message color + */ public Color getMessageColor() { return cmsg; } + /** + * Sets the color of the message. + * + * @param c the color to set + */ public void setMessageColor(Color c) { cmsg = c; } + /** + * Retrieves the font used for the proof text. + * + * @return the font + */ public Font getFont() { return font; } + /** + * Sets the font used for the proof text. + * + * @param f the font to set + */ public void setFont(Font f) { font = f; } + /** + * Retrieves the header text. + * + * @return the header text + */ public String getHead() { return head; } + /** + * Sets the header text. + * + * @param s the header text to set + */ public void setHead(String s) { head = s; } + /** + * Retrieves the message text. + * + * @return the message text + */ public String getMessage() { return msg; } + /** + * Sets the message text. + * + * @param s the message text to set + */ public void setMessage(String s) { msg = s + " " + this.bidx; } + /** + * Retrieves the list of objects associated with the undo structure. + * + * @return the list of objects + */ public Vector getObjectList() { if (m_undo == null) return new Vector(); return m_undo.objectlist; } + /** + * Sets the list of objects associated with the undo structure. + * + * @param v the list of objects to set + */ public void setObjectList(Vector v) { if (m_undo != null) { m_undo.objectlist.clear(); @@ -329,52 +484,78 @@ public void setObjectList(Vector v) { } } + /** + * Sets the width of the proof text. + * + * @param ww the width to set + */ public void setWidth(double ww) { width = ww; } + /** + * Retrieves the width of the proof text. + * + * @return the width + */ public double getWidth() { return w; } - public double getHeadLength() { - return whead; - } - + /** + * Sets the x and y coordinates of the proof text. + * + * @param x the x-coordinate to set + * @param y the y-coordinate to set + */ public void setXY(double x, double y) { this.x = x; this.y = y; } + /** + * Retrieves the type string of the proof text. + * + * @return the type string + */ public String TypeString() { return "proof text"; } + /** + * Retrieves the description of the proof text. + * + * @return the description + */ public String getDescription() { return this.TypeString(); } + /** + * Selects the child proof text at the given coordinates. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @param onselect a boolean indicating whether to select the child + * @return the selected child proof text, or null if not found + */ public CProveText selectChild(double x1, double y1, boolean onselect) { if (cpfield != null) return cpfield.select(x1, y1, onselect); return null; } + /** + * Clears the selection of the proof text. + */ public void clearSelection() { if (cpfield != null) cpfield.clearSelection(); } - public void expandAll() { - if (this.isexpand) - this.setExpanded(false); - else - this.setExpanded(true); - - if (cpfield != null) - cpfield.expandAll(); - } - + /** + * Expands or collapses the proof text. + */ public void expand() { if (this.isexpand) this.setExpanded(false); @@ -382,6 +563,12 @@ public void expand() { this.setExpanded(true); } + /** + * Redoes the invisible head of the proof text in the draw process. + * + * @param dp the draw process + * @return the proof text with the redone invisible head + */ public CProveText redo_invisible_head(DrawProcess dp) { if (cpfield == null) return this; if (!this.isexpand) return this; @@ -393,12 +580,12 @@ public CProveText redo_invisible_head(DrawProcess dp) { return ct; } - public void regenerateAll() { - if (m_undo != null) { - this.msg = m_undo.msg; - } - } - + /** + * Retrieves the list of flash objects associated with the proof text. + * + * @param v the list to populate with flash objects + * @param dp the draw process + */ public void getFlashObjectList(Vector v, DrawProcess dp) { if (m_undo.m_type != UndoStruct.T_PROVE_NODE) { v.addAll(m_undo.getAllObjects(dp)); @@ -411,12 +598,12 @@ public void getFlashObjectList(Vector v, DrawProcess dp) { v.addAll(m_undo.getAllObjects(dp)); } -// public CProveText next(drawProcess dp) -// { -// - -// } - + /** + * Finds the proof text associated with the given undo structure. + * + * @param un the undo structure to find the proof text for + * @return the proof text associated with the undo structure, or null if not found + */ public CProveText findPText(UndoStruct un) { if (un == null) return null; @@ -428,9 +615,15 @@ public CProveText findPText(UndoStruct un) { return cpfield.findPText(un); } - + /** + * Finds the next proof step in the draw process. + * + * @param dp the draw process + * @param cpt the current proof text + * @param find a boolean indicating whether the proof step has been found + * @return the next proof step, or null if not found + */ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) { - if (find.getValue() == false) { if (cpt == this) { find.setValue(true); @@ -447,21 +640,24 @@ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) } } else { if (this.visible) { - if (!this.isexpand || m_undo.m_type == UndoStruct.T_UNDO_NODE)//||m_undo.m_type ==UndoStruct.T_COMBINED_NODE) - { -// dp.redo_step(m_undo); + if (!this.isexpand || m_undo.m_type == UndoStruct.T_UNDO_NODE) { + // dp.redo_step(m_undo); } return this; } else { - { -// dp.redo_step(m_undo); - } + // dp.redo_step(m_undo); return null; } - } } + /** + * Checks if the given coordinates are within the bounds of the proof text. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @return true if the coordinates are within the bounds, false otherwise + */ public boolean select(double x1, double y1) { double dx = x1 - x; double dy = y1 - y; @@ -472,10 +668,22 @@ public boolean select(double x1, double y1) { return false; } + /** + * Gets the location for the pop-up menu. + * + * @return the location for the pop-up menu + */ public Point getPopExLocation() { return new Point((int) (ax + 16), (int) (ay + 16)); } + /** + * Handles mouse movement events. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @return the proof text if the mouse is on the arrow, or null otherwise + */ public CProveText mouseMove(double x, double y) { if (!visible) return null; @@ -490,6 +698,13 @@ public CProveText mouseMove(double x, double y) { return null; } + /** + * Selects all proof texts at the given coordinates. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @return the selected proof text, or null if not found + */ public CProveText selectAll(double x1, double y1) { if (this.select(x1, y1)) return this; @@ -499,30 +714,42 @@ public CProveText selectAll(double x1, double y1) { return null; } + /** + * Moves the proof text by the given offsets. + * + * @param dx the x-offset to move by + * @param dy the y-offset to move by + */ public void move(double dx, double dy) { x = x + (int) dx; y = y + (int) dy; } - + /** + * Sets the current position of the proof text. + * + * @param p the point to set the position to + */ public void setCurrentPosition(Point p) { x = p.x; y = p.y; } - + /** + * Gets the next position for the proof text. + * + * @param p the point to set the next position to + */ public void getNextPosition(Point p) { p.setLocation((int) x, (int) (y + height)); } - public Point getNextPositionFromFirstNode() { - return new Point((int) (x + whead), (int) (y + height)); - } - - public double getHeadwidth() { - return whead; - } - + /** + * Runs the proof text to the beginning of the draw process. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean run_to_begin(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -532,6 +759,12 @@ else if (m_undo.m_type == UndoStruct.T_UNDO_NODE || m_undo.m_type == UndoStruct. return true; } + /** + * Undoes the default action for the proof text. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean undo_default(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -541,6 +774,12 @@ public boolean undo_default(DrawProcess dp) { return true; } + /** + * Undoes the proof text to the head of the draw process. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean undo_to_head(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -550,6 +789,12 @@ public boolean undo_to_head(DrawProcess dp) { return true; } + /** + * Draws the proof text with the given selection state. + * + * @param g2 the graphics context + * @param selected true if the proof text is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { if (selected == false) this.draw(g2); @@ -563,12 +808,24 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Draws the child proof text at the given point. + * + * @param g2 the graphics context + * @param p the point to draw the child proof text at + */ public void drawChild(Graphics2D g2, Point p) { if (cpfield != null) { cpfield.draw(g2, p); } } + /** + * Finds the proof text with the given row index. + * + * @param i the row index to find the proof text for + * @return the proof text with the given row index, or null if not found + */ public CProveText fd_text(int i) { if (i == this.m_row) return this; @@ -577,12 +834,20 @@ public CProveText fd_text(int i) { else return null; } + /** + * Sets the step row to the default value. + */ public void setStepRowDefault() { this.m_row = -1; if (cpfield != null) cpfield.setStepRowDefault(); } + /** + * Draws the proof text. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { if (head == null) return; m_row = D_ROW++; @@ -603,7 +868,6 @@ public void draw(Graphics2D g2) { whead = w = tw; if (msg == null || msg.length() == 0) return; - g2.setColor(cmsg); String[] sl = msg.split("\n"); double start = x + tw + HSpace; @@ -625,10 +889,15 @@ public void draw(Graphics2D g2) { g2.drawImage(arrow, (int) (ax), (int) (ay), Color.pink, d); } else g2.drawImage(arrow, (int) ax, (int) ay, d); - } - ////////////////////////////////////////////////////////////////////////// + /** + * Saves the text representation of the proof to the specified data output stream. + * + * @param out the data output stream to write to + * @param space the number of spaces to indent the text + * @throws IOException if an I/O error occurs + */ public void saveText(DataOutputStream out, int space) throws IOException { if (m_undo.m_type == UndoStruct.T_TO_PROVE_NODE || m_undo.m_type == UndoStruct.T_PROVE_NODE) { if (msg != null && msg.length() != 0) { @@ -643,11 +912,17 @@ public void saveText(DataOutputStream out, int space) throws IOException { if (cpfield != null) cpfield.saveText(out, space + 5); } - } - public void SavePS(FileOutputStream fp, int stype, int ntype) throws IOException // 0 0. 1 20. 2 25. - { + /** + * Saves the proof text as a PostScript file. + * + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @param ntype the number type (0 for default, 1 for 20 added, 2 for 25 added) + * @throws IOException if an I/O error occurs + */ + public void SavePS(FileOutputStream fp, int stype, int ntype) throws IOException { if (visible == false) return; if (head == null) return; @@ -683,33 +958,52 @@ else if (ntype == 2) cpfield.SavePS(fp, stype); } + /** + * Sets the PostScript color based on the given color and style type. + * + * @param c the color to set + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs + */ public void SavePsColor(Color c, FileOutputStream fp, int stype) throws IOException { - if (stype == 0) //color - { + if (stype == 0) { // color double r = ((double) (100 * c.getRed() / 255)) / 100; double g = ((double) (100 * c.getGreen() / 255)) / 100; double b = ((double) (100 * c.getBlue() / 255)) / 100; String s = r + " " + r + " " + r; s += " setrgbcolor "; fp.write(s.getBytes()); - } else if (stype == 1) //gray - { + } else if (stype == 1) { // gray String s = ""; double gray = (int) ((0.11 * c.getRed() + 0.59 * c.getGreen() + 0.3 * c.getBlue()) / 2.55) / 100.0; s += " " + gray + " " + gray + " " + gray + " setrgbcolor "; fp.write(s.getBytes()); - } else if (stype == 2) // black & white - { + } else if (stype == 2) { // black & white String s = "0.0 0.0 0.0 setrgbcolor "; fp.write(s.getBytes()); } } + /** + * Writes a string to the specified data output stream. + * + * @param out the data output stream to write to + * @param s the string to write + * @throws IOException if an I/O error occurs + */ public void WriteString(DataOutputStream out, String s) throws IOException { out.writeInt(s.length()); out.writeChars(s); } + /** + * Writes a font to the specified data output stream. + * + * @param out the data output stream to write to + * @param f the font to write + * @throws IOException if an I/O error occurs + */ public void WriteFont(DataOutputStream out, Font f) throws IOException { String s = f.getName(); WriteString(out, s); @@ -717,6 +1011,13 @@ public void WriteFont(DataOutputStream out, Font f) throws IOException { out.writeInt(f.getSize()); } + /** + * Reads a string from the specified data input stream. + * + * @param in the data input stream to read from + * @return the string read from the input stream + * @throws IOException if an I/O error occurs + */ public String ReadString(DataInputStream in) throws IOException { int size = in.readInt(); if (size == 0) return new String(""); @@ -726,15 +1027,27 @@ public String ReadString(DataInputStream in) throws IOException { return s; } + /** + * Reads a font from the specified data input stream. + * + * @param in the data input stream to read from + * @return the font read from the input stream + * @throws IOException if an I/O error occurs + */ public Font ReadFont(DataInputStream in) throws IOException { String name = ReadString(in); int stye = in.readInt(); int size = in.readInt(); return new Font(name, stye, size); - } + /** + * Saves the proof text data to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { this.WriteString(out, head); this.WriteString(out, msg); @@ -764,11 +1077,16 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(true); out.writeInt(m_undo.m_id); } - } + /** + * Loads the proof text data from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { - head = this.ReadString(in); msg = this.ReadString(in); if (CMisc.version_load_now >= 0.033) diff --git a/src/main/java/wprover/CStyleDialog.java b/src/main/java/wprover/CStyleDialog.java index bf23bd17..04305d2e 100644 --- a/src/main/java/wprover/CStyleDialog.java +++ b/src/main/java/wprover/CStyleDialog.java @@ -8,6 +8,10 @@ import java.awt.*; import java.util.Vector; +/** + * CStyleDialog is a class that creates a dialog for selecting drawing styles, including color, + * line width, and line type. It is used in the GExpert application. + */ public class CStyleDialog extends FloatableToolBar { public static int CELLWIDTH = 60; int action = -1; @@ -34,6 +38,13 @@ public class CStyleDialog extends FloatableToolBar { JPanel pagColor = null; JPanel topAgPanel = null; + /** + * Constructor for the CStyleDialog class. + * Initializes the dialog with the given GExpert and DPanel instances. + * + * @param gx the GExpert instance + * @param d the DPanel instance + */ public CStyleDialog(GExpert gx, DPanel d) { this.gxInstance = gx; this.d = d; @@ -47,6 +58,9 @@ public CStyleDialog(GExpert gx, DPanel d) { this.add(pcs); } + /** + * Resets the drawing style panels to the current drawing data indices. + */ public void reset() { rColor.index = DrawData.cindex; rStyle.index = DrawData.dindex; @@ -55,10 +69,19 @@ public void reset() { pgColor.index = DrawData.polygoncolor; } - public void setAction(int actionType) ////-1. ByPass Action; 0. defalut; - // 1. Draw Action + point; 2: draw action line + circle - // 3: fill action 4: angle 5: move/select/intersect - { + /** + * Sets the action type for the dialog and updates the layout accordingly. + * + * @param actionType the action type to set + * -1: ByPass Action + * 0: Default + * 1: Draw Action + point + * 2: Draw Action line + circle + * 3: Fill Action + * 4: Angle + * 5: Move/Select/Intersect + */ + public void setAction(int actionType) { reset(); if (actionType == action) return; @@ -101,24 +124,31 @@ public void reset() { case 4: this.removeAll(); this.add(mpanel); - + this.add(pColor); this.add(pStyle); this.add(pWidth); break; default: break; - } this.pack(); } + /** + * Returns the preferred size of the dialog. + * + * @return the preferred size of the dialog + */ public Dimension getPreferredSize() { Dimension dm = super.getPreferredSize(); return dm; } - + /** + * This class is used to create a panel for selecting color, line width, and line type. + * It extends the JPanel class and implements ActionListener to handle action events. + */ class Panel_CS extends JPanel implements ActionListener { DPanel d; @@ -178,7 +208,10 @@ public void paintComponent(Graphics g) { } } - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the JPanel class and implements MouseListener to handle mouse events. + */ class DrawStylePanel extends JPanel implements MouseListener { JLabel label; PopComboRender selector; @@ -287,7 +320,10 @@ public void mouseExited(MouseEvent e) { } } - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the JPanel class and implements MouseListener to handle mouse events. + */ class PopComboRender extends JPanel implements MouseListener { Vector vlist = new Vector(); @@ -355,6 +391,11 @@ public void mouseExited(MouseEvent e) { } } + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the ColorComboRender class and implements MouseListener to handle + * mouse events. + */ class PopComboRenderCell extends ColorComboRender implements MouseListener { public PopComboRenderCell(int type, int w, int h) { super(type, w, h); @@ -388,9 +429,11 @@ public void mouseExited(MouseEvent e) { } } - //////////// - /////////////////////////////////////////////////////////////// - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the PopComboRender class and overrides the mousePressed method to + * set the selected index for the corresponding style. + */ class GeneralPopComboRender extends PopComboRender { public GeneralPopComboRender(int type) { super(type); @@ -418,6 +461,11 @@ public void mousePressed(MouseEvent e) { } } + /** + * This class is used to handle the rendering of the polygon fill color selection. + * It extends the PopComboRender class and overrides the mousePressed method to + * set the polygon color when a color is selected. + */ class PolygonFillPopComboRender extends PopComboRender { public PolygonFillPopComboRender(int type) { super(type); @@ -434,41 +482,4 @@ public void mousePressed(MouseEvent e) { pgColor.index = idx; } } - - class AngleFillPopComboRender extends PopComboRender { - public AngleFillPopComboRender(int type) { - super(type); - } - - public void mousePressed(MouseEvent e) { - super.mousePressed(e); - PopComboRenderCell c = (PopComboRenderCell) e.getSource(); - int t = c.type; - int idx = c.index; - DrawData.polygoncolor = idx; - if (pgColor != null) - pgColor.index = idx; - } - } - - class AnglePropertyPanel extends JPanel implements ActionListener { - JComboBox boxType; - - public AnglePropertyPanel() { - this.setLayout(new FlowLayout(FlowLayout.LEFT)); - - Vector v = new Vector(); - v.add("Without Arrow"); - v.add("With Arrow"); - v.add("Multiple Arc"); - v.add("Fill"); - boxType = new JComboBox(v); - this.add(boxType); - boxType.addActionListener(AnglePropertyPanel.this); - } - - public void actionPerformed(ActionEvent e) { - } - } - } diff --git a/src/main/java/wprover/CTMark.java b/src/main/java/wprover/CTMark.java index 15fd9475..9d85b6a1 100644 --- a/src/main/java/wprover/CTMark.java +++ b/src/main/java/wprover/CTMark.java @@ -6,6 +6,10 @@ import java.io.DataOutputStream; import java.io.DataInputStream; +/** + * CTMark is a class that represents a mark on a drawing, defined by two lines. + * It provides methods for drawing the mark, moving it, and saving/loading its state. + */ public class CTMark extends CClass { CLine ln1, ln2; @@ -17,7 +21,9 @@ public class CTMark extends CClass { int pos1x, pos1y, pos2x, pos2y; int pos3x, pos3y, pos4x, pos4y; - + /** + * Default constructor for CTMark. + */ public CTMark() { super(TMARK); m_color = 3; @@ -25,6 +31,12 @@ public CTMark() { m_color = DrawData.RED; } + /** + * Constructs a CTMark with two lines. + * + * @param ln1 the first line + * @param ln2 the second line + */ public CTMark(CLine ln1, CLine ln2) { super(TMARK); @@ -34,18 +46,39 @@ public CTMark(CLine ln1, CLine ln2) { this.ln2 = ln2; } + /** + * Returns the type string of the mark. + * + * @return the type string + */ public String TypeString() { return null; } + /** + * Returns the description of the mark. + * + * @return the description + */ public String getDescription() { return null; } + /** + * Draws the mark using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Moves the mark by the specified delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ void move(double dx, double dy) { double r[] = CLine.Intersect(ln1, ln2); if (r == null || r.length == 0) @@ -64,6 +97,12 @@ else if (len > 10 && len < 40) length = len; } + /** + * Draws the mark using the specified Graphics2D object, with an option to select it. + * + * @param g2 the Graphics2D object + * @param selected whether the mark is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -84,11 +123,25 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Selects the mark based on the specified coordinates. + * + * @param x the x coordinate + * @param y the y coordinate + * @return true if the mark is selected, false otherwise + */ boolean select(double x, double y) { boolean xr = Math.pow(tx - x, 2) + Math.pow(ty - y, 2) < CMisc.PIXEPS * CMisc.PIXEPS; return xr; } + /** + * Saves the mark to a PostScript file. + * + * @param fp the FileOutputStream to write to + * @param stype the stroke type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -101,6 +154,16 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } + /** + * Draws the TTFoot mark using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + * @param x the x coordinate + * @param y the y coordinate + * @param p1 the first point + * @param p2 the second point + * @param select whether the mark is selected + */ public void drawTTFoot(Graphics2D g2, double x, double y, CPoint p1, CPoint p2, boolean select) { if (p1 == null || p2 == null) return; @@ -149,7 +212,12 @@ public void drawTTFoot(Graphics2D g2, double x, double y, CPoint p1, CPoint p2, pos4y = (int) (ey); } - + /** + * Saves the mark to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(ln1.m_id); @@ -157,6 +225,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(length); } + /** + * Loads the mark from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess used for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { super.Load(in, dp); int d = in.readInt(); diff --git a/src/main/java/wprover/CText.java b/src/main/java/wprover/CText.java index 98806062..c5eca799 100644 --- a/src/main/java/wprover/CText.java +++ b/src/main/java/wprover/CText.java @@ -10,11 +10,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-26 - * Time: 15:29:29 - * To change this template use File | Settings | File Templates. + * CText is a class that represents a text object in a graphical application. + * It extends the CClass class and provides methods to manipulate and display text. */ public class CText extends CClass { @@ -39,10 +36,20 @@ public class CText extends CClass { private double posX, posY; +/** + * Retrieves the font of this CText object. + * + * @return the font + */ public Font getFont() { return font; } + /** + * Sets the text type and parses the text value. + * + * @param t the text type to set + */ public void setTextType(int t) { type = t; tvalue = CTextValue.parseString(str); @@ -53,49 +60,79 @@ public void setTextType(int t) { m_color = 16; } - public boolean fontsizeChange(int n) { - int size = font.getSize() + n; - if (size <= 5) - return false; - - font = new Font(font.getName(), font.getStyle(), size); - return true; - } - + /** + * Retrieves the font size of this CText object. + * + * @return the font size + */ public int getFontSize() { return font.getSize(); } + /** + * Sets the font to bold. + */ public void setBold() { if (!font.isBold()) font = new Font(font.getName(), Font.BOLD, font.getSize()); } + /** + * Sets the font to plain. + */ public void setPlain() { if (!font.isPlain()) font = new Font(font.getName(), Font.PLAIN, font.getSize()); } + /** + * Sets the font of this CText object. + * + * @param f the font to set + */ public void setFont(Font f) { font = f; } + /** + * Sets the font size of this CText object. + * + * @param n the font size to set + */ public void setFontSize(int n) { if (n != font.getSize()) font = new Font(font.getName(), font.getStyle(), n); } + /** + * Default constructor for the CText class. + * Initializes the text object with default values. + */ public CText() { super(CClass.TEXT); str = new String(); - } + /** + * Sets the x and y coordinates of this CText object. + * + * @param x the x-coordinate to set + * @param y the y-coordinate to set + */ public void setXY(int x, int y) { this.x = x; this.y = y; } + /** + * Constructor for the CText class. + * Initializes the text object with the specified parent, coordinates, and type. + * + * @param f the parent CClass object + * @param dx the x-coordinate offset + * @param dy the y-coordinate offset + * @param type the type of the text + */ public CText(CClass f, double dx, double dy, int type) { super(CClass.TEXT); str = new String(); @@ -107,15 +144,26 @@ public CText(CClass f, double dx, double dy, int type) { father = f; } + /** + * Moves the text object by the specified offsets. + * + * @param dx the x-offset to move by + * @param dy the y-offset to move by + */ public void move(double dx, double dy) { super.move(dx, dy); if (type == NORMAL_TEXT || type == VALUE_TEXT) { x += dx; y += dy; } - } + /** + * Checks if this CText object is equal to another object. + * + * @param obj the object to compare with + * @return true if the objects are equal, false otherwise + */ public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof CText)) return false; @@ -137,6 +185,14 @@ public boolean equals(Object obj) { // font = new Font("Dialog", Font.PLAIN, 14); // } + /** + * Constructor for the CText class. + * Initializes the text object with the specified coordinates and string. + * + * @param x the x-coordinate of the text + * @param y the y-coordinate of the text + * @param s the string content of the text + */ public CText(int x, int y, String s) { super(CClass.TEXT); str = s; @@ -145,7 +201,11 @@ public CText(int x, int y, String s) { this.y = y; } - + /** + * Retrieves the text content of this CText object. + * + * @return the text content + */ public String getText() { if (type == NORMAL_TEXT) return str; @@ -157,15 +217,23 @@ else if (type == VALUE_TEXT) return str; return null; - } + /** + * Sets the text content of this CText object. + * + * @param s the text content to set + */ public void setText1(String s) { str = s; } + /** + * Sets the text content of this CText object based on its type. + * + * @param s the text content to set + */ public void setText(String s) { - if (type == NORMAL_TEXT) str = s; else if (type == NAME_TEXT) @@ -183,42 +251,67 @@ else if (type == CNAME_TEXT) { } } + /** + * Retrieves the string content of this CText object. + * + * @return the string content + */ public String getString() { return str; } + /** + * Retrieves the dimensions of the text as a Dimension object. + * + * @return the dimensions of the text + */ public Dimension getTextDimension() { return new Dimension((int) w, (int) height); } + /** + * Retrieves the x-coordinate of the text. + * + * @return the x-coordinate + */ public int getX() { return x; } + /** + * Retrieves the y-coordinate of the text. + * + * @return the y-coordinate + */ public int getY() { return y; } + /** + * Retrieves the location of the text as a Point object. + * + * @return the location of the text + */ public Point getLocation() { return new Point(x, y); } + /** + * Retrieves the type of this CText object. + * + * @return the type of the text + */ public int getType() { return this.type; } - - public int vlength() { - if (str == null) return 0; - return str.length(); - } - - public void setSvalue(String s) { - svalue = s; - } - public boolean nameTextShown = CMisc.nameTextShown; + /** + * Checks if the text should be drawn based on its visibility and the visibility of its parent. + * + * @return true if the text should be drawn, false otherwise + */ public boolean isdraw() { if (!super.isdraw()) return false; @@ -230,14 +323,18 @@ public boolean isdraw() { return CMisc.nameTextShown; } else { if (type == NAME_TEXT) - return nameTextShown; //APPLET ONLY + return nameTextShown; // APPLET ONLY } return true; } + /** + * Retrieves the x-coordinate for drawing the text. + * + * @return the x-coordinate for drawing + */ public int getSX() { - double lx; - lx = 0; + double lx = 0; if (type == NORMAL_TEXT) { lx = x; } else if (type == NAME_TEXT) { @@ -250,25 +347,31 @@ public int getSX() { return (int) lx; } + /** + * Retrieves the y-coordinate for drawing the text. + * + * @return the y-coordinate for drawing + */ public int getSY() { - double ly; - ly = 0; + double ly = 0; if (type == NORMAL_TEXT) { -// lx = x; ly = y; } else if (type == NAME_TEXT) { CPoint p = (CPoint) father; -// lx = p.getx() + x; ly = p.gety() + y; } else if (type == CNAME_TEXT && CMisc.show_angle_text) { CAngle ag = (CAngle) father; -// lx = ag.getxForString() + x; ly = ag.getyForString() + y; } return (int) ly; } + /** + * Retrieves the value text of this CText object. + * + * @return the value text + */ public String getValueText() { double r = tvalue.dvalue; //CTextValue.calvalue(tvalue, null); String shead = ""; @@ -295,6 +398,11 @@ public String getValueText() { return shead + " = " + r; } + /** + * Draws the text object using the provided Graphics2D context. + * + * @param g2 the Graphics2D context + */ public void draw(Graphics2D g2) { if (!isdraw()) return; @@ -330,12 +438,9 @@ public void draw(Graphics2D g2) { ly = r[1] + y + dy - height / 2; posX = lx; posY = ly; - //lx = ag.getxForString() + x - w / 2; - //ly = ag.getyForString() + y - height / 2; } } else if (type == VALUE_TEXT) { - tstring = getValueText(); lx = x; ly = y; @@ -343,11 +448,9 @@ public void draw(Graphics2D g2) { posY = ly; } - if (tstring == null) return; if (tstring.length() == 0) return; - String[] sl = tstring.split("\n"); g2.setFont(font); super.setDraw(g2); @@ -364,9 +467,14 @@ public void draw(Graphics2D g2) { w = r2.getWidth(); g2.drawString(sl[i], (float) lx, (float) (ly + (i + 1) * h)); } - } + /** + * Draws the text object with a selection highlight using the provided Graphics2D context. + * + * @param g2 the Graphics2D context + * @param select true if the text object is selected, false otherwise + */ public void draw(Graphics2D g2, boolean select) { if (visible == false) return; @@ -404,6 +512,11 @@ public void draw(Graphics2D g2, boolean select) { g2.draw(rc); } + /** + * Retrieves a string representation of the type of this text object. + * + * @return the type string + */ public String TypeString() { if (str == null) return ""; @@ -434,10 +547,24 @@ public String TypeString() { return null; } + /** + * Retrieves a description of this text object. + * + * @return the description + */ public String getDescription() { return this.TypeString(); } + /** + * Checks if the given rectangle defined by (x0, y0) and (x1, y1) intersects with this text object. + * + * @param x0 the x-coordinate of the first corner of the rectangle + * @param y0 the y-coordinate of the first corner of the rectangle + * @param x1 the x-coordinate of the opposite corner of the rectangle + * @param y1 the y-coordinate of the opposite corner of the rectangle + * @return true if the rectangle intersects with this text object, false otherwise + */ public boolean inRect(double x0, double y0, double x1, double y1) { if (x0 > x1) { double r = x0; @@ -449,11 +576,17 @@ public boolean inRect(double x0, double y0, double x1, double y1) { double r = y0; y0 = y1; y1 = r; - } return x0 < x && y0 < y && x1 > x + w && y1 > y + height; } + /** + * Checks if the given point (x1, y1) is within the bounds of this text object. + * + * @param x1 the x-coordinate of the point + * @param y1 the y-coordinate of the point + * @return true if the point is within the bounds, false otherwise + */ public boolean select(double x1, double y1) { if (visible == false) return false; @@ -486,6 +619,12 @@ public boolean select(double x1, double y1) { return false; } + /** + * Drags the text object by the given offsets (dx, dy). + * + * @param dx the x-offset to drag by + * @param dy the y-offset to drag by + */ public void drag(double dx, double dy) { x += dx; y += dy; @@ -509,10 +648,17 @@ public void drag(double dx, double dy) { x -= dx + x1; y -= dy + y1; } - } } + /** + * Drags the text object from the given starting point (x0, y0) by the given offsets (dx, dy). + * + * @param x0 the starting x-coordinate + * @param y0 the starting y-coordinate + * @param dx the x-offset to drag by + * @param dy the y-offset to drag by + */ public void drag(double x0, double y0, double dx, double dy) { if (type == NORMAL_TEXT || type == VALUE_TEXT) drag(dx, dy); @@ -529,7 +675,6 @@ else if (type == NAME_TEXT) { if (len > CMisc.rlength) { this.x = (int) (xp * CMisc.rlength / len); this.y = (int) (yp * CMisc.rlength / len); - } else { this.x += dx; this.y += dy; @@ -547,21 +692,24 @@ else if (type == NAME_TEXT) { if (len > CMisc.rlength) { this.x = (int) (xp * CMisc.rlength / len); this.y = (int) (yp * CMisc.rlength / len); - } else { this.x += dx; this.y += dy; } } - - } + /** + * Saves the text object as a PostScript file. + * + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!isdraw()) return; if (father != null && !father.isdraw()) return; - String tstring = null; double lx, ly; @@ -611,11 +759,15 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } else { fp.write(("mf " + (int) lx + " " + (int) (-ly - 15) + " moveto (" + tstring + ") " + "show\n").getBytes()); } - } + /** + * Saves the text object to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { - super.Save(out); out.writeInt(type); @@ -642,7 +794,6 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(s.length); out.write(s, 0, s.length); out.writeInt(father.m_id); - } else if (type == VALUE_TEXT) { s = str.getBytes(); out.writeInt(s.length); @@ -651,12 +802,16 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(-1); else out.writeInt(father.m_id); } - - } + /** + * Loads the text object from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { - if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); x = in.readInt(); @@ -707,7 +862,6 @@ else if (m_color == 7) } else { super.Load(in, dp); - type = in.readInt(); x = in.readInt(); y = in.readInt(); @@ -754,10 +908,6 @@ else if (m_color == 7) father = dp.getOjbectById(id); } } - - } - } - } diff --git a/src/main/java/wprover/CTextValue.java b/src/main/java/wprover/CTextValue.java index c24d3a97..38a10c1d 100644 --- a/src/main/java/wprover/CTextValue.java +++ b/src/main/java/wprover/CTextValue.java @@ -3,11 +3,9 @@ import maths.TMono; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-28 - * Time: 13:31:13 - * To change this template use File | Settings | File Templates. + * CTextValue is a class that represents a mathematical expression in a tree structure. + * It can parse a string representation of the expression, evaluate it, and perform various + * mathematical functions. */ public class CTextValue { @@ -50,25 +48,50 @@ public class CTextValue { CTextValue left; CTextValue right; - + /** + * Default constructor for CTextValue. + */ public CTextValue() { } + /** + * Constructor for CTextValue with a specified type. + * + * @param t the type of the CTextValue + */ private CTextValue(int t) { TYPE = t; } - + /** + * Parses a string representation of a mathematical expression into a CTextValue object. + * + * @param str the string representation of the expression + * @return the parsed CTextValue object + */ public static CTextValue parseString(String str) { TMono index = new TMono(0, 0, 0); return parseEntityA(str.toCharArray(), index); } + /** + * Parses a byte array representation of a mathematical expression into a CTextValue object. + * + * @param src the byte array representation of the expression + * @param index the index used for parsing + * @return the parsed CTextValue object + */ public static CTextValue parse(byte[] src, TMono index) { return null; } + /** + * Gets the function index for a given function name. + * + * @param s the function name + * @return the index of the function, or -1 if not found + */ public static int getFunction(String s) { for (int i = 0; i < sfunction.length; i++) { if (s.equalsIgnoreCase(sfunction[i])) @@ -77,6 +100,13 @@ public static int getFunction(String s) { return -1; } + /** + * Parses a function name from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed function name + */ public static String parseFunction(char[] src, TMono index) { parseSpace(src, index); int i = index.x; @@ -95,7 +125,13 @@ public static String parseFunction(char[] src, TMono index) { return s; } - + /** + * Parses an entity of type A from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityA(char[] src, TMono index) { CTextValue ct1 = parseEntityB(src, index); @@ -131,6 +167,13 @@ else if (b == '-') return ct1; } + /** + * Parses an entity of type B from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityB(char[] src, TMono index) { parseSpace(src, index); @@ -164,6 +207,13 @@ else if (b == '/') return ct1; } + /** + * Parses an entity of type C from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityC(char[] src, TMono index) { // ^ parseSpace(src, index); CTextValue t1 = parseEntityD(src, index); @@ -204,6 +254,13 @@ private static CTextValue parseEntityC(char[] src, TMono index) { // ^ else return t1; } + /** + * Parses an entity of type D from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityD(char[] src, TMono index) { // (), x1,value. @@ -274,35 +331,13 @@ private static CTextValue parseEntityD(char[] src, TMono index) { // (), x1,valu } - private static char parseByte(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - if (i >= src.length) return 0; - - char b = src[i]; - if (b != '+' && b != '-') { - index.x = i; - return 0; - } - index.x++; - - parseSpace(src, index); - return b; - } - - private static char parseByteB(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - if (i >= src.length) return 0; - - if (src[i] == '*' || src[i] == '/') { - index.x++; - parseSpace(src, index); - return src[i]; - } - return 0; - } - + /** + * Parses an integer value from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed integer value + */ private static double parseInt(char[] src, TMono index) { parseSpace(src, index); @@ -339,6 +374,12 @@ else if (step == 0) { return v; } + /** + * Parses and skips spaces in the source character array. + * + * @param src the source character array + * @param index the index used for parsing + */ private static void parseSpace(char[] src, TMono index) { int i = index.x; @@ -352,64 +393,45 @@ private static void parseSpace(char[] src, TMono index) { } - private static String getAString(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - String s = new String(); - - if (src == null || i >= src.length) return s; - - while ((src[i] >= 'a' && src[i] <= 'z') || (src[i] >= 'A' && src[i] <= 'Z')) { - s += src[i]; - i++; - if (i >= src.length) break; - } - - if (s.length() != 0) { - index.x = i; - return s; - } - - - if (src[i] == '(' || src[i] == ')' || src[i] == '*' || src[i] == '/' || src[i] == '^') { - s += src[i]; - index.x = i + 1; - return s; - } - - while (src[i] >= '0' && src[i] <= '9') { - s += src[i]; - i++; - if (i >= src.length) break; - - } - if (s.length() != 0) { - index.x = i; - return s; - } - parseSpace(src, index); - - return s; - } - + /** + * Rounds a double value to three decimal places. + * + * @param r the double value to round + * @return the rounded double value + */ public static double roud3(double r) { return Math.round(r * 1000 + 0.1) / 1000.0; } + /** + * Calculates the value of this CTextValue object using the specified DrawProcess. + * + * @param dp the DrawProcess used for calculation + */ public void calculate(DrawProcess dp) { double r = calvalue(this, dp); this.dvalue = roud3(r); } + /** + * Calculates the value of the specified CTextValue object using the specified DrawProcess. + * + * @param ct the CTextValue object to calculate + * @param dp the DrawProcess used for calculation + * @return the calculated double value + */ public static double calvalue(CTextValue ct, DrawProcess dp) { if (ct == null) return 0.0; return dp.calculate(ct); } -// "sin", "cos", "tan", "arcsin", "arccos", "arctan", - - // "abs", "sqrt", "ln", "log", "sgn", "round", "trunc"} - + /** + * Calculates the result of a mathematical function on a given value. + * + * @param n the function index + * @param v the value to apply the function to + * @return the result of the function + */ public static double cal_func(int n, double v) { switch (n) { case 0: diff --git a/src/main/java/wprover/CTrace.java b/src/main/java/wprover/CTrace.java index 49c079bb..da633f17 100644 --- a/src/main/java/wprover/CTrace.java +++ b/src/main/java/wprover/CTrace.java @@ -6,6 +6,10 @@ import java.io.DataInputStream; import java.io.FileOutputStream; +/** + * CTrace is a class that represents a trace of points in a graphical application. + * It extends the CClass class and provides methods to manage and draw the trace. + */ public class CTrace extends CClass { private static final int MAX_POINT = 501; @@ -18,7 +22,11 @@ public class CTrace extends CClass { private boolean dlns; private final static int MAXLEN = 300; - + /** + * Constructs a CTrace object with the specified point. + * + * @param p the point associated with the trace + */ public CTrace(CPoint p) { super(CClass.TRACE); m_name = "Trace of " + p; @@ -28,6 +36,13 @@ public CTrace(CPoint p) { Num = -1; } + /** + * Constructs a CTrace object with the specified points and line. + * + * @param p the point associated with the trace + * @param po the point on the line + * @param o the line associated with the trace + */ public CTrace(CPoint p, CPoint po, CLine o) { super(CClass.TRACE); m_name = "Locus of " + p + " when " + po + " is on" + o; @@ -38,6 +53,13 @@ public CTrace(CPoint p, CPoint po, CLine o) { oObj = o; } + /** + * Constructs a CTrace object with the specified points and circle. + * + * @param p the point associated with the trace + * @param po the point on the circle + * @param o the circle associated with the trace + */ public CTrace(CPoint p, CPoint po, Circle o) { super(CClass.TRACE); m_name = "Locus of " + p + " when " + po + " is on" + o; @@ -48,26 +70,52 @@ public CTrace(CPoint p, CPoint po, Circle o) { oObj = o; } + /** + * Checks if the specified point is the trace point. + * + * @param pt the point to check + * @return true if the specified point is the trace point, false otherwise + */ public boolean isTracePt(CPoint pt) { return point == pt && po == null && oObj == null; } - + /** + * Sets whether to draw lines for the trace. + * + * @param r true to draw lines, false otherwise + */ public void setDLns(boolean r) { dlns = r; } + /** + * Checks if lines are drawn for the trace. + * + * @return true if lines are drawn, false otherwise + */ public boolean isDrawLines() { return dlns; } + /** + * Sets the number of points for the trace. + * + * @param n the number of points + */ public void setNumPts(int n) { if (n < MAX_POINT) Num = n; else Num = MAX_POINT; } + /** + * Draws the trace using the specified Graphics2D object, with an option to select it. + * + * @param g2 the Graphics2D object + * @param selected whether the trace is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -93,6 +141,15 @@ else if (i < Num - 1) } } + /** + * Draws a line segment between two points using the specified Graphics2D object. + * + * @param x the x coordinate of the first point + * @param y the y coordinate of the first point + * @param x1 the x coordinate of the second point + * @param y1 the y coordinate of the second point + * @param g2 the Graphics2D object + */ public void drawALN(int x, int y, int x1, int y1, Graphics2D g2) { if ((x1 < -0 || x1 > 1000) && (x < -0 || x > 1000)) @@ -109,19 +166,41 @@ public void drawALN(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x, y, x1, y1); } + /** + * Draws the trace using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Returns the type string of the trace. + * + * @return the type string of the trace + */ public String TypeString() { if (m_name == null) return "Trace"; return "Trace " + m_name; } + /** + * Returns the description of the trace. + * + * @return the description of the trace + */ public String getDescription() { return "Trace " + point.TypeString(); } + /** + * Selects the trace based on the specified coordinates. + * + * @param x the x coordinate + * @param y the y coordinate + * @return true if the trace is selected, false otherwise + */ public boolean select(double x, double y) { if (!isdraw()) return false; double r2 = CMisc.PIXEPS * CMisc.PIXEPS; @@ -132,6 +211,12 @@ public boolean select(double x, double y) { return false; } + /** + * Moves the trace by the specified delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ public void move(double dx, double dy) { for (int i = 0; i < Num; i++) { PX[i] += dx; @@ -139,6 +224,13 @@ public void move(double dx, double dy) { } } + /** + * Saves the trace to a PostScript file. + * + * @param fp the FileOutputStream to write to + * @param stype the stroke type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -163,7 +255,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } } - + /** + * Saves the trace to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(point.m_id); @@ -194,6 +291,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(dlns); } + /** + * Loads the trace from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess used for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { super.Load(in, dp); if (CMisc.version_load_now >= 0.011) { @@ -216,9 +320,13 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { } } - /////////////////////////////////////////////////////// - - + /** + * Adds a trace point at the specified index with the given coordinates. + * + * @param i the index to add the trace point + * @param x the x coordinate of the trace point + * @param y the y coordinate of the trace point + */ public void addTracePoint(int i, double x, double y) { PX[i] = (int) x; PY[i] = (int) y; @@ -229,12 +337,12 @@ public void addTracePoint(int i, double x, double y) { } - public void addTracePoint(int x, int y, int i) { - PX[i] = x; - PY[i] = y; - soft(i); - } - + /** + * Adds a trace point with the given coordinates. + * + * @param x the x coordinate of the trace point + * @param y the y coordinate of the trace point + */ public void addTracePoint(int x, int y) { for (int i = 0; i <= Num; i++) @@ -248,7 +356,9 @@ public void addTracePoint(int x, int y) { PY[Num] = y; } - + /** + * Softens the edges of the trace. + */ public void softEdge() { for (int i = 2; i < Num - 1; i++) { @@ -276,17 +386,19 @@ public void softEdge() { } } + /** + * Softens the trace at the specified index. + * + * @param i the index to soften + */ public void soft(int i) { } - - public void trans(double dx, double dy) { - for (int i = 0; i < Num; i++) { - PX[i] += dx; - PY[i] += dy; - } - } - + /** + * Calculates the round length of the trace. + * + * @return the round length of the trace + */ public double Roud_length() { if (Num == 0) return 0.0; @@ -304,29 +416,59 @@ public double Roud_length() { return len; } + /** + * Returns the x coordinate of the trace point at the specified index. + * + * @param i the index of the trace point + * @return the x coordinate of the trace point + */ int getPtxi(int i) { return PX[i]; } + /** + * Returns the y coordinate of the trace point at the specified index. + * + * @param i the index of the trace point + * @return the y coordinate of the trace point + */ int getPtyi(int i) { return PY[i]; } + /** + * Returns the point associated with the trace. + * + * @return the point associated with the trace + */ public CPoint getPoint() { return point; } + /** + * Returns the point on the trace. + * + * @return the point on the trace + */ public CPoint getonPoint() { return po; } + /** + * Returns the object associated with the trace. + * + * @return the object associated with the trace + */ public CClass getOnObject() { return oObj; } + /** + * Returns the number of points in the trace. + * + * @return the number of points in the trace + */ public int getPointSize() { return Num; } - - } diff --git a/src/main/java/wprover/Cedmark.java b/src/main/java/wprover/Cedmark.java index e9e82c7e..02f68b17 100644 --- a/src/main/java/wprover/Cedmark.java +++ b/src/main/java/wprover/Cedmark.java @@ -7,13 +7,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-23 - * Time: 14:50:02 - * To change this template use File | Settings | File Templates. - * - * This class represents an equality mark between two points. + * Represents a Cedmark object, which is a type of equality mark in a geometric drawing. + * It extends the CClass class and provides methods for drawing and saving the equality mark. */ public class Cedmark extends CClass { private static int DEFAULT_LEN = 8; @@ -154,15 +149,6 @@ public void drawALine(double x, double y, double dx, double dy, Graphics2D g2) { g2.drawLine((int) xx1, (int) yy1, (int) xx2, (int) yy2); } - /** - * Draws the equality mark using the given Graphics2D object and a point. - * - * @param g2 the Graphics2D object - * @param d the point - */ - void draw(Graphics2D g2, CPoint d) { - } - /** * Draws the equality mark with the option to highlight if selected. * diff --git a/src/main/java/wprover/Circle.java b/src/main/java/wprover/Circle.java index ee684b22..a92da603 100644 --- a/src/main/java/wprover/Circle.java +++ b/src/main/java/wprover/Circle.java @@ -8,13 +8,7 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:29:48 - * To change this template use File | Settings | File Templates. - * - * This class represents a circle in geometric constructions. + * Represents a geometric circle with various properties and methods. */ public class Circle extends CClass { public static int PCircle = 0; @@ -315,6 +309,13 @@ public Circle(CPoint O, CPoint A, CPoint B, CPoint C) { points.add(C); } +/** + * Constructs a Circle object with the specified center and two points on the circle. + * + * @param O the center of the circle + * @param A the first point on the circle + * @param B the second point on the circle + */ public Circle(CPoint O, CPoint A, CPoint B) { super(CClass.CIRCLE); this.o = O; @@ -322,34 +323,54 @@ public Circle(CPoint O, CPoint A, CPoint B) { points.add(B); } + /** + * Constructs a Circle object with the specified center and one point on the circle. + * + * @param O the center of the circle + * @param A the point on the circle + */ public Circle(CPoint O, CPoint A) { super(CClass.CIRCLE); this.o = O; points.add(A); } + /** + * Constructs a Circle object with the specified type and center. + * + * @param type the type of the circle + * @param O the center of the circle + */ public Circle(int type, CPoint O) { super(CClass.CIRCLE); this.o = O; this.type = type; } + /** + * Adds a constraint to the circle. + * + * @param cs the constraint to add + */ public void addConstraint(Constraint cs) { cons.add(cs); } - public boolean hasPoint(CPoint p) { - for (int i = 0; i < points.size(); i++) { - if (p.isEqual((CPoint) points.get(i))) return true; - } - return false; - } - + /** + * Adds a point to the circle. + * + * @param p the point to add + */ public void addPoint(CPoint p) { if (!points.contains(p)) points.add(p); } + /** + * Adjusts the coordinates of the given point to lie on the circle. + * + * @param p the point to adjust + */ public void pointStickToCircle(CPoint p) { double x = p.getx(); double y = p.gety(); @@ -362,13 +383,27 @@ public void pointStickToCircle(CPoint p) { double y1 = yo + (y - yo) * R / R1; double x1 = xo + (x - xo) * R / R1; p.setXY(x1, y1); - } + /** + * Checks if the given coordinates are on the circle. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the coordinates are on the circle, false otherwise + */ public boolean on_circle(double x, double y) { return this.select(x, y); } + /** + * Checks if the given coordinates are near the circle within a specified tolerance. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param eps the tolerance + * @return true if the coordinates are near the circle, false otherwise + */ public boolean nearcircle(double x, double y, double eps) { double ox, oy; ox = o.getx(); @@ -381,18 +416,21 @@ public boolean nearcircle(double x, double y, double eps) { return false; } + /** + * Adjusts the coordinates of the given point to lie on the circle using a smart algorithm. + * + * @param p the point to adjust + */ public void SmartPonc(CPoint p) { - // CPoint pt = (CPoint) points.get(0); double ox, oy, x, y; ox = o.getx(); oy = o.gety(); x = p.getx(); y = p.gety(); - double r = this.getRadius();//Math.sqrt(Math.pow(pt.getx() - ox, 2) + Math.pow(pt.gety() - oy, 2)); + double r = this.getRadius(); double len = Math.sqrt(Math.pow(p.getx() - ox, 2) + Math.pow(p.gety() - oy, 2)); - if (Math.abs(x - o.getx()) < 0.001) { if (y > oy) p.setXY(ox, oy + r); @@ -404,6 +442,13 @@ public void SmartPonc(CPoint p) { } } + /** + * Finds the common points between two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return a vector of common points + */ public static Vector CommonPoints(Circle c1, Circle c2) { Vector vlist = new Vector(); for (int i = 0; i < c1.points.size(); i++) { @@ -416,6 +461,12 @@ public static Vector CommonPoints(Circle c1, Circle c2) { return vlist; } + /** + * Checks if the given object is tangent to the circle. + * + * @param obj the object to check + * @return true if the object is tangent to the circle, false otherwise + */ public boolean Tangent(Object obj) { if (obj instanceof CLine) { return true; @@ -434,6 +485,13 @@ public boolean Tangent(Object obj) { return false; } + /** + * Saves the circle to a PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -444,6 +502,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { this.saveSuper(fp); } + /** + * Saves the circle to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); @@ -459,10 +523,15 @@ public void Save(DataOutputStream out) throws IOException { Constraint cs = (Constraint) cons.get(i); out.writeInt(cs.id); } - - } + /** + * Loads the circle from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); @@ -483,7 +552,6 @@ else if (m_color == 7) m_dash = drawt.dash; m_width = drawt.width; - type = in.readInt(); int size = in.readInt(); m_name = new String(); @@ -520,10 +588,7 @@ else if (m_color == 7) int dx = in.readInt(); cons.add(dp.getConstraintByid(dx)); } - } - - } diff --git a/src/main/java/wprover/ColorButtonPanel.java b/src/main/java/wprover/ColorButtonPanel.java index 8a792175..998e94bd 100644 --- a/src/main/java/wprover/ColorButtonPanel.java +++ b/src/main/java/wprover/ColorButtonPanel.java @@ -6,16 +6,19 @@ import java.awt.event.MouseListener; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-9 - * Time: 9:36:35 - * To change this template use File | Settings | File Templates. + * ColorButtonPanel is a JPanel that displays a color button. When the button is clicked, + * it opens a color menu to allow the user to select a color. */ public class ColorButtonPanel extends JPanel implements MouseListener { private ColorMenu cm = new ColorMenu("color"); + /** + * Constructs a ColorButtonPanel with specified dimensions. + * + * @param x the width of the panel + * @param y the height of the panel + */ public ColorButtonPanel(int x, int y) { this.setBorder(BorderFactory.createLineBorder(Color.black, 1)); @@ -28,11 +31,21 @@ public ColorButtonPanel(int x, int y) this.addMouseListener(this); } + /** + * Returns the ColorMenu associated with this panel. + * + * @return the ColorMenu + */ public ColorMenu getColorMenu() { return cm; } + /** + * Invoked when the mouse button has been clicked (pressed and released) on a component. + * + * @param e the event to be processed + */ public void mouseClicked(MouseEvent e) { int x = e.getX(); @@ -42,26 +55,51 @@ public void mouseClicked(MouseEvent e) cm.show(this, x, y); } + /** + * Invoked when a mouse button has been pressed on a component. + * + * @param e the event to be processed + */ public void mousePressed(MouseEvent e) { } + /** + * Invoked when a mouse button has been released on a component. + * + * @param e the event to be processed + */ public void mouseReleased(MouseEvent e) { } + /** + * Invoked when the mouse enters a component. + * + * @param e the event to be processed + */ public void mouseEntered(MouseEvent e) { } + /** + * Invoked when the mouse exits a component. + * + * @param e the event to be processed + */ public void mouseExited(MouseEvent e) { } + /** + * Sets the background color of the panel to the selected color from the ColorMenu. + * + * @return the new color if the color pane is not null, otherwise null + */ public Color setNewColor() { if (cm.colorPane != null) diff --git a/src/main/java/wprover/ColorComboRender.java b/src/main/java/wprover/ColorComboRender.java index b39d85e6..21efc06e 100644 --- a/src/main/java/wprover/ColorComboRender.java +++ b/src/main/java/wprover/ColorComboRender.java @@ -21,6 +21,13 @@ class ColorComboRender extends JPanel int index = 0; boolean select = false; + /** + * Constructs a ColorComboRender with specified type and dimensions. + * + * @param type the type of the renderer (0 for color, 1 for line width, 2 for line type) + * @param w the width of the renderer + * @param h the height of the renderer + */ public ColorComboRender(int type, int w, int h) { setOpaque(true); this.type = type; @@ -29,6 +36,16 @@ public ColorComboRender(int type, int w, int h) { height = h; } + /** + * Returns the component used for drawing the cell in the list. + * + * @param list the JList we're painting + * @param value the value returned by list.getModel().getElementAt(index) + * @param index the cell's index + * @param isSelected true if the specified cell was selected + * @param cellHasFocus true if the specified cell has the focus + * @return the component that the renderer uses to draw the value + */ public Component getListCellRendererComponent(JList list, Object value, int index, @@ -50,7 +67,11 @@ public Component getListCellRendererComponent(JList list, this.index = selectedIndex; return this; } - + /** + * Paints the component. + * + * @param g the Graphics object to protect + */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; if (select) @@ -116,12 +137,21 @@ public void paintComponent(Graphics g) { } + /** + * Returns the component used for drawing the cell in the table. + * + * @param table the JTable we're painting + * @param value the value returned by table.getValueAt(row, column) + * @param isSelected true if the specified cell was selected + * @param hasFocus true if the specified cell has the focus + * @param row the row of the cell to render + * @param column the column of the cell to render + * @return the component that the renderer uses to draw the value + */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { select = isSelected; return this; } - - } \ No newline at end of file diff --git a/src/main/java/wprover/ColorMenu.java b/src/main/java/wprover/ColorMenu.java index b9580f47..6225995f 100644 --- a/src/main/java/wprover/ColorMenu.java +++ b/src/main/java/wprover/ColorMenu.java @@ -24,7 +24,7 @@ public ColorMenu(String name) super(name); unselectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, getBackground()), new BevelBorder(BevelBorder.LOWERED, - Color.white, Color.gray)); + Color.white, Color.gray)); selectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, Color.red), new MatteBorder(1, 1, 1, 1, getBackground())); activeBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, @@ -52,7 +52,11 @@ public ColorMenu(String name) } add(p); } - + /** + * Sets the selected color in the ColorMenu. + * + * @param c the color to be selected + */ public void setColor(Color c) { Object obj = paneTable.get(c); @@ -64,6 +68,11 @@ public void setColor(Color c) colorPane.setSelected(true); } +/** + * Gets the currently selected color in the ColorMenu. + * + * @return the selected color, or null if no color is selected + */ public Color getColor() { if (colorPane == null) @@ -71,10 +80,16 @@ public Color getColor() return colorPane.getColor(); } + /** + * Performs the selection action. This method is intended to be overridden. + */ public void doSelection() { } + /** + * Hides the ColorMenu. + */ public void HideMenu() { this.setVisible(false); @@ -86,37 +101,68 @@ class ColorPane extends JPanel implements MouseListener protected boolean isSelected; +/** + * Constructs a ColorPane with the specified color. + * Sets the background color, border, tooltip text, and registers a MouseListener. + * + * @param c the color of the pane + */ public ColorPane(Color c) { color = c; setBackground(c); setBorder(unselectedBorder); - String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " - + c.getBlue(); + String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " + c.getBlue(); setToolTipText(msg); addMouseListener(this); } + /** + * Returns the color of the pane. + * + * @return the color of the pane + */ public Color getColor() { return color; } + /** + * Returns the preferred size of the pane. + * + * @return the preferred size of the pane + */ public Dimension getPreferredSize() { return new Dimension(25, 25); } + /** + * Returns the maximum size of the pane. + * + * @return the maximum size of the pane + */ public Dimension getMaximumSize() { return getPreferredSize(); } + /** + * Returns the minimum size of the pane. + * + * @return the minimum size of the pane + */ public Dimension getMinimumSize() { return getPreferredSize(); } + /** + * Sets the selection state of the pane. + * Updates the border based on the selection state. + * + * @param selected the selection state to set + */ public void setSelected(boolean selected) { isSelected = selected; @@ -126,19 +172,40 @@ public void setSelected(boolean selected) setBorder(unselectedBorder); } + /** + * Returns whether the pane is selected. + * + * @return true if the pane is selected, false otherwise + */ public boolean isSelected() { return isSelected; } + /** + * Invoked when a mouse button has been pressed on the pane. + * + * @param e the MouseEvent triggered by the press + */ public void mousePressed(MouseEvent e) { } + /** + * Invoked when the mouse has been clicked on the pane. + * + * @param e the MouseEvent triggered by the click + */ public void mouseClicked(MouseEvent e) { } + /** + * Invoked when a mouse button has been released on the pane. + * Sets the color, clears the selected path, performs the selection action, and hides the menu. + * + * @param e the MouseEvent triggered by the release + */ public void mouseReleased(MouseEvent e) { setColor(color); @@ -147,11 +214,23 @@ public void mouseReleased(MouseEvent e) HideMenu(); } + /** + * Invoked when the mouse enters the pane. + * Sets the border to the active border. + * + * @param e the MouseEvent triggered when entering the pane + */ public void mouseEntered(MouseEvent e) { setBorder(activeBorder); } + /** + * Invoked when the mouse exits the pane. + * Sets the border based on the selection state. + * + * @param e the MouseEvent triggered when exiting the pane + */ public void mouseExited(MouseEvent e) { setBorder(isSelected ? selectedBorder : unselectedBorder); diff --git a/src/main/java/wprover/ConcDialog.java b/src/main/java/wprover/ConcDialog.java index 99294ccd..a4f2ca03 100644 --- a/src/main/java/wprover/ConcDialog.java +++ b/src/main/java/wprover/ConcDialog.java @@ -7,6 +7,10 @@ import java.awt.*; import java.awt.event.*; +/** + * ConcDialog is a dialog for selecting geometric conclusions. + * It allows the user to select points and check geometric properties. + */ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListener { int type = 0; // 0. Conclusion 1. NDGS. final static String[] ts = { @@ -31,7 +35,7 @@ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListe "Special Angle", "Angles Equation", "Segment Equation" - };//CST.s_conc_detail; + }; final public static int CONCLUSION_OK = 0; @@ -53,15 +57,30 @@ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListe private condPane Pane2; + /** + * Sets the type of the dialog. + * + * @param t the type to set + */ public void setType(int t) { this.type = t; } + /** + * Changes the action listener for the OK button. + * + * @param ls the new ActionListener to set + */ public void changeBOKListener(ActionListener ls) { bok.removeActionListener(this); bok.addActionListener(ls); } + /** + * Sets the conclusion in the dialog. + * + * @param c the conclusion to set + */ public void setCns(Cons c) { if (c == null) return; @@ -75,6 +94,12 @@ public void setCns(Cons c) { } } + /** + * Constructs a ConcDialog with the specified GExpert instance and title. + * + * @param gx the GExpert instance + * @param title the title of the dialog + */ public ConcDialog(GExpert gx, String title) { super(gx.getFrame(), title); this.setTitle(title); @@ -83,9 +108,13 @@ public ConcDialog(GExpert gx, String title) { init(); this.setPoints(gx.dp.getPointList()); this.setModal(false); - } + /** + * Sets the value of ltext1 based on the given type. + * + * @param t the type to set + */ private void setLtext1Value(int t) { if (model) return; @@ -104,16 +133,10 @@ private void setLtext1Value(int t) { } } - public ConcDialog(GExpert frame) { - super(frame.getFrame(), "Add Conclusion"); - this.setModal(false); - model = false; - init(); - } - + /** + * Initializes the dialog components. + */ private void init() { - - JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); @@ -124,7 +147,6 @@ private void init() { ic2 = GExpert.createImageIcon("images/ptree/cross.gif"); ic3 = GExpert.createImageIcon("images/ptree/question.gif"); - int len = ts.length; String[] ss = new String[len]; for (int i = 0; i < len; i++) @@ -188,7 +210,6 @@ public Dimension getMaximumSize() { Pane1.add(textPane); cardPane.add(Pane1, "1"); - JPanel bottomPane = new JPanel(); bottomPane.setLayout(new BoxLayout(bottomPane, BoxLayout.X_AXIS)); @@ -205,7 +226,6 @@ public Dimension getMaximumSize() { bclear.setActionCommand("Clear"); bcancel.setActionCommand("Cancel"); - contentPane.add(cardPane); contentPane.add(bottomPane); this.add(contentPane); @@ -221,6 +241,11 @@ public void windowClosing(WindowEvent e) { this.resetAllItem(); } + /** + * Sets the points in the combo boxes. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -242,6 +267,11 @@ public void setPoints(Vector v) { Pane2.setPoints(v); } + /** + * Returns the number of points left to be selected. + * + * @return the number of points left to be selected + */ private int ptLeftTobeSelect() { int n = 0; @@ -260,6 +290,11 @@ private int ptLeftTobeSelect() { return n; } + /** + * Handles item state changes for the combo boxes. + * + * @param e the ItemEvent triggered by the user + */ public void itemStateChanged(ItemEvent e) { if (!this.isVisible()) return; Object source = e.getSource(); @@ -306,19 +341,23 @@ public void itemStateChanged(ItemEvent e) { } } + /** + * Checks if the input is finished. + * + * @return true if the input is finished, false otherwise + */ private boolean inputFinished() { return 0 == ptLeftTobeSelect(); } - private void showTipText() { - - } - + /** + * Selects a point in the combo boxes. + * + * @param p the point to select + */ public void selectAPoint(CPoint p) { - Pane2.selectAPoint(p); - for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -333,9 +372,11 @@ public void selectAPoint(CPoint p) { return; } } - } + /** + * Resets all combo boxes and labels. + */ private void resetAllItem() { bok.setEnabled(false); ltext1.setIcon(ic3); @@ -344,7 +385,6 @@ private void resetAllItem() { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); b.setSelectedIndex(-1); - } for (int i = 0; i < vlist1.size(); i++) { JComboBox b = (JComboBox) vlist1.get(i); @@ -352,9 +392,13 @@ private void resetAllItem() { } bx1.setSelectedIndex(0); bx2.setSelectedIndex(0); - } + /** + * Returns the number of points required for the selected item. + * + * @return the number of points required + */ private int getStatePointsCount() { switch (bt.getSelectedIndex()) { case 0: @@ -369,7 +413,6 @@ private int getStatePointsCount() { case 5: case 11: case 13: - return 4; case 7: case 8: @@ -382,6 +425,11 @@ private int getStatePointsCount() { return -1; } + /** + * Updates the visibility of combo boxes based on the selected item ID. + * + * @param id the ID of the selected item + */ private void setItemChanged(int id) { switch (id) { case 0: @@ -398,7 +446,6 @@ private void setItemChanged(int id) { case 5: case 11: case 13: - this.setVisibleBox1(4); break; case 7: @@ -409,7 +456,6 @@ private void setItemChanged(int id) { case 12: this.setVisibleBox1(8); break; - } if (id == 13) { setRatioVisible(); @@ -423,16 +469,22 @@ private void setItemChanged(int id) { } } + /** + * Sets the angles in the combo box for special angles. + */ public void setSAngle() { bx1.removeAllItems(); int[] angles = {0, 15, 30, 36, 45, 72, 75, 90, 120, 135, 150, 180}; - for (int i: angles) { + for (int i : angles) { bx1.addItem(i); } bx1.setVisible(true); bx2.setVisible(false); } + /** + * Sets the ratio values in the combo boxes. + */ public void setRatioVisible() { bx1.removeAllItems(); bx2.removeAllItems(); @@ -445,6 +497,11 @@ public void setRatioVisible() { bx2.setVisible(true); } + /** + * Handles action events for the buttons. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equalsIgnoreCase("OK")) { @@ -455,7 +512,6 @@ public void actionPerformed(ActionEvent e) { gxInstance.getpprove().set_conclusion(getProve(), this.checkValid()); else gxInstance.getpprove().add_ndgs(getProve()); - } else if (command.equalsIgnoreCase("Cancel")) { returnValue = CONCLUSION_CANCEL; this.setVisible(false); @@ -465,6 +521,12 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Displays the dialog and returns the result. + * + * @param s the string to select in the combo box + * @return the return value indicating the result of the dialog + */ public int showDialog(String s) { if (model == false) this.setPoints(gxInstance.dp.getPointList()); @@ -478,11 +540,14 @@ public int showDialog(String s) { bt.setSelectedItem(s); ltext.setText(""); return returnValue; - } + /** + * Sets the visibility of the first set of combo boxes based on the number of items. + * + * @param num the number of items to be visible + */ private void setVisibleBox1(int num) { - int k = num / 2; for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -500,6 +565,11 @@ private void setVisibleBox1(int num) { } } + /** + * Sets the visibility of the second set of combo boxes based on the number of items. + * + * @param num the number of items to be visible + */ private void setVisibleBox(int num) { for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -514,13 +584,13 @@ private void setVisibleBox(int num) { } } - private String vs(int id1, int id2) { - if (id1 == 0) - return ((JComboBox) vlist.get(id2)).getSelectedItem().toString(); - else - return ((JComboBox) vlist1.get(id2)).getSelectedItem().toString(); - } - + /** + * Returns the selected point from the combo boxes. + * + * @param id1 the ID of the combo box set (0 or 1) + * @param id2 the index of the combo box within the set + * @return the selected point + */ private CPoint vspt(int id1, int id2) { if (id1 == 0) { return (CPoint) ((JComboBox) vlist.get(id2)).getSelectedItem(); @@ -528,34 +598,23 @@ private CPoint vspt(int id1, int id2) { return (CPoint) ((JComboBox) vlist1.get(id2)).getSelectedItem(); } } -// "Collinear", -// "Parallel", -// "Perpendicular", -// "Midpoint", -// "Cyclic", -// "Equal Distance", -// "Equal Angle", -// -// "Similiar Triangle", -// "Congruent Triangle", -// "Equalateral Triangle", -// -// "Bisect", -// "Tangent", -// -// "Equal Product", -// "Ratio", -// -// "Special Angle", -// "Angles Equation", -// "Segment Equation" + /** + * Checks if the selected item is valid. + * + * @return true if the selected item is valid, false otherwise + */ public boolean checkValid() { int id = bt.getSelectedIndex(); return checkValid(id); - } + /** + * Checks if the selected item with the given ID is valid. + * + * @param id the ID of the selected item + * @return true if the selected item is valid, false otherwise + */ public boolean checkValid(int id) { switch (id) { case 0: // COLLINEAR @@ -572,12 +631,10 @@ public boolean checkValid(int id) { return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case 6: return DrawBase.check_eqangle(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(0, 3), vspt(1, 0), vspt(1, 1), vspt(1, 2), vspt(1, 3)); - case 7: //Similiar Triangle return DrawBase.check_simtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 8: //Congruent Triangle return DrawBase.check_congtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 9: //Equilateral Triangle return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(0, 1), vspt(0, 2)) && DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(0, 0), vspt(0, 2)); @@ -585,7 +642,6 @@ public boolean checkValid(int id) { return DrawBase.check_bisect(vspt(0, 0), vspt(0, 1), vspt(0, 2)); case 11: //Tangent return DrawBase.check_perp(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(0, 1)); - case 12: { //Eq_product double d1 = DrawBase.sdistance(vspt(0, 0), vspt(0, 1)); double d2 = DrawBase.sdistance(vspt(0, 2), vspt(0, 3)); @@ -598,12 +654,16 @@ public boolean checkValid(int id) { int t2 = getRatioValue(2); return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1), t1, t2); } - } return false; } - + /** + * Returns the ratio value from the combo box. + * + * @param id the ID of the combo box (1 or 2) + * @return the ratio value + */ private int getRatioValue(int id) { if (id == 1) { String s1 = bx1.getSelectedItem().toString(); @@ -616,25 +676,11 @@ private int getRatioValue(int id) { } } - public MAssertion getProveM() { - int id = bt.getSelectedIndex(); - if (id < 0) return null; - MAssertion ass = new MAssertion(id); - for (int i = 0; i < vlist.size(); i++) { - JComboBox b = (JComboBox) vlist.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - for (int i = 0; i < vlist1.size(); i++) { - JComboBox b = (JComboBox) vlist1.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - return ass; - } - + /** + * Returns the conclusion based on the selected points and type. + * + * @return the conclusion object + */ public Cons getProve() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return null; @@ -690,14 +736,6 @@ public Cons getProve() { return c; } - public String getSpecialAngle() { - Object o = bx1.getSelectedItem(); - if (o != null) - return o.toString(); - else - return null; - } - class condPane extends JPanel implements ActionListener { JComboBox[] bx = new JComboBox[3]; @@ -709,6 +747,10 @@ class condPane extends JPanel implements ActionListener { JPopupMenu mint; + /** + * Constructs a condPane object. + * Initializes the layout, buttons, combo boxes, and other components. + */ public condPane() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); field.setFont(font); @@ -757,6 +799,9 @@ public condPane() { field.setFocusable(true); } + /** + * Clears the text field and resets the combo boxes. + */ public void clear() { field.setText(""); bx[0].setSelectedIndex(-1); @@ -767,6 +812,12 @@ public void clear() { ltext1.setText(""); } + /** + * Sets the status of the condPane. + * Updates the visibility and enabled state of the combo boxes based on the status. + * + * @param s the status to set (0 for segment, 1 for angle) + */ public void setStatus(int s) { if (s == 0) { bx[2].setVisible(false); @@ -783,13 +834,16 @@ public void setStatus(int s) { bx[2].setSelectedIndex(-1); } + /** + * Handles action events for the buttons and menu items. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (o == b3) { - { - addPtsText1(); - addText(" * "); - } + addPtsText1(); + addText(" * "); } else if (o == b1) { addPtsText1(); addText(" + "); @@ -799,9 +853,9 @@ public void actionPerformed(ActionEvent e) { } else if (o == b4) { addPtsText1(); addText(" = "); - } else if (o == b5) + } else if (o == b5) { mint.show(b5, 0, b5.getHeight()); - else if (o == badd) { + } else if (o == badd) { addText(getPts()); } else { String s = e.getActionCommand(); @@ -809,17 +863,30 @@ else if (o == badd) { } } + /** + * Adds the selected points text to the field if the add button is enabled. + */ public void addPtsText1() { if (!badd.isEnabled()) return; addText(getPts()); } + /** + * Appends the specified text to the field and unselects the combo boxes. + * + * @param s the text to add + */ public void addText(String s) { field.setText(field.getText() + s); unselect(); } + /** + * Sets the points in the combo boxes. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < 3; i++) { bx[i].removeAllItems(); @@ -831,6 +898,11 @@ public void setPoints(Vector v) { } } + /** + * Selects a point in the combo boxes. + * + * @param o the point to select + */ public void selectAPoint(Object o) { boolean set = false; for (int i = 0; i < 3; i++) { @@ -839,13 +911,17 @@ public void selectAPoint(Object o) { if (set == false) { bx[i].setSelectedItem(o); set = true; - } else + } else { return; + } } } badd.setEnabled(true); } + /** + * Unselects all combo boxes and disables the add button. + */ public void unselect() { for (int i = 0; i < 3; i++) { bx[i].setSelectedIndex(-1); @@ -853,18 +929,11 @@ public void unselect() { badd.setEnabled(false); } - public void getSelected(Vector v) { - for (int i = 0; i < 3 && bx[i].isEnabled(); i++) { - Object obj = bx[i].getSelectedItem(); - if (obj != null) - v.add(obj); - else { - v.clear(); - return; - } - } - } - + /** + * Returns the selected points as a string. + * + * @return the selected points + */ public String getPts() { String s = ""; for (int i = 0; i < 3 && bx[i].isEnabled(); i++) { @@ -874,6 +943,11 @@ public String getPts() { return s; } + /** + * Returns the value of the text field. + * + * @return the value of the text field + */ public String getValue() { return field.getText(); } diff --git a/src/main/java/wprover/ConcPanel.java b/src/main/java/wprover/ConcPanel.java index 5da06604..a82587a0 100644 --- a/src/main/java/wprover/ConcPanel.java +++ b/src/main/java/wprover/ConcPanel.java @@ -8,11 +8,8 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-7-5 - * Time: 13:25:43 - * To change this template use File | Settings | File Templates. + * ConcPanel is a JPanel that provides a user interface for selecting geometric assertions. + * It allows users to select points and check the validity of assertions based on the selected points. */ public class ConcPanel extends JPanel implements ActionListener, ItemListener { @@ -34,20 +31,35 @@ public class ConcPanel extends JPanel implements ActionListener, ItemListener { private MProveInputPanel ipanel = null; + /** + * Constructs a ConcPanel with the specified GExpert instance. + * Initializes the panel and sets the selected index of the combo box to -1. + * + * @param gx the GExpert instance + */ public ConcPanel(GExpert gx) { gxInstance = gx; init(); bt.setSelectedIndex(-1); } + /** + * Constructs a ConcPanel with the specified GExpert instance and MProveInputPanel. + * Calls the other constructor and sets the input panel. + * + * @param gx the GExpert instance + * @param ipanel the MProveInputPanel instance + */ public ConcPanel(GExpert gx, MProveInputPanel ipanel) { this(gx); this.ipanel = ipanel; } - + /** + * Initializes the ConcPanel. + * Sets up the layout, combo boxes, panels, and other components. + */ private void init() { - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); @@ -127,11 +139,22 @@ public Dimension getMaximumSize() { ass_show = new MAssertion(0); } + /** + * Sets the selected index of the combo box and revalidates the state. + * + * @param k the index to set + */ public void setTypeSelection(int k) { bt.setSelectedIndex(k); this.revalidateValidState(); } + /** + * Sets the user object for the panel. + * Resets all items and updates the combo box and points based on the provided assertion. + * + * @param as the MAssertion object to set + */ public void setUserObject(MAssertion as) { this.resetAllItem(); ass = as; @@ -143,10 +166,14 @@ public void setUserObject(MAssertion as) { } else { bt.setSelectedIndex(-1); } - - } + /** + * Returns the user object for the panel. + * Creates or updates the assertion object based on the selected points. + * + * @return the MObject representing the assertion + */ public MObject getUserObject() { if (ass == null) ass = new MAssertion(bt.getSelectedIndex()); @@ -170,10 +197,18 @@ public MObject getUserObject() { return ass; } + /** + * Updates the points in the panel based on the current point list from the GExpert instance. + */ public void update() { this.setPoints(gxInstance.dp.getPointList()); } + /** + * Sets the value of the ltext1 label based on the given boolean. + * + * @param t the boolean value to set + */ private void setLtext1Value(boolean t) { if (t) { ltext1.setText(""); @@ -184,11 +219,11 @@ private void setLtext1Value(boolean t) { } } - public int getPointsCount() { - JComboBox b = (JComboBox) vlist.get(0); - return b.getItemCount(); - } - + /** + * Sets the points in the combo boxes based on the provided vector of points. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -208,6 +243,11 @@ public void setPoints(Vector v) { } } + /** + * Returns the number of points left to be selected. + * + * @return the number of points left to be selected + */ private int ptLeftTobeSelect() { int n = this.getStatePointsCount(); @@ -226,6 +266,10 @@ private int ptLeftTobeSelect() { return n; } + /** + * Revalidates the state of the panel based on the current input. + * Checks if the input is finished and updates the validity state and combo box accordingly. + */ public void revalidateValidState() { if (inputFinished()) { boolean v = checkValid(); @@ -239,6 +283,12 @@ public void revalidateValidState() { ltext1.setIcon(icon_Question); } + /** + * Handles item state changes for the combo boxes. + * Resets all items, updates the combo box and points, and revalidates the state. + * + * @param e the ItemEvent triggered by the user + */ public void itemStateChanged(ItemEvent e) { if (!this.isVisible()) return; @@ -265,9 +315,13 @@ public void itemStateChanged(ItemEvent e) { ltext1.setIcon(icon_Question); updateBState(); - } + /** + * Updates the state of the button in the input panel based on the current selection. + * If the input panel is not null and the input is finished or the selected index is CONVEX, + * it sets the button state to true, otherwise sets it to false. + */ public void updateBState() { if (ipanel != null) { if (inputFinished() || bt.getSelectedIndex() == MAssertion.CONVEX) @@ -277,6 +331,12 @@ public void updateBState() { } } + /** + * Creates an assertion based on the selected points. + * Initializes or updates the assertion object and adds selected points to it. + * + * @return true if the assertion is valid, false otherwise + */ private boolean createAssertion() { if (ass_show == null) ass_show = new MAssertion(bt.getSelectedIndex()); @@ -296,8 +356,12 @@ private boolean createAssertion() { return ass_show.checkValid(); } + /** + * Checks if the input is finished by verifying that all enabled combo boxes have a selected item. + * + * @return true if the input is finished, false otherwise + */ private boolean inputFinished() { -// return 0 == ptLeftTobeSelect(); for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -313,6 +377,10 @@ private boolean inputFinished() { return true; } + /** + * Displays a tip text indicating the number of points left to be selected. + * Updates the assertion panel with the appropriate message. + */ private void showTipText() { int n = ptLeftTobeSelect(); @@ -326,8 +394,13 @@ private void showTipText() { } } + /** + * Selects a point in the combo boxes. + * Sets the selected item in the first available enabled combo box. + * + * @param p the point to select + */ public void selectAPoint(CPoint p) { - for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -343,9 +416,11 @@ public void selectAPoint(CPoint p) { } } asspane.repaint(); -// this.repaint(); } + /** + * Resets all combo boxes by setting their selected index to -1. + */ private void resetAllItem() { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -355,9 +430,13 @@ private void resetAllItem() { JComboBox b = (JComboBox) vlist1.get(i); b.setSelectedIndex(-1); } - } + /** + * Returns the number of points required for the selected assertion type. + * + * @return the number of points required + */ private int getStatePointsCount() { switch (bt.getSelectedIndex()) { case MAssertion.COLL: @@ -386,6 +465,11 @@ private int getStatePointsCount() { return -1; } + /** + * Sets the visibility and enabled state of the combo boxes based on the selected assertion type. + * + * @param id the selected assertion type + */ private void setItemChanged(int id) { switch (id) { case MAssertion.COLL: @@ -423,7 +507,6 @@ private void setItemChanged(int id) { case MAssertion.ANGLE_INSIDE: case MAssertion.ANGLE_OUTSIDE: case MAssertion.TRIANGLE_INSIDE: - this.setVisibleBox2(3); break; case MAssertion.BETWEEN: @@ -438,10 +521,15 @@ private void setItemChanged(int id) { default: CMisc.print("massertion " + id + " not found"); break; - } } + /** + * Handles action events for the buttons. + * Resets all items and updates the assertion based on the temporary assertion. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); Object obj = e.getSource(); @@ -458,9 +546,13 @@ public void actionPerformed(ActionEvent e) { } else { } bpanel.setVisible(false); - } + /** + * Sets the visibility and enabled state of the combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox2(int num) { int k = 1; for (int i = 0; i < vlist.size(); i++) { @@ -486,9 +578,13 @@ private void setVisibleBox2(int num) { obj.setVisible(false); } } - } +/** + * Sets the visibility and enabled state of the first set of combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox1(int num) { int k = num / 2; for (int i = 0; i < vlist.size(); i++) { @@ -513,6 +609,11 @@ private void setVisibleBox1(int num) { } } + /** + * Sets the visibility and enabled state of the combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox(int num) { for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -531,6 +632,13 @@ private void setVisibleBox(int num) { } } + /** + * Returns the selected item from the specified combo box as a string. + * + * @param id1 the index of the combo box list (0 for vlist, 1 for vlist1) + * @param id2 the index of the combo box within the list + * @return the selected item as a string, or an empty string if the index is out of bounds + */ private String vs(int id1, int id2) { if (id1 == 0) { JComboBox box = ((JComboBox) vlist.get(id2)); @@ -556,9 +664,15 @@ private String vs(int id1, int id2) { return obj.toString(); } } - } + /** + * Returns the selected item from the specified combo box as a CPoint. + * + * @param id1 the index of the combo box list (0 for vlist, 1 for vlist1) + * @param id2 the index of the combo box within the list + * @return the selected item as a CPoint, or null if the index is out of bounds + */ private CPoint vspt(int id1, int id2) { if (id1 == 0) { JComboBox box = ((JComboBox) vlist.get(id2)); @@ -585,6 +699,11 @@ private CPoint vspt(int id1, int id2) { } } + /** + * Checks the validity of the selected geometric assertion based on the selected points. + * + * @return true if the assertion is valid, false otherwise + */ private boolean checkValid() { int id = bt.getSelectedIndex(); if (!inputFinished()) return false; @@ -605,16 +724,14 @@ private boolean checkValid() { return DrawBase.check_eqangle(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 7: return DrawBase.check_congtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 8: return DrawBase.check_simtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 9: return DrawBase.check_distance_less(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case 10: return DrawBase.check_angle_less(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 11: -// return drawbase.check_concurrent(); + // return drawbase.check_concurrent(); case 12: return DrawBase.check_perp(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(0, 1)); case 13: @@ -644,7 +761,6 @@ private boolean checkValid() { case MAssertion.ANGLE_INSIDE: return DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)) && DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case MAssertion.ANGLE_OUTSIDE: return !(DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)) && DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2))); @@ -653,38 +769,21 @@ private boolean checkValid() { case MAssertion.PARA_INSIDE: return DrawBase.check_triangle_inside(vspt(0, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2)) || DrawBase.check_triangle_inside(vspt(0, 0), vspt(1, 0), vspt(1, 2), vspt(1, 3)); - case MAssertion.OPPOSITE_SIDE: return !DrawBase.check_same_side(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case MAssertion.SAME_SIDE: return DrawBase.check_same_side(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case MAssertion.CONVEX: return true; - } return true; } - - public MAssertion getProveM() { - int id = bt.getSelectedIndex(); - if (id < 0) return null; - MAssertion ass = new MAssertion(id); - for (int i = 0; i < vlist.size(); i++) { - JComboBox b = (JComboBox) vlist.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - for (int i = 0; i < vlist1.size(); i++) { - JComboBox b = (JComboBox) vlist1.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - return ass; - } - + /** + * Returns the proof statement for the selected geometric assertion. + * + * @return the proof statement as a string, or "Not Yet Supported Conclusion" if the assertion type is not supported + */ public String getProve() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return ""; @@ -715,37 +814,9 @@ public String getProve() { return "Not Yet Supported Conclusion"; } - public String getProveDescription() { - JComboBox box1 = (JComboBox) vlist.get(0); - if (box1.getItemCount() == 0) return ""; - if (!this.inputFinished()) return ""; - - int id = bt.getSelectedIndex(); - - switch (id) { - case MAssertion.COLL: - return vs(0, 0) + " " + vs(0, 1) + " " + vs(0, 2) + " are collinear;"; - case MAssertion.PARA: - return vs(0, 0) + " " + vs(0, 1) + " is Parallel to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.PERP: - return vs(0, 0) + " " + vs(0, 1) + " is Perpendicular to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.MID: - return vs(0, 0) + " is the midpoint of " + vs(0, 1) + " " + vs(0, 2) + ";"; - case MAssertion.CYCLIC: - return vs(0, 0) + " " + vs(0, 1) + " " + vs(0, 2) + " " + vs(0, 3) + " are cyclic;"; - case MAssertion.EQDIS: - return vs(0, 0) + " " + vs(0, 1) + " equals to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.EQANGLE: - return Cm.ANGLE_SIGN + vs(0, 0) + vs(0, 1) + vs(0, 2) + " = " + Cm.ANGLE_SIGN + vs(1, 0) + vs(1, 1) + vs(1, 2); - - case MAssertion.SIM: - return "tri " + vs(0, 0) + vs(0, 1) + vs(0, 2) + " is similiar to " + "tri " + vs(1, 0) + vs(1, 1) + vs(1, 2); - case MAssertion.CONG: - return "tri " + vs(0, 0) + vs(0, 1) + vs(0, 2) + " is equal to " + "tri " + vs(1, 0) + vs(1, 1) + vs(1, 2); - } - return "Not Yet Supported Conclusion"; - } - + /** + * Shows the correct order of points for the selected geometric assertion. + */ private void showCorrentOrder() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return; @@ -789,10 +860,11 @@ else if (id == MAssertion.CONG) bpanel.setVisible(true); } } - - } + /** + * Cancels the current assertion and resets all combo boxes. + */ public void cancel() { ass = null; this.resetAllItem(); diff --git a/src/main/java/wprover/Constraint.java b/src/main/java/wprover/Constraint.java index 3b3fe328..7c1880f4 100644 --- a/src/main/java/wprover/Constraint.java +++ b/src/main/java/wprover/Constraint.java @@ -12,7 +12,11 @@ import maths.Param; import maths.TMono; - +/** + * The Constraint class represents a geometric constraint in a geometric construction. + * It contains methods to generate and manipulate constraints, as well as to calculate + * polynomial representations of the constraints. + */ public class Constraint { final public static int NULLTYPE = 0; final public static int PONLINE = 11; // collinear @@ -114,6 +118,11 @@ public class Constraint { Cons csd = null; Cons csd1 = null; + /** + * Retrieves the polynomial list and sets it to null. + * + * @return the current polynomial list + */ public static TPoly getPolyListAndSetNull() { TPoly pl = polylist; polylist = null; @@ -125,10 +134,21 @@ public static TPoly getPolyListAndSetNull() { return pl; } + /** + * Gets the type of the constraint. + * + * @return the type of the constraint + */ public int GetConstraintType() { return this.ConstraintType; } + /** + * Retrieves an element from the element list at the specified index. + * + * @param i the index of the element to retrieve + * @return the element at the specified index, or null if the index is out of bounds + */ public Object getelement(int i) { if (i >= 0 && i < elementlist.size()) return elementlist.get(i); @@ -136,35 +156,45 @@ public Object getelement(int i) { return null; } - public CPoint getLPoints2(CPoint p1, CPoint p2) { - for (int i = 0; i < elementlist.size(); i++) { - CPoint p = (CPoint) elementlist.get(i); - if (p != p1 && p != p2) - return p; - } - return null; - } - - public boolean cotainPoints(CPoint p1, CPoint p2) { - return elementlist.contains(p1) && elementlist.contains(p2); - } - + /** + * Retrieves all elements in the element list. + * + * @return a vector containing all elements in the element list + */ public Vector getAllElements() { Vector v = new Vector(); v.addAll(elementlist); return v; } + /** + * Constructs a Constraint with the specified ID. + * + * @param id the ID of the constraint + */ public Constraint(int id) { this.id = id; } + /** + * Calculates the polynomial representation using the given parameters. + * + * @param para an array of parameters to use for the calculation + */ public void calculate(Param[] para) { if (polylist == null) return; poly.calculv(polylist.getPoly(), para); is_poly_genereate = false; } +/** + * Constructs a Constraint with two elements and optionally generates the polynomial. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param gpoly true if the polynomial should be generated, false otherwise + */ public Constraint(int type, Object obj1, Object obj2, boolean gpoly) { this.ConstraintType = type; elementlist.add(obj1); @@ -175,19 +205,37 @@ public Constraint(int type, Object obj1, Object obj2, boolean gpoly) { } } + /** + * Constructs a Constraint with a list of elements and generates the polynomial. + * + * @param type the type of the constraint + * @param olist a vector containing the elements + */ public Constraint(int type, Vector olist) { this.ConstraintType = type; elementlist.addAll(olist); PolyGenerate(); } + /** + * Constructs a Constraint with a single element. + * + * @param type the type of the constraint + * @param obj the element + */ public Constraint(int type, Object obj) { this.ConstraintType = type; elementlist.add(obj); } - public Constraint(int type, Object obj1, Object obj2)// - { + /** + * Constructs a Constraint with two elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + */ + public Constraint(int type, Object obj1, Object obj2) { this.ConstraintType = type; elementlist.add(obj1); elementlist.add(obj2); @@ -203,6 +251,15 @@ else if (type == PERPENDICULAR) { } } + /** + * Constructs a Constraint with three elements and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param prop the proportion + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, int prop) { this.ConstraintType = type; elementlist.add(obj1); @@ -211,18 +268,33 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, int prop) { this.proportion = prop; if (is_poly_genereate) PolyGenerate(); - } + /** + * Constructs a Constraint with a single element and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the element + * @param prop the proportion + */ public Constraint(int type, Object obj1, int prop) { this.ConstraintType = type; elementlist.add(obj1); this.proportion = prop; if (is_poly_genereate) PolyGenerate(); - } + /** + * Constructs a Constraint with four elements and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param prop the proportion + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, int prop) { this.ConstraintType = type; elementlist.add(obj1); @@ -234,6 +306,16 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } + /** + * Constructs a Constraint with five elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param obj5 the fifth element + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5) { this.ConstraintType = type; addelement(obj1); @@ -245,8 +327,15 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } - public Constraint(int type, Object obj1, Object obj2, Object obj3)// - { + /** + * Constructs a Constraint with three elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -255,13 +344,26 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3)// PolyGenerate(); } + /** + * Adds an element to the element list if it is not null. + * + * @param obj the element to be added + */ public void addelement(Object obj) { if (obj != null) elementlist.add(obj); } - public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4)// - { + /** + * Constructs a Constraint with four elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -271,8 +373,18 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4)/ PolyGenerate(); } - public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6)// - { + /** + * Constructs a Constraint with six elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param obj5 the fifth element + * @param obj6 the sixth element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -284,19 +396,38 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } - + /** + * Sets whether the polynomial should be generated. + * + * @param r true if the polynomial should be generated, false otherwise + */ public void setPolyGenerate(boolean r) { is_poly_genereate = r; } + /** + * Adds an element to the element list. + * + * @param obj the element to be added + */ public void addElement(Object obj) { elementlist.add(obj); } + /** + * Returns the message representation of the constraint. + * + * @return the message representation of the constraint + */ String getMessage() { return toString(); } + /** + * Returns the string representation of the constraint. + * + * @return the string representation of the constraint + */ public String toString() { if (csd != null) return csd.toDString(); @@ -352,7 +483,6 @@ else if (i == 3) case PERPBISECT: return e1.TypeString() + " is on the perpendicular bisector of " + e2.m_name + " " + e3.TypeString(); case MIRROR: - case PRATIO: return "o(" + e1.m_name + e2.m_name + ") / " + "o(" + e3.m_name + e4.m_name + ") = 1 : " + this.proportion; case LRATIO: @@ -368,24 +498,31 @@ else if (i == 3) return "set " + e1.TypeString() + e2.TypeString() + " a horizonal line"; case VERTICAL: return "set " + e1.TypeString() + e2.TypeString() + " a vertical line"; - } return new String(); } + /** + * Clears all constraints by setting the constraint descriptors to null. + */ public void clear_all_cons() { csd = null; csd1 = null; } + /** + * Generates the polynomial representation based on the constraint type. + * + * @return a TPoly object representing the generated polynomial list + */ TPoly PolyGenerate() { TMono tm = null; TPoly tp = null; switch (this.ConstraintType) { case LINE: -// this.add_des(gib.C_LINE, elementlist); + // this.add_des(gib.C_LINE, elementlist); break; case CIRCLE: this.add_des(Gib.C_CIRCLE, elementlist); @@ -423,7 +560,7 @@ TPoly PolyGenerate() { case PONLINE: // p_o_L tm = this.PolyOnLine(); break; - case PONCIRCLE: // p_o_C + case PONCIRCLE: // p_o_C tm = this.PolyOnCircle(); break; case INTER_LL: @@ -435,43 +572,42 @@ TPoly PolyGenerate() { case INTER_CC: tp = PolyIntersection_CC(); break; - case PARALLEL: // P_O_P + case PARALLEL: // P_O_P tm = this.PolyParel(); break; - case PERPENDICULAR: // p_o_T + case PERPENDICULAR: // p_o_T tm = this.PolyPerp(); break; - case PFOOT: // LT + case PFOOT: // LT tp = this.PolyPfoot(); break; - case MIDPOINT: // MID + case MIDPOINT: // MID tp = this.PolyMidPoint(); break; - case EQDISTANCE: // + case EQDISTANCE: tm = this.PolyEqidstance(); break; - case EQANGLE: // P_O_A + case EQANGLE: // P_O_A tm = this.PolyEqAngle(); break; - case COLLINEAR: // P_O_L + case COLLINEAR: // P_O_L tm = this.collinear(); break; case CCTANGENT: tm = this.PolyCCTangent(); break; - case CCLine: { - } - break; + case CCLine: + break; case TRATIO: tp = this.PolyTRatio(); break; - case PERPBISECT: // p_O_B + case PERPBISECT: // p_O_B tm = this.PolyPerpBisect(); break; case ISO_TRIANGLE: tm = PolyISOTriangle(); break; - case MIRROR: // P_REF + case MIRROR: // P_REF tp = this.PolyMirror(); break; case PRATIO: @@ -480,7 +616,7 @@ TPoly PolyGenerate() { case LRATIO: tp = this.PolyPropPoint(); break; - case CIRCUMCENTER: // P_CIR + case CIRCUMCENTER: // P_CIR tp = this.PolyCircumCenter(); break; case BARYCENTER: @@ -581,7 +717,6 @@ TPoly PolyGenerate() { case CONSTANT: tm = PolyConstant(); break; - } if (tm != null) { @@ -594,6 +729,11 @@ TPoly PolyGenerate() { return polylist; } + /** + * Adds a polynomial to the polynomial list. + * + * @param tp the polynomial to be added + */ public void addPoly(TPoly tp) { TPoly t = tp; while (t.getNext() != null) @@ -602,20 +742,11 @@ public void addPoly(TPoly tp) { polylist = tp; } - public boolean optimizePolygon(TPoly p) { - boolean a = false; - while (p != null) { - TMono m = p.getPoly(); - if (m != null && poly.plength(m) == 1) { - boolean d = poly.addZeroN(m.x); - if (d) - a = true; - } - p = p.getNext(); - } - return a; - } - + /** + * Computes the polynomial representation of a constant. + * + * @return a TMono object representing the constant + */ TMono PolyConstant() { String t1 = elementlist.get(0).toString(); String t2 = elementlist.get(1).toString(); @@ -624,6 +755,11 @@ TMono PolyConstant() { return parseTMonoString(t1, t2, p1.xindex); } + /** + * Computes the polynomial representation of points on a line. + * + * @return a TMono object representing the points on a line + */ TMono PolyONALine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -646,6 +782,11 @@ TMono PolyONALine() { } } + /** + * Computes the polynomial representation of points on a circle. + * + * @return a TMono object representing the points on a circle + */ TMono PolyONRCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -656,6 +797,11 @@ TMono PolyONRCircle() { p4.x1.xindex, p4.y1.xindex, p3.x1.xindex, p3.y1.xindex); } + /** + * Computes the polynomial representation of points on a perpendicular circle. + * + * @return a TMono object representing the points on a perpendicular circle + */ TMono PolyONDCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -665,6 +811,11 @@ TMono PolyONDCircle() { p1.x1.xindex, p1.y1.xindex, p3.x1.xindex, p3.y1.xindex); } + /** + * Computes the polynomial representation of points on an AB line. + * + * @return a TMono object representing the points on an AB line + */ TMono PolyONABLine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -676,6 +827,11 @@ TMono PolyONABLine() { p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of points on a cyclic circle. + * + * @return a TMono object representing the points on a cyclic circle + */ TMono PolyONSCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -686,6 +842,11 @@ TMono PolyONSCircle() { p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of a tangent line to two circles. + * + * @return a TPoly object representing the tangent line to two circles + */ TPoly PolyCCTangentLine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -704,9 +865,13 @@ TPoly PolyCCTangentLine() { TPoly poly2 = this.NewTPoly(m3, m4); poly1.getNext().setNext(poly2); return poly1; - } + /** + * Computes the polynomial representation of a ratio. + * + * @return a TMono object representing the ratio + */ TMono PolyRatio() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -723,6 +888,11 @@ TMono PolyRatio() { p7.x1.xindex, p7.y1.xindex, p8.x1.xindex, p8.y1.xindex); } + /** + * Computes the polynomial representation of a bisected line. + * + * @return a TMono object representing the bisected line + */ TMono PolyBLine() { CPoint p1 = (CPoint) elementlist.get(1); CPoint p2 = (CPoint) elementlist.get(2); @@ -734,9 +904,13 @@ TMono PolyBLine() { add_des(Gib.C_O_B, p, p1, p2); return poly.bisect1(p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - } + /** + * Computes the polynomial representation of a tangent line to a circle. + * + * @return a TMono object representing the tangent line to a circle + */ TMono PolyTCLine() { Circle c = (Circle) elementlist.get(0); CLine ln = (CLine) elementlist.get(1); @@ -755,9 +929,13 @@ TMono PolyTCLine() { return poly.perpendicular(p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - } + /** + * Computes the polynomial representation of a circle passing through three points. + * + * @return a TPoly object representing the circle passing through three points + */ TPoly PolyCircle3P() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -769,6 +947,11 @@ TPoly PolyCircle3P() { p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of an angle bisector. + * + * @return a TMono object representing the angle bisector + */ TMono PolyAngleBisector() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -784,8 +967,12 @@ TMono PolyAngleBisector() { return null; } - TPoly PolyPsym() // p1 is the mirror of p2 through p3 - { + /** + * Computes the polynomial representation of a symmetric point. + * + * @return a TPoly object representing the symmetric point + */ + TPoly PolyPsym() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); @@ -795,23 +982,11 @@ TPoly PolyPsym() // p1 is the mirror of p2 through p3 return this.NewTPoly(m1, m2); } - TPoly PolySquare() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_SQUARE, p1, p2, p3, p4); - TPoly t1 = poly.squarept1(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, this.proportion); - TPoly t2 = poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - TPoly t = t2; - while (t2.getNext() != null) - t2 = t2.getNext(); - t2.setNext(t1); - return t1; - } - + /** + * Computes the polynomial representation of an equilateral triangle. + * + * @return a TPoly object representing the equilateral triangle + */ TPoly PolyPeTriangle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -820,6 +995,11 @@ TPoly PolyPeTriangle() { return poly.pn_eq_triangle(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, true); } + /** + * Computes the polynomial representation of points on a line. + * + * @return a TMono object representing the points on a line + */ TMono polyPonALine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -832,6 +1012,11 @@ TMono polyPonALine() { p4.x1.xindex, p4.y1.xindex, p5.x1.xindex, p5.y1.xindex, p6.x1.xindex, p6.y1.xindex); } + /** + * Computes the polynomial representation of an incenter. + * + * @return a TPoly object representing the incenter + */ TPoly PolyInCenter() { CPoint p = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -849,6 +1034,11 @@ TPoly PolyInCenter() { return this.NewTPoly(m1, m2); } + /** + * Computes the polynomial representation of an orthocenter. + * + * @return a TPoly object representing the orthocenter + */ TPoly PolyOrthoCenter() { CPoint p = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -862,9 +1052,13 @@ TPoly PolyOrthoCenter() { add_des(Gib.C_ORTH, p, p1, p2, p3); return this.NewTPoly(m1, m2); - } + /** + * Computes the polynomial representation of a symmetric point. + * + * @return a TPoly object representing the symmetric point + */ TPoly PolySymPoint() { CPoint p1 = (CPoint) elementlist.get(0); CPoint po = (CPoint) elementlist.get(1); @@ -876,6 +1070,11 @@ TPoly PolySymPoint() { return this.NewTPoly(m1, m2); } + /** + * Computes the polynomial representation of a multiple side ratio. + * + * @return a TMono object representing the multiple side ratio + */ TMono polyMulside() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -885,23 +1084,35 @@ TMono polyMulside() { Integer i2 = (Integer) elementlist.get(5); add_des(Gib.C_NRATIO, p1, p2, p3, p4, i1, i2); return poly.p_p_mulside(p1, p2, p3, p4, i1.intValue(), i2.intValue()); - - } + /** + * Computes the polynomial representation of a horizontal line. + * + * @return a TMono object representing the horizontal line + */ TMono PolyHorizonal() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); return poly.p_p_horizonal(p1, p2); } + /** + * Computes the polynomial representation of a vertical line. + * + * @return a TMono object representing the vertical line + */ TMono PolyVertical() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); return poly.p_p_vertical(p1, p2); } - + /** + * Computes the polynomial representation of a line-circle tangent. + * + * @return a TPoly object representing the line-circle tangent + */ TPoly PolyLCTangent() { CLine line1; Circle c; @@ -926,6 +1137,11 @@ TPoly PolyLCTangent() { return tp; } + /** + * Computes the polynomial representation of a circumcenter. + * + * @return a TPoly object representing the circumcenter + */ TPoly PolyCircumCenter() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -938,6 +1154,11 @@ TPoly PolyCircumCenter() { p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of a barycenter. + * + * @return a TPoly object representing the barycenter + */ TPoly PolyBaryCenter() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -948,7 +1169,11 @@ TPoly PolyBaryCenter() { p4.x1.xindex, p4.y1.xindex); } - + /** + * Computes the polynomial representation of a proportional point. + * + * @return a TPoly object representing the proportional point + */ TPoly PolyPropPoint() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -961,7 +1186,12 @@ TPoly PolyPropPoint() { return poly.prop_point(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, i1.intValue(), i2.intValue()); } - TPoly PolyPratio() { // p1 is p2 + /p3p4/ + /** + * Computes the polynomial representation of a point ratio. + * + * @return a TPoly object representing the point ratio + */ + TPoly PolyPratio() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); @@ -981,6 +1211,11 @@ TPoly PolyPratio() { // p1 is p2 + /p3p4/ p4.x1.xindex, p4.y1.xindex, r1, r2); } + /** + * Computes the polynomial representation of the intersection of two circles. + * + * @return a TPoly object representing the intersection of the circles + */ TPoly PolyInterCC() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -988,16 +1223,18 @@ TPoly PolyInterCC() { Circle c2 = (Circle) elementlist.get(3); CPoint p3 = c1.o; CPoint p4 = c2.o; -// add_des(gib.C_O_C, p1, p3, p2); -// add_des(gib.C_O_C, p1, p4, p2); add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } - TPoly PolyMirror() // p1 to p2 through obj - { + /** + * Computes the polynomial representation of a mirror point. + * + * @return a TPoly object representing the mirror point + */ + TPoly PolyMirror() { Object obj = elementlist.get(2); CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1020,9 +1257,13 @@ TPoly PolyMirror() // p1 to p2 through obj return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } - } + /** + * Computes the polynomial representation of an isosceles triangle. + * + * @return a TMono object representing the isosceles triangle + */ TMono PolyISOTriangle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1033,16 +1274,25 @@ TMono PolyISOTriangle() { return poly.bisect(p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p1.x1.xindex, p1.y1.xindex); } + /** + * Computes the polynomial representation of a perpendicular bisector. + * + * @return a TMono object representing the perpendicular bisector + */ TMono PolyPerpBisect() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); add_des(Gib.C_O_B, p1, p2, p3); - return poly.bisect(p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p1.x1.xindex, p1.y1.xindex); } + /** + * Computes the polynomial representation of a trapezoid. + * + * @return a TPoly object representing the trapezoid + */ TPoly PolyTRatio() { int n = elementlist.size(); CPoint p1 = (CPoint) elementlist.get(0); @@ -1062,19 +1312,13 @@ TPoly PolyTRatio() { int t2 = I1.intValue(); return poly.Tratio(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, t1, t2); - - } - - TPoly PolyNTSegment() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - //des = new Act(Act.QSQUAR, p1, p2, p3, p4); - return poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - } + /** + * Computes the polynomial representation of an angle. + * + * @return a TMono object representing the angle + */ TMono PolyNTAngle() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1093,6 +1337,11 @@ TMono PolyNTAngle() { c.x1.xindex, c.y1.xindex, pt.x1.xindex, pt.y1.xindex); } + /** + * Computes the polynomial representation of a square. + * + * @return a TPoly object representing the square + */ TPoly PolyPsquare() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1100,32 +1349,26 @@ TPoly PolyPsquare() { CPoint p4 = (CPoint) elementlist.get(2); return poly.squarept1(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - } + /** + * Computes the polynomial representation of a square. + * + * @return a TPoly object representing the square + */ TPoly PolyQsquare() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = p2; CPoint p4 = (CPoint) elementlist.get(2); return poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - - } - - TMono PolyCCLine() { - CPoint p = (CPoint) this.getelement(0); - Circle c1 = (Circle) this.getelement(1); - Circle c2 = (Circle) this.getelement(2); - CPoint po1 = c1.o; - CPoint po2 = c2.o; - CPoint pc1 = c1.getSidePoint(); - CPoint pc2 = c2.getSidePoint(); - - return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, - po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); - } + /** + * Computes the polynomial representation of a specific angle. + * + * @return a TMono object representing the specific angle + */ TMono PolySAngle() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1141,6 +1384,11 @@ TMono PolySAngle() { return null; } + /** + * Computes the polynomial representation of an angle. + * + * @return a TMono object representing the angle + */ TMono PolyALine() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1182,6 +1430,11 @@ TMono PolyALine() { return null; } + /** + * Computes the polynomial representation of equal angles. + * + * @return a TMono object representing the equal angles + */ TMono PolyEqAngle() { if (elementlist.size() == 2) { CAngle ag1 = (CAngle) elementlist.get(0); @@ -1235,10 +1488,14 @@ TMono PolyEqAngle() { lp2[0].x1.xindex, lp2[0].y1.xindex, lp2[1].x1.xindex, lp2[1].y1.xindex, lp3[0].x1.xindex, lp3[0].y1.xindex, lp3[1].x1.xindex, lp3[1].y1.xindex, lp4[0].x1.xindex, lp4[0].y1.xindex, lp4[1].x1.xindex, lp4[1].y1.xindex); - } } + /** + * Computes the polynomial representation of equal angles with three points. + * + * @return a TMono object representing the equal angles with three points + */ TMono PolyEqAngle3P() { CAngle ag1 = (CAngle) elementlist.get(0); CAngle ag2 = (CAngle) elementlist.get(1); @@ -1261,14 +1518,23 @@ TMono PolyEqAngle3P() { p4.x1.xindex, p4.y1.xindex, p5.x1.xindex, p5.y1.xindex, p6.x1.xindex, p6.y1.xindex, p7.x1.xindex, p7.y1.xindex, p8.x1.xindex, p8.y1.xindex, p9.x1.xindex, p9.y1.xindex, pm.xindex); - } + /** + * Computes the polynomial representation of a specific angle. + * + * @return a TMono object representing the specific angle + */ TMono PolySpecifiAngle() { Param pm = (Param) elementlist.get(0); return poly.specificangle(pm.xindex, this.proportion); } + /** + * Computes the polynomial representation of equal distances. + * + * @return a TMono object representing the equal distances + */ TMono PolyEqidstance() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1278,9 +1544,13 @@ TMono PolyEqidstance() { add_des(Gib.C_EQDISTANCE, p1, p2, p3, p4); return poly.eqdistance(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - } + /** + * Computes the polynomial representation of a midpoint. + * + * @return a TPoly object representing the midpoint + */ TPoly PolyMidPoint() { CPoint po = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -1297,282 +1567,334 @@ TPoly PolyMidPoint() { poly2.setPoly(m2); poly2.setNext(poly); return poly2; - - } - - - TPoly PolyRectangle() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_RECTANGLE, p1, p2, p3, p4); - - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - TMono m3 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TPoly p = NewTPoly(m1, m2); - TPoly pp = new TPoly(); - pp.setPoly(m3); - pp.setNext(p); - return pp; } - TMono PolyTrapezoid() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_TRAPEZOID, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - return m1; - } - - TPoly PolyParallelogram() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - int n = p4.x1.xindex; - if (n > p1.x1.xindex && n > p2.x1.xindex) { - CPoint pt = p4; - p4 = p1; - p1 = pt; - pt = p3; - p3 = p2; - p2 = pt; + /** + * Computes the polynomial representation of a rectangle. + * + * @return a TPoly object representing the rectangle + */ + TPoly PolyRectangle() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_RECTANGLE, p1, p2, p3, p4); + + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + TMono m3 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TPoly p = NewTPoly(m1, m2); + TPoly pp = new TPoly(); + pp.setPoly(m3); + pp.setNext(p); + return pp; } - add_des(Gib.C_PARALLELOGRAM, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - return this.NewTPoly(m1, m2); - - } - - TPoly PolyRTrapezoid() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_R_TRAPEZOID, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); - return this.NewTPoly(m1, m2); - - } - - TMono PolyRightTriangle() { - CPoint po = (CPoint) elementlist.get(0); - CPoint p1 = (CPoint) elementlist.get(1); - CPoint p2 = (CPoint) elementlist.get(2); - add_des(Gib.C_R_TRI, po, p1, p2); - return poly.perpendicular(po.x1.xindex, po.y1.xindex, p1.x1.xindex, p1.y1.xindex, - po.x1.xindex, po.y1.xindex, p2.x1.xindex, p2.y1.xindex); - } - - TMono PolyOnLine() { - CPoint p = (CPoint) this.getelement(0); - CLine line = (CLine) this.getelement(1); - int x, y; - x = p.x1.xindex; - y = p.y1.xindex; - if (line.type == CLine.CCLine) { - Constraint cs = line.getcons(0); - - Circle c1 = (Circle) cs.getelement(1); - Circle c2 = (Circle) cs.getelement(2); - CPoint po1 = c1.o; - CPoint po2 = c2.o; - CPoint pc1 = c1.getSidePoint(); - CPoint pc2 = c2.getSidePoint(); - //????? - return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, - po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); - - - } else { - CPoint[] plist = line.getTowSideOfLine(); - if (plist == null) return null; - CPoint p1, p2; - p1 = plist[0]; - p2 = plist[1]; - add_des(Gib.C_O_L, p, p1, p2); - return poly.collinear(x, y, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); + /** + * Computes the polynomial representation of a trapezoid. + * + * @return a TMono object representing the trapezoid + */ + TMono PolyTrapezoid() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_TRAPEZOID, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + return m1; } - } - - TPoly PolyIntersection_CC() { - CPoint p1 = (CPoint) elementlist.get(0); - Circle c1 = (Circle) elementlist.get(1); - Circle c2 = (Circle) elementlist.get(2); - Vector v = Circle.CommonPoints(c1, c2); - TPoly tp = null; - int n = v.size(); - CPoint p2 = null; - - if (n == 2) { - CPoint t1 = (CPoint) v.get(0); - CPoint t2 = (CPoint) v.get(1); - if (p1 == t1) - p2 = t2; - else - p2 = t1; - } else if (n == 1 && v.get(0) != p1) - p2 = (CPoint) v.get(0); + /** + * Computes the polynomial representation of a parallelogram. + * + * @return a TPoly object representing the parallelogram + */ + TPoly PolyParallelogram() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); - if (p2 != null && p2.x1.xindex < p1.x1.xindex) { - CPoint p3 = c1.o; - CPoint p4 = c2.o; - this.add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); - return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, - p4.x1.xindex, p4.y1.xindex); + int n = p4.x1.xindex; + if (n > p1.x1.xindex && n > p2.x1.xindex) { + CPoint pt = p4; + p4 = p1; + p1 = pt; + pt = p3; + p3 = p2; + p2 = pt; + } + add_des(Gib.C_PARALLELOGRAM, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, + p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + return this.NewTPoly(m1, m2); } - p2 = c1.getSidePoint(); - CPoint p3 = c2.getSidePoint(); - if (p2 != null && p3 != null) { - this.add_des(Gib.C_I_CC, p1, c1.o, p2, c2.o, p3); - TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, - p2.x1.xindex, p2.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex); - TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, - p3.x1.xindex, p3.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex); - return this.NewTPoly(m1, m2); - } else { - CPoint[] l1 = c1.getRadiusPoint(); - CPoint[] l2 = c2.getRadiusPoint(); - this.add_des(Gib.C_I_RR, p1, c1.o, l1[0], l1[1], c2.o, l2[0], l2[1]); - - TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, - l1[0].x1.xindex, l1[0].y1.xindex, l1[1].x1.xindex, l1[1].y1.xindex); - TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, - l2[0].x1.xindex, l2[0].y1.xindex, l2[1].x1.xindex, l2[1].y1.xindex); + /** + * Computes the polynomial representation of a right trapezoid. + * + * @return a TPoly object representing the right trapezoid + */ + TPoly PolyRTrapezoid() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_R_TRAPEZOID, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, + p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); return this.NewTPoly(m1, m2); } - } - TPoly PolyIntersection_ll() { - CPoint p1 = (CPoint) elementlist.get(0); - CLine ln1 = (CLine) elementlist.get(1); - CLine ln2 = (CLine) elementlist.get(2); - if (compareLN(ln1, ln2)) { - CLine ln = ln1; - ln1 = ln2; - ln2 = ln; + /** + * Computes the polynomial representation of a right triangle. + * + * @return a TMono object representing the right triangle + */ + TMono PolyRightTriangle() { + CPoint po = (CPoint) elementlist.get(0); + CPoint p1 = (CPoint) elementlist.get(1); + CPoint p2 = (CPoint) elementlist.get(2); + add_des(Gib.C_R_TRI, po, p1, p2); + return poly.perpendicular(po.x1.xindex, po.y1.xindex, p1.x1.xindex, p1.y1.xindex, + po.x1.xindex, po.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - CPoint[] ps1 = ln1.getTowSideOfLine(); - if (ps1 == null) return null; - CPoint[] ps2 = ln2.getTowSideOfLine(); - if (ps2 == null) return null; - add_des(Gib.C_I_LL, p1, ps1[0], ps1[1], ps2[0], ps2[1]); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps1[0].x1.xindex, ps1[0].y1.xindex, ps1[1].x1.xindex, ps1[1].y1.xindex); - addZeron(m1); - TMono m2 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps2[0].x1.xindex, ps2[0].y1.xindex, ps2[1].x1.xindex, ps2[1].y1.xindex); - return this.NewTPoly(m1, m2); - } - - TPoly PolyIntersection_lc() { - CPoint p1 = (CPoint) elementlist.get(0); - CLine ln = (CLine) elementlist.get(1); - Circle c = (Circle) elementlist.get(2); - CPoint[] ls = CLine.commonPoint(ln, c); - CPoint[] np = ln.getTowSideOfLine(); - CPoint o = c.o; - - CPoint p2; + /** + * Computes the polynomial representation of a point on a line. + * + * @return a TMono object representing the point on the line + */ + TMono PolyOnLine() { + CPoint p = (CPoint) this.getelement(0); + CLine line = (CLine) this.getelement(1); + int x, y; + x = p.x1.xindex; + y = p.y1.xindex; + + if (line.type == CLine.CCLine) { + Constraint cs = line.getcons(0); + + Circle c1 = (Circle) cs.getelement(1); + Circle c2 = (Circle) cs.getelement(2); + CPoint po1 = c1.o; + CPoint po2 = c2.o; + CPoint pc1 = c1.getSidePoint(); + CPoint pc2 = c2.getSidePoint(); + //????? + return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, + po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); + } else { + CPoint[] plist = line.getTowSideOfLine(); + if (plist == null) return null; + CPoint p1, p2; + p1 = plist[0]; + p2 = plist[1]; + add_des(Gib.C_O_L, p, p1, p2); + return poly.collinear(x, y, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); + } + } - if (ls.length == 2) { - if (p1 == ls[0]) - p2 = ls[1]; - else - p2 = ls[0]; - } else if (ls.length == 1 && ls[0] != p1) - p2 = ls[0]; - else - p2 = null; + /** + * Computes the polynomial representation of the intersection of two circles. + * + * @return a TPoly object representing the intersection of the circles + */ + TPoly PolyIntersection_CC() { + CPoint p1 = (CPoint) elementlist.get(0); + Circle c1 = (Circle) elementlist.get(1); + Circle c2 = (Circle) elementlist.get(2); + Vector v = Circle.CommonPoints(c1, c2); + TPoly tp = null; + int n = v.size(); + CPoint p2 = null; + + if (n == 2) { + CPoint t1 = (CPoint) v.get(0); + CPoint t2 = (CPoint) v.get(1); + if (p1 == t1) + p2 = t2; + else + p2 = t1; + } else if (n == 1 && v.get(0) != p1) + p2 = (CPoint) v.get(0); + + if (p2 != null && p2.x1.xindex < p1.x1.xindex) { + CPoint p3 = c1.o; + CPoint p4 = c2.o; + this.add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); + return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, + p4.x1.xindex, p4.y1.xindex); + } - if (p2 != null && p1.x1.xindex > p2.x1.xindex) { - add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); - CPoint pl = ln.getSecondPoint(p2); - return poly.LCMeet(o.x1.xindex, o.y1.xindex, p2.x1.xindex, - p2.y1.xindex, pl.x1.xindex, pl.y1.xindex, p1.x1.xindex, p1.y1.xindex); + p2 = c1.getSidePoint(); + CPoint p3 = c2.getSidePoint(); + if (p2 != null && p3 != null) { + this.add_des(Gib.C_I_CC, p1, c1.o, p2, c2.o, p3); + TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, + p2.x1.xindex, p2.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex); + TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, + p3.x1.xindex, p3.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex); + return this.NewTPoly(m1, m2); + } else { + CPoint[] l1 = c1.getRadiusPoint(); + CPoint[] l2 = c2.getRadiusPoint(); + this.add_des(Gib.C_I_RR, p1, c1.o, l1[0], l1[1], c2.o, l2[0], l2[1]); + + TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, + l1[0].x1.xindex, l1[0].y1.xindex, l1[1].x1.xindex, l1[1].y1.xindex); + TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, + l2[0].x1.xindex, l2[0].y1.xindex, l2[1].x1.xindex, l2[1].y1.xindex); + return this.NewTPoly(m1, m2); + } } - CPoint pl = c.getSidePoint(); - if (pl != null) { - add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); - addZeron(m1); - TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, o.x1.xindex, o.y1.xindex, pl.x1.xindex, pl.y1.xindex); - return this.NewTPoly(m1, m2); - } else { - CPoint[] ll = c.getRadiusPoint(); - add_des(Gib.C_I_LR, p1, np[0], np[1], c.o, ll[0], ll[1]); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + /** + * Computes the polynomial representation of the intersection of two lines. + * + * @return a TPoly object representing the intersection of the lines + */ + TPoly PolyIntersection_ll() { + CPoint p1 = (CPoint) elementlist.get(0); + CLine ln1 = (CLine) elementlist.get(1); + CLine ln2 = (CLine) elementlist.get(2); + if (compareLN(ln1, ln2)) { + CLine ln = ln1; + ln1 = ln2; + ln2 = ln; + } + + CPoint[] ps1 = ln1.getTowSideOfLine(); + if (ps1 == null) return null; + CPoint[] ps2 = ln2.getTowSideOfLine(); + if (ps2 == null) return null; + add_des(Gib.C_I_LL, p1, ps1[0], ps1[1], ps2[0], ps2[1]); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps1[0].x1.xindex, ps1[0].y1.xindex, ps1[1].x1.xindex, ps1[1].y1.xindex); addZeron(m1); - TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, ll[0].x1.xindex, ll[0].y1.xindex, ll[1].x1.xindex, ll[1].x1.xindex); + TMono m2 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps2[0].x1.xindex, ps2[0].y1.xindex, ps2[1].x1.xindex, ps2[1].y1.xindex); return this.NewTPoly(m1, m2); } - } - - TMono collinear() { - CPoint p1, p2, p3; - p1 = p2 = p3 = null; + /** + * Computes the polynomial representation of the intersection of a line and a circle. + * + * @return a TPoly object representing the intersection of the line and the circle + */ + TPoly PolyIntersection_lc() { + CPoint p1 = (CPoint) elementlist.get(0); + CLine ln = (CLine) elementlist.get(1); + Circle c = (Circle) elementlist.get(2); + CPoint[] ls = CLine.commonPoint(ln, c); + CPoint[] np = ln.getTowSideOfLine(); + CPoint o = c.o; - for (int i = 0; i < this.elementlist.size(); i++) { - CPoint p = (CPoint) this.getelement(i); - if (p == null) continue; + CPoint p2; - if (p1 == null) - p1 = p; - else if (p1.x1.xindex < p.x1.xindex) { - if (p2 == null) - p2 = p1; + if (ls.length == 2) { + if (p1 == ls[0]) + p2 = ls[1]; else - p3 = p1; - p1 = p; - - } else if (p2 == null) - p2 = p; + p2 = ls[0]; + } else if (ls.length == 1 && ls[0] != p1) + p2 = ls[0]; else - p3 = p; - } + p2 = null; - add_des(Gib.C_O_L, p1, p2, p3); - return poly.collinear(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - } + if (p2 != null && p1.x1.xindex > p2.x1.xindex) { + add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); + CPoint pl = ln.getSecondPoint(p2); + return poly.LCMeet(o.x1.xindex, o.y1.xindex, p2.x1.xindex, + p2.y1.xindex, pl.x1.xindex, pl.y1.xindex, p1.x1.xindex, p1.y1.xindex); + } - TPoly PolyLCMeet() { + CPoint pl = c.getSidePoint(); + if (pl != null) { + add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + addZeron(m1); + TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, o.x1.xindex, o.y1.xindex, pl.x1.xindex, pl.y1.xindex); + return this.NewTPoly(m1, m2); + } else { + CPoint[] ll = c.getRadiusPoint(); + add_des(Gib.C_I_LR, p1, np[0], np[1], c.o, ll[0], ll[1]); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + addZeron(m1); + TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, ll[0].x1.xindex, ll[0].y1.xindex, ll[1].x1.xindex, ll[1].x1.xindex); + return this.NewTPoly(m1, m2); + } + } - CPoint pl = null; - CPoint p = (CPoint) this.getelement(0); - CPoint pc = (CPoint) this.getelement(1); - CLine ln = (CLine) this.getelement(2); - Circle c = (Circle) this.getelement(3); - CPoint o = c.o; - Vector pts = ln.points; - for (int i = 0; i < pts.size(); i++) - if (pts.get(i) != pc) { - pl = (CPoint) pts.get(i); - break; + /** + * Computes the polynomial representation of collinear points. + * + * @return a TMono object representing the collinear points + */ + TMono collinear() { + CPoint p1, p2, p3; + p1 = p2 = p3 = null; + + for (int i = 0; i < this.elementlist.size(); i++) { + CPoint p = (CPoint) this.getelement(i); + if (p == null) continue; + + if (p1 == null) + p1 = p; + else if (p1.x1.xindex < p.x1.xindex) { + if (p2 == null) + p2 = p1; + else + p3 = p1; + p1 = p; + + } else if (p2 == null) + p2 = p; + else + p3 = p; } - if (pl == null) return null; - add_des(Gib.C_I_LC, p, pc, pl, o, pc); - return poly.LCMeet(o.x1.xindex, o.y1.xindex, pc.x1.xindex, pc.y1.xindex, pl.x1.xindex, pl.y1.xindex, p.x1.xindex, p.y1.xindex); - } + add_des(Gib.C_O_L, p1, p2, p3); + return poly.collinear(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + } + + /** + * Computes the polynomial representation of the intersection of a line and a circle. + * + * @return a TPoly object representing the intersection of the line and the circle + */ + TPoly PolyLCMeet() { + CPoint pl = null; + CPoint p = (CPoint) this.getelement(0); + CPoint pc = (CPoint) this.getelement(1); + CLine ln = (CLine) this.getelement(2); + Circle c = (Circle) this.getelement(3); + CPoint o = c.o; + Vector pts = ln.points; + for (int i = 0; i < pts.size(); i++) + if (pts.get(i) != pc) { + pl = (CPoint) pts.get(i); + break; + } + if (pl == null) return null; + add_des(Gib.C_I_LC, p, pc, pl, o, pc); + return poly.LCMeet(o.x1.xindex, o.y1.xindex, pc.x1.xindex, pc.y1.xindex, pl.x1.xindex, pl.y1.xindex, p.x1.xindex, p.y1.xindex); + } + + /** + * Checks if a point lies on a circle. + * + * @return a TMono object representing the constraint + */ TMono PolyOnCircle() { CPoint p = (CPoint) this.getelement(0); Circle c = (Circle) this.getelement(1); @@ -1594,8 +1916,7 @@ TMono PolyOnCircle() { add_des(Gib.C_O_R, p, o, p1, p2); return poly.eqdistance(o.x1.xindex, o.y1.xindex, p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); - } else if (c.points.size() != 0)//|| c.type == Circle.PCircle || c.type == Circle.SCircle) - { + } else if (c.points.size() != 0) { CPoint pt = c.getSidePoint(); if (pt == null) return null; @@ -1610,6 +1931,11 @@ TMono PolyOnCircle() { return null; } + /** + * Checks if two lines or four points are perpendicular. + * + * @return a TMono object representing the perpendicularity constraint + */ TMono PolyPerp() { if (elementlist.size() == 2) { CLine line1 = (CLine) this.getelement(0); @@ -1645,9 +1971,13 @@ TMono PolyPerp() { return poly.perpendicular(x1, y1, x2, y2, x3, y3, x4, y4); } return null; - } + /** + * Computes the foot of a perpendicular from a point to a line. + * + * @return a TPoly object representing the foot of the perpendicular + */ TPoly PolyPfoot() { CPoint p1 = (CPoint) this.getelement(0); CPoint p2 = (CPoint) this.getelement(1); @@ -1659,10 +1989,13 @@ TPoly PolyPfoot() { TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); return mpoly(m1, m2); - - } + /** + * Checks if two lines are parallel. + * + * @return a TMono object representing the parallelism constraint + */ TMono PolyParel() { CLine line1 = (CLine) this.getelement(0); CLine line2 = (CLine) this.getelement(1); @@ -1681,6 +2014,11 @@ TMono PolyParel() { pl2[0].x1.xindex, pl2[0].y1.xindex, pl2[1].x1.xindex, pl2[1].y1.xindex); } + /** + * Computes the tangent between two circles. + * + * @return a TMono object representing the tangent constraint + */ TMono PolyCCTangent() { Circle c1 = (Circle) this.getelement(0); Circle c2 = (Circle) this.getelement(1); @@ -1692,60 +2030,13 @@ TMono PolyCCTangent() { return poly.c_c_tangent(pl1[0], pl1[1], c1.o, pl2[0], pl2[1], c2.o); } - public static boolean PolyConstraint(int type, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - int x1, y1, x2, y2, x3, y3, x4, y4; - x1 = p1.x1.xindex; - y1 = p1.y1.xindex; - x2 = p2.x1.xindex; - y2 = p2.y1.xindex; - x3 = p3.x1.xindex; - y3 = p3.y1.xindex; - TMono mpoly = null; - TMono mpoly1 = null; - switch (type) { - case Constraint.COLLINEAR: // 3 obj - mpoly = poly.collinear(x1, y1, x2, y2, x3, y3); - break; - case Constraint.PARALLEL: // 4 obj - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.parallel(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.PERPENDICULAR: //4 - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.perpendicular(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.EQDISTANCE: //4 - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.eqdistance(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.BISECT: - mpoly = poly.bisect(x1, y1, x2, y2, x3, y3); - break; - case Constraint.MIDPOINT: - mpoly = poly.midpoint(x1, x2, x3); - mpoly1 = poly.midpoint(y1, y2, y3); - default: - break; - } - - if (mpoly == null) - return false; - TPoly tp = new TPoly(); - tp.setPoly(mpoly); - tp.setNext(polylist); - polylist = tp; - if (type == Constraint.MIDPOINT) { - tp = new TPoly(); - tp.setPoly(mpoly1); - tp.setNext(polylist); - polylist = tp; - } - return true; - } - + /** + * Creates a new TPoly object from two TMono objects. + * + * @param m1 the first TMono object + * @param m2 the second TMono object + * @return the created TPoly object + */ public TPoly NewTPoly(TMono m1, TMono m2) { TPoly poly = new TPoly(); poly.setPoly(m1); @@ -1755,6 +2046,12 @@ public TPoly NewTPoly(TMono m1, TMono m2) { return poly2; } + /** + * Saves the constraint data to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { out.writeInt(id); @@ -1806,10 +2103,13 @@ public void Save(DataOutputStream out) throws IOException { } out.writeInt(proportion); out.writeBoolean(this.is_poly_genereate); - - } + /** + * Adds a constraint description to the list of constraints. + * + * @param s the Cons object representing the constraint description + */ private void add_des(Cons s) { if (this.csd == null) this.csd = s; @@ -1817,7 +2117,15 @@ private void add_des(Cons s) { this.csd1 = s; } - + /** + * Adds a constraint description with three points and an additional object to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param obj the additional object + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, Object obj) { Cons csd = new Cons(t); @@ -1829,6 +2137,14 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, Object obj) { add_des(csd); } + /** + * Adds a constraint description with three points to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3) { Cons csd = new Cons(t); @@ -1839,6 +2155,12 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3) { add_des(csd); } + /** + * Adds a constraint description with a vector of points to the list of constraints. + * + * @param t the type of the constraint + * @param v the vector of points + */ public void add_des(int t, Vector v) { Cons csd = new Cons(t); csd.setId(id); @@ -1847,11 +2169,27 @@ public void add_des(int t, Vector v) { add_des(csd); } + /** + * Compares two points based on their x-index. + * + * @param a the first point + * @param b the second point + * @return true if the x-index of the first point is less than the x-index of the second point, false otherwise + */ public boolean less(CPoint a, CPoint b) { return a.x1.xindex < b.x1.xindex; } - public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { //parallel ,perpendicular + /** + * Adds a constraint description with four points to the list of constraints, ensuring the points are ordered by their x-index. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ + public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (less(p1, p2)) { CPoint a = p1; p1 = p2; @@ -1873,8 +2211,16 @@ public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { //p add_des(t, p1, p2, p3, p4); } + /** + * Adds a constraint description with four points to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1884,6 +2230,16 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { add_des(csd); } + /** + * Adds a constraint description with five objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + */ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5) { Cons csd = new Cons(t); csd.setId(id); @@ -1895,6 +2251,17 @@ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5 add_des(csd); } + /** + * Adds a constraint description with six objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + */ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) { Cons csd = new Cons(t); csd.setId(id); @@ -1907,8 +2274,20 @@ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5 add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7, Object p8) { + /** + * Adds a constraint description with eight objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + * @param p8 the eighth object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1922,8 +2301,22 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) { + /** + * Adds a constraint description with ten objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + * @param p8 the eighth object + * @param p9 the ninth object + * @param p10 the tenth object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1939,8 +2332,19 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7) { + /** + * Adds a constraint description with seven objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1953,7 +2357,13 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - + /** + * Loads the constraint data from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess instance to use for retrieving elements + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { id = in.readInt(); ConstraintType = in.readInt(); @@ -2001,18 +2411,16 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { this.ConstraintType = NSQUARE; elementlist.remove(1); } - } } - int pidx(CPoint p) { - return p.x1.xindex; - } - - int pidy(CPoint p) { - return p.y1.xindex; - } - + /** + * Creates a new TPoly object from two TMono objects. + * + * @param m1 the first TMono object + * @param m2 the second TMono object + * @return the created TPoly object + */ TPoly mpoly(TMono m1, TMono m2) { TPoly p1 = new TPoly(); p1.setPoly(m1); @@ -2022,6 +2430,12 @@ TPoly mpoly(TMono m1, TMono m2) { return p2; } + /** + * Returns the special angle value for the given angle in degrees. + * + * @param v the angle in degrees + * @return the special angle value + */ public static double get_sp_ag_value(int v) { double val = 0; if (v == 90) @@ -2032,10 +2446,13 @@ public static double get_sp_ag_value(int v) { return val; } - public double get_sangle_v() { - return get_sp_ag_value(proportion); - } - + /** + * Checks if the constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the constraint is satisfied, false otherwise + */ public boolean check_constraint(double x, double y) { switch (ConstraintType) { case ANGLE_BISECTOR: @@ -2047,6 +2464,13 @@ public boolean check_constraint(double x, double y) { } } + /** + * Checks if the incenter constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the incenter constraint is satisfied, false otherwise + */ public boolean check_incenter(double x, double y) { CPoint p1 = (CPoint) elementlist.get(1); CPoint p2 = (CPoint) elementlist.get(2); @@ -2066,6 +2490,13 @@ public boolean check_incenter(double x, double y) { return r1 * r2 > 0 && r3 * r4 > 0; } + /** + * Checks if the angle bisector constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the angle bisector constraint is satisfied, false otherwise + */ public boolean check_agbisector(double x, double y) { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -2083,26 +2514,65 @@ public boolean check_agbisector(double x, double y) { return r1 * r2 > 0; } + /** + * Calculates the determinant of the given points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x the x-coordinate of the third point + * @param y the y-coordinate of the third point + * @return the determinant value + */ public double dr_pr(double x1, double y1, double x2, double y2, double x, double y) { return (y2 - y1) * (x - x2) - (y - y2) * (x2 - x1); - } + /** + * Creates a TMono object representing the equality of distances between two pairs of points. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return the created TMono object + */ public TMono eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return poly.eqdistance(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Compares two lines based on the ID of their first points. + * + * @param ln1 the first line + * @param ln2 the second line + * @return true if the first point of the first line has a greater ID than the first point of the second line, false otherwise + */ public boolean compareLN(CLine ln1, CLine ln2) { - return - (ln1.getfirstPoint().m_id > ln2.getfirstPoint().m_id); + return (ln1.getfirstPoint().m_id > ln2.getfirstPoint().m_id); } + /** + * Parses a TMono object from a string representation. + * + * @param name the name of the TMono object + * @param func the function string + * @param x the x-coordinate + * @return the parsed TMono object + */ public TMono parseTMonoString(String name, String func, int x) { Parser p = new Parser(name, func, x); TMono m = p.parse(); return m; } + /** + * Adds a zero coefficient to the TMono object if its length is 1. + * + * @param m1 the TMono object + * @return true if a zero coefficient was added, false otherwise + */ public boolean addZeron(TMono m1) { if (m1 != null && poly.plength(m1) == 1) return poly.addZeroN(m1.x); diff --git a/src/main/java/wprover/DPanel.java b/src/main/java/wprover/DPanel.java index ff3914a1..2746d918 100644 --- a/src/main/java/wprover/DPanel.java +++ b/src/main/java/wprover/DPanel.java @@ -3,36 +3,51 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; - +/** + * A custom JPanel that handles various mouse and component events. + * Implements MouseListener, MouseMotionListener, MouseWheelListener, and ComponentListener. + */ class DPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener { + /** Constant for draw mode. */ final public static int DRAW = 0; + /** Constant for construction mode. */ final public static int CONS = 1; // construction. DrawTextProcess dp = new DrawTextProcess(); + /** The input type, either DRAW or CONS. */ private int Input_type = DRAW; // draw ,1 : prove GExpert gxInstance; - public void SetInputType(int type) { - this.Input_type = type; - } - + /** + * Clears all components from the panel. + */ public void clearAll() { this.removeAll(); } - public void SetDrawType(int type) { - this.Input_type = DRAW; - dp.SetCurrentAction(type); - } - + /** + * Sets the animation step. + * + * @param step the step value to set + */ public void setStep(double step) { dp.animate.Setstep(step); } + /** + * Checks if an action needs to proceed based on the prover's state. + * + * @return true if the action needs to proceed, false otherwise + */ public boolean actionNeedProceed() { return gxInstance == null || !gxInstance.getpprove().isProverRunning(); } + /** + * Constructor for DPanel. + * + * @param gx the GExpert instance + */ public DPanel(GExpert gx) { gxInstance = gx; @@ -42,18 +57,22 @@ public DPanel(GExpert gx) { this.setDoubleBuffered(true); this.setLayout(null); this.addComponentListener(this); -// this.setBorder(BorderFactory.createLineBorder(Color.lightGray)); -// this.setBorder(new GBevelBorder(GBevelBorder.RAISED)); this.setBackground(CMisc.getBackGroundColor()); } - + /** + * Recalculates and repaints the panel. + */ public void repaintAndCalculate() { dp.reCalculate(); this.repaint(); } - + /** + * Handles animation based on the type. + * + * @param type the type of animation (0: on time, 1: start, 2: stop) + */ public void onAnimate(int type) { if (type == 1) //start dp.animationStart(); @@ -63,18 +82,22 @@ else if (type == 0) dp.animationOntime(); repaint(); - } + /** + * Returns the preferred size of the panel. + * + * @return the preferred size + */ public Dimension getPreferredSize() { -// Rectangle rc = dp.getBounds(); -// -// int x = (int) (Math.abs(rc.getX() + rc.getWidth())) + 20; -// int y = (int) (Math.abs(rc.getY() + rc.getHeight())) + 20; -// return new Dimension(x, y); return super.getPreferredSize(); } + /** + * Handles mouse pressed events. + * + * @param e the MouseEvent + */ public void mousePressed(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -93,23 +116,30 @@ public void mousePressed(MouseEvent e) { } } + /** + * Handles mouse dragged events. + * + * @param e the MouseEvent + */ public void mouseDragged(MouseEvent e) { if (!this.actionNeedProceed()) return; int button = e.getButton(); if (button == MouseEvent.BUTTON3) { - return; } if (Input_type == 0) { dp.DWMouseDrag(e.getX(), e.getY()); repaint(); - } else { } } - + /** + * Handles mouse released events. + * + * @param e the MouseEvent + */ public void mouseReleased(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -124,9 +154,12 @@ public void mouseReleased(MouseEvent e) { } } + /** + * Handles mouse moved events. + * + * @param e the MouseEvent + */ public void mouseMoved(MouseEvent e) { - - int button = e.getButton(); if (button == MouseEvent.BUTTON3) @@ -137,6 +170,11 @@ public void mouseMoved(MouseEvent e) { } } + /** + * Handles mouse clicked events. + * + * @param e the MouseEvent + */ public void mouseClicked(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -145,69 +183,82 @@ public void mouseClicked(MouseEvent e) { dp.DWMouseRightClick(e.getX(), e.getY()); else if (e.getClickCount() > 1) dp.DWMouseDbClick(e.getX(), e.getY()); - } + /** + * Handles mouse exited events. + * + * @param e the MouseEvent + */ public void mouseExited(MouseEvent e) { -// if (!this.actionNeedProceed()) -// return; - dp.setMouseInside(false); this.repaint(); } + /** + * Handles mouse entered events. + * + * @param e the MouseEvent + */ public void mouseEntered(MouseEvent e) { -// if (!this.actionNeedProceed()) -// return; - dp.setMouseInside(true); this.repaint(); } + /** + * Handles mouse wheel moved events. + * + * @param e the MouseWheelEvent + */ public void mouseWheelMoved(MouseWheelEvent e) { -// if (!this.actionNeedProceed()) -// return; - int n = e.getScrollAmount(); dp.DWMouseWheel(e.getX(), e.getY(), n, e.getWheelRotation()); this.repaint(); } - + /** + * Handles component resized events. + * + * @param e the ComponentEvent + */ public void componentResized(ComponentEvent e) { } + /** + * Handles component moved events. + * + * @param e the ComponentEvent + */ public void componentMoved(ComponentEvent e) { } + /** + * Handles component shown events. + * + * @param e the ComponentEvent + */ public void componentShown(ComponentEvent e) { } + /** + * Handles component hidden events. + * + * @param e the ComponentEvent + */ public void componentHidden(ComponentEvent e) { } - + /** + * Paints the component. + * + * @param g the Graphics object + */ public void paintComponent(Graphics g) { super.paintComponent(g); Dimension dm = this.getSize(); dp.SetDimension(dm.getWidth(), dm.getHeight()); dp.paintPoint(g); -// paintBD(g); - } - - - final private static BasicStroke bstroke = new BasicStroke(1.0f); - - public void paintBD(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setStroke(bstroke); - g2.setColor(Color.LIGHT_GRAY); - int w = this.getWidth() - 1; - int h = this.getHeight() - 1; - - g2.drawLine(0, h, w, h); - g2.drawLine(w, 0, w, h); } -} +} \ No newline at end of file diff --git a/src/main/java/wprover/DiagramUpdater.java b/src/main/java/wprover/DiagramUpdater.java index 1eecd8ea..9c0a67e5 100644 --- a/src/main/java/wprover/DiagramUpdater.java +++ b/src/main/java/wprover/DiagramUpdater.java @@ -1,13 +1,13 @@ package wprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 14, 2007 - * Time: 9:03:10 AM - * To change this template use File | Settings | File Templates. + * DiagramUpdater is an interface that defines a method for updating a diagram. + * Implementing classes should provide the specific implementation of the UpdateDiagram method. */ public interface DiagramUpdater { - + /** + * Updates the diagram. + * This method should be implemented to provide the specific logic for updating the diagram. + */ public void UpdateDiagram(); } diff --git a/src/main/java/wprover/DialogProperty.java b/src/main/java/wprover/DialogProperty.java index 68eb1c27..98f053dd 100644 --- a/src/main/java/wprover/DialogProperty.java +++ b/src/main/java/wprover/DialogProperty.java @@ -4,14 +4,16 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-16 - * Time: 15:47:43 - * To change this template use File | Settings | File Templates. + * DialogProperty is a class that represents a dialog for displaying properties. + * It extends the JBaseDialog class and provides a constructor to initialize the dialog with a specified owner and panel. */ public class DialogProperty extends JBaseDialog { + /** + * Constructs a DialogProperty with specified owner and panel. + * @param owner the owner of the dialog + * @param panel the panel to be displayed in the dialog + */ public DialogProperty(GExpert owner,JPanel panel) { super(owner.getFrame(),false); diff --git a/src/main/java/wprover/DialogPsProperty.java b/src/main/java/wprover/DialogPsProperty.java index 6a345ab0..97edc0b6 100644 --- a/src/main/java/wprover/DialogPsProperty.java +++ b/src/main/java/wprover/DialogPsProperty.java @@ -3,12 +3,21 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +/** + * Dialog for setting PostScript (PS) properties. + * Extends JBaseDialog and implements ActionListener. + */ public class DialogPsProperty extends JBaseDialog implements ActionListener { private int type = -1; private JCheckBox pfill; private GExpert gxInstance; + /** + * Retrieves the localized language string for the given key. + * + * @param s the key for the language string + * @return the localized language string, or the key if no localization is found + */ public String getLanguage(String s) { String s1 = ""; if (gxInstance != null) @@ -18,13 +27,18 @@ public String getLanguage(String s) { return s; } + /** + * Constructor for the DialogPsProperty class. + * Initializes the dialog with the specified GExpert owner. + * + * @param owner the GExpert instance that owns this dialog + */ public DialogPsProperty(GExpert owner) { super(owner.getFrame(), true); gxInstance = owner; this.setTitle(getLanguage("Save as PS")); -// this.setSize(350, 120); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JToggleButton button1 = new JToggleButton(gxInstance.getLanguage("Color")); @@ -54,14 +68,16 @@ public DialogPsProperty(GExpert owner) { JPanel ppanel = new JPanel(); ppanel.setLayout(new BoxLayout(ppanel, BoxLayout.Y_AXIS)); pfill = new JCheckBox(gxInstance.getLanguage("Point filled with background color")); -// ptext = new JCheckBox(gxInstance.getLanguage(1014, "Proof text")); -// ptext.setSelected(true); ppanel.add(pfill); -// ppanel.add(ptext); this.getContentPane().add(ppanel, "South"); this.pack(); } + /** + * Handles action events for the dialog's buttons. + * + * @param e the ActionEvent triggered by a button click + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.compareTo("Color") == 0) @@ -75,15 +91,21 @@ else if (command.compareTo("Cancel") == 0) this.setVisible(false); } + /** + * Retrieves the selected save type for PostScript. + * + * @return the save type (0: Color, 1: Gray, 2: Black and White, 3: Cancel) + */ int getSavePsType() { return type; } + /** + * Checks if the point fill option is selected. + * + * @return true if the point fill option is selected, false otherwise + */ boolean getPointfilled() { return pfill.isSelected(); } - -// boolean getisProveTextSaved() { -// return ptext.isSelected(); -// } } diff --git a/src/main/java/wprover/DrawBase.java b/src/main/java/wprover/DrawBase.java index 1b46d880..96435130 100644 --- a/src/main/java/wprover/DrawBase.java +++ b/src/main/java/wprover/DrawBase.java @@ -13,11 +13,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-2 - * Time: 21:27:59 - * To change this template use File | Settings | File Templates. + * DrawBase is a class that provides methods for drawing geometric objects and handling user interactions. + * It includes methods for drawing points, lines, circles, polygons, and other geometric shapes. + * It also provides methods for handling mouse events and managing the drawing environment. */ public class DrawBase { final public static int D_POINT = 1; @@ -122,7 +120,15 @@ public class DrawBase { protected GExpert gxInstance; protected Language lan; + protected boolean footMarkShown = CMisc.isFootMarkShown(); + protected double footMarkLength = CMisc.FOOT_MARK_LENGTH; + /** + * The POOL array contains the types of geometric objects and their parameters. + * Each entry in the array represents a different type of geometric object, + * with the first element being the type identifier and the subsequent elements + * representing the number of parameters required for that object. + */ final public static int[][] POOL = //1: pt //2. line 3. Circle. 4. LC (line or circle). { @@ -153,7 +159,6 @@ public class DrawBase { {D_CCLINE, 3, 3}, {D_IOSTRI, 1, 1}, {MIRROR, 4, 2}, -// {D_PFOOT, 1, 1}, {87, 1, 1, 4}, {43, 1}, {D_PTDISTANCE, 1, 1}, @@ -169,14 +174,17 @@ public class DrawBase { {75, 1, 1}, {82, 1, 1, 1, 1, 1, 1, 1, 1}, {81, 2, 1} - -// {29, 1, 1, 1, 4} -// {D_PFOOT, 1, 1} - - }; - + /** + * Returns the number of parameters for the specified geometric object type. + * For a polygon (\_D\_POLYGON), returns the current status if less than 10, otherwise 0. + * For other types, iterates through the POOL array and returns the parameter count. + * Returns -1 if the type is not found. + * + * @param a the geometric object type identifier + * @return the number of parameters for the object type, or -1 if not found + */ final public int getPooln(int a) { if (a == D_POLYGON) { if (STATUS < 10) @@ -192,6 +200,15 @@ final public int getPooln(int a) { return -1; } + /** + * Returns the parameter at a specific index for the given geometric object type. + * Iterates through the POOL array and returns the value at the specified index. + * If the index is out of bounds, returns 1. + * + * @param a the geometric object type identifier + * @param index the index of the parameter to retrieve + * @return the parameter value at the given index, or 1 if not found + */ public int getPoolA(int a, int index) { for (int i = 0; i < POOL.length; i++) { if (POOL[i][0] == a) { @@ -202,25 +219,57 @@ public int getPoolA(int a, int index) { return 1; } + /** + * Sets the language for the drawing environment. + * + * @param lan the Language instance to be set + */ public void setLanguage(Language lan) { this.lan = lan; } + /** + * Handles a button down event at the specified coordinates. + * The implementation depends on the current action. + * + * @param x the x-coordinate of the button down event + * @param y the y-coordinate of the button down event + */ public void DWButtonDown(double x, double y) { switch (CurrentAction) { } } + /** + * Sets the state indicating whether the mouse is inside the drawing area. + * + * @param t true if the mouse is inside, false otherwise + */ public void setMouseInside(boolean t) { mouseInside = t; } + /** + * Creates a temporary point with the specified coordinates. + * + * @param x the x-coordinate of the temporary point + * @param y the y-coordinate of the temporary point + * @return a new temporary CPoint instance + */ final public CPoint CreateATempPoint(double x, double y) { Param p1 = new Param(-1, x); Param p2 = new Param(-1, y); return new CPoint(CPoint.TEMP_POINT, p1, p2); } + /** + * Finds and returns an existing line that connects the two specified points. + * Returns null if no such line exists or if either point is null. + * + * @param p1 the first point + * @param p2 the second point + * @return the CLine connecting the two points, or null if not found + */ public CLine fd_line(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return null; @@ -234,6 +283,11 @@ public CLine fd_line(CPoint p1, CPoint p2) { return null; } + /** + * Sets the antialiasing rendering hint on the provided Graphics2D object based on the application setting. + * + * @param g2 the Graphics2D object on which to set the anti-aliasing + */ final public void setAntiAlias(Graphics2D g2) { if (CMisc.AntiAlias) { RenderingHints qualityHints = new RenderingHints(RenderingHints. @@ -249,21 +303,16 @@ final public void setAntiAlias(Graphics2D g2) { } } - void paint(Graphics2D g2) { - drawList(polygonlist, g2); - drawSelect(SelectList, g2); - drawPerpFoot(g2, null, 0); - drawList(tracelist, g2); - drawList(distancelist, g2); - drawList(anglelist, g2); - drawList(circlelist, g2); - drawList(linelist, g2); - drawList(pointlist, g2); - drawList(textlist, g2); - drawList(otherlist, g2); - drawCatch(g2); - } - + /** + * Draws the perpendicular footmarks for constraints. + * Iterates through the constraint list and draws the foot for each applicable constraint. + * Supports constraint types such as PERPENDICULAR, PFOOT, RIGHT\_ANGLED\_TRIANGLE, + * and RIGHT\_ANGLE\_TRAPEZOID. + * + * @param g2 the Graphics2D object used for drawing + * @param vlist a Vector used for additional drawing information + * @param type the mode type (0 for drawing and 1 for PostScript) + */ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: draw ,1: ps for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -328,11 +377,6 @@ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: dr CPoint p3 = (CPoint) cs.getelement(2); CPoint p4 = (CPoint) cs.getelement(3); -// drawTTFoot(type, vlist, g2, p1.getx(), p1.gety(), p1, p2, p4); -// drawTTFoot(type, vlist, g2, p2.getx(), p2.gety(), p2, p1, p3); -// drawTTFoot(type, vlist, g2, p3.getx(), p3.gety(), p3, p2, p4); -// drawTTFoot(type, vlist, g2, p4.getx(), p4.gety(), p4, p1, p3); - } break; case Constraint.RIGHT_ANGLED_TRIANGLE: { @@ -359,22 +403,44 @@ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: dr } + /** + * Removes the last n elements from the provided Vector. + * + * @param v the Vector from which elements will be removed + * @param n the number of elements to remove from the end + */ final public void removeFromeListLastNElements(Vector v, int n) { if (v.size() < n) return; while (n-- > 0) v.remove(v.size() - 1); } + /** + * Returns the number of points in the drawing. + * + * @return the size of the point list + */ final public int getPointSize() { return pointlist.size(); } + /** + * Returns a copy of the point list. + * + * @return a new Vector containing all points. + */ final public Vector getPointList() { Vector v = new Vector(); v.addAll(pointlist); return v; } + /** + * Draws all objects in the given list using the provided Graphics2D context. + * + * @param list the Vector containing drawable objects. + * @param g2 the Graphics2D object used for drawing. + */ final public void drawList(Vector list, Graphics2D g2) { if (list == null || list.size() == 0) { return; @@ -386,18 +452,33 @@ final public void drawList(Vector list, Graphics2D g2) { } } + /** + * Draws the name and coordinate location of a point. + * + * @param p the point whose location is displayed. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawPointNameLocation(CPoint p, Graphics2D g2) { g2.drawString("(x: " + ((int) p.getx()) + ", y: " + (int) p.gety() + ")", (int) p.getx() + 23, (int) p.gety() - 5); // FIXME: 23 and 5 seem hardcoded } + /** + * Sets the current drawing environment parameters such as color and stroke. + * + * @param g2 the Graphics2D object where the environment settings are applied. + */ final public void setCurrentDrawEnvironment(Graphics2D g2) { g2.setColor(DrawData.getCurrentColor()); g2.setStroke(CMisc.NormalLineStroke); } - + /** + * Draws the grid on the drawing area if grid drawing or snapping is enabled. + * + * @param g2 the Graphics2D context used for drawing the grid. + */ final public void drawGrid(Graphics2D g2) { if (!this.DRAWGRID && !SNAP) { return; @@ -424,6 +505,14 @@ final public void drawGrid(Graphics2D g2) { } + /** + * Draws a tip triangle marker based on the provided points. + * + * @param p1 the first point defining the triangle. + * @param p2 the second point defining the triangle. + * @param p the reference point for triangle alignment. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawTipTirangle(CPoint p1, CPoint p2, CPoint p, Graphics2D g2) { @@ -484,6 +573,14 @@ final public void drawTipTirangle(CPoint p1, CPoint p2, CPoint p, catchY = y2; } + /** + * Draws a cross centered at the given coordinates with the specified half-width. + * + * @param x the x-coordinate of the center. + * @param y the y-coordinate of the center. + * @param w the half-width of the cross. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawCross(int x, int y, int w, Graphics2D g2) { g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.0f)); @@ -491,6 +588,11 @@ final public void drawCross(int x, int y, int w, Graphics2D g2) { g2.drawLine(x + w, y - w, x - w, y + w); } + /** + * Draws a catch rectangle around the catch point if certain conditions are met. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchRect(Graphics2D g2) { if (!isPointOnObject || !mouseInside) return; int x = (int) CatchPoint.getx(); @@ -506,6 +608,11 @@ public void drawCatchRect(Graphics2D g2) { } } + /** + * Draws a cross marker to indicate an intersection catch point. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchInterCross(Graphics2D g2) { if (!isPointOnIntersection) return; int x = (int) CatchPoint.getx(); @@ -516,18 +623,23 @@ public void drawCatchInterCross(Graphics2D g2) { g2.drawString(GExpert.getLanguage("Intersection"), x + 10, y); } + /** + * Draws a tip rectangle around the specified coordinates. + * + * @param x the x-coordinate for the tip rectangle. + * @param y the y-coordinate for the tip rectangle. + * @param g2 the Graphics2D context used for drawing. + */ public void drawTipRect(int x, int y, Graphics2D g2) { g2.setColor(Color.red); this.drawRect(x - 5, y - 5, x + 5, y + 5, g2); } - public void drawCatchCross(Graphics2D g2) { - if (!isPointOnObject || !mouseInside) return; - int x = (int) CatchPoint.getx(); - int y = (int) CatchPoint.gety(); - drawCross(x, y, 5, g2); - } - + /** + * Draws either a point or a cross based on the object's state. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawPointOrCross(Graphics2D g2) { if (this.isPointOnObject) { if (!isPointOnIntersection) @@ -539,6 +651,11 @@ public void drawPointOrCross(Graphics2D g2) { } } + /** + * Draws the name of the caught object if exactly one object is caught. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchObjName(Graphics2D g2) { if (CatchList.size() != 1) return; @@ -552,6 +669,14 @@ public void drawCatchObjName(Graphics2D g2) { g2.drawString(s, MouseX + 16, MouseY + 20); } + /** + * Draws a tip square marker using the provided points. + * + * @param p1 the first point defining the square. + * @param p2 the second point defining the square. + * @param p the reference point used for adjusting the square. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawTipSquare(CPoint p1, CPoint p2, CPoint p, Graphics2D g2) { double x0 = p1.getx(); @@ -613,9 +738,18 @@ final public void drawTipSquare(CPoint p1, CPoint p2, CPoint p, } } - protected boolean footMarkShown = CMisc.isFootMarkShown(); - protected double footMarkLength = CMisc.FOOT_MARK_LENGTH; - + /** + * Draws two footmarks for a constraint between two lines. + * + * @param type the drawing mode (0 for direct drawing, non-zero for vector accumulation) + * @param vlist the vector list to add drawing points if not drawing directly + * @param g2 the Graphics2D context to draw on + * @param x the starting x coordinate for the footmark + * @param y the starting y coordinate for the footmark + * @param pc the common point for both lines (may be null) + * @param p1 the first point defining the first line + * @param p2 the second point defining the second line + */ public void drawTTFoot(int type, Vector vlist, Graphics2D g2, double x, double y, CPoint pc, CPoint p1, CPoint p2) { if (p1 == null || p2 == null) return; @@ -666,6 +800,14 @@ public void drawTTFoot(int type, Vector vlist, Graphics2D g2, double x, double y } } + /** + * Draws the catch indicator based on the current catch list and catch point. + * If no catch objects exist, draws smart horizontal/vertical catch lines. + * If one object exists, draws it with its predefined style. + * If multiple objects exist, displays a prompt for selection. + * + * @param g2 the Graphics2D context to draw on + */ public void drawCatch(Graphics2D g2) { int size = CatchList.size(); @@ -709,11 +851,25 @@ public void drawCatch(Graphics2D g2) { } + /** + * Checks if a line connecting the two given points is drawn. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line exists and is drawn; false otherwise + */ public boolean isLineDrawn(CPoint p1, CPoint p2) { CLine ln = this.fd_line(p1, p2); return ln != null && ln.isdraw(); } + /** + * Draws the selection highlight for a list of geometric objects. + * Iterates over the list and draws each object with selection indication. + * + * @param list the list of objects to be highlighted + * @param g2 the Graphics2D context to use for drawing + */ public void drawSelect(Vector list, Graphics2D g2) { for (int i = 0; i < list.size(); i++) { CClass cc = (CClass) list.get(i); @@ -722,7 +878,16 @@ public void drawSelect(Vector list, Graphics2D g2) { } } - + /** + * Draws a rectangle defined by two opposite corner coordinates. + * Four lines are drawn between the specified corners. + * + * @param x the x coordinate of the first corner + * @param y the y coordinate of the first corner + * @param x1 the x coordinate of the opposite corner + * @param y1 the y coordinate of the opposite corner + * @param g2 the Graphics2D context for drawing + */ public void drawRect(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x, y, x1, y); g2.drawLine(x, y, x, y1); @@ -730,30 +895,61 @@ public void drawRect(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x1, y, x1, y1); } - + /** + * Draws a circle defined by two points. + * The first point represents the center and the distance to the + * second point determines the radius. + * + * @param x1 the x coordinate of the center + * @param y1 the y coordinate of the center + * @param x2 the x coordinate of a point on the circle + * @param y2 the y coordinate of a point on the circle + * @param g2 the Graphics2D context for drawing + */ public void drawcircle2p(double x1, double y1, double x2, double y2, Graphics2D g2) { int r = (int) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); g2.drawOval((int) (x1 - r), (int) (y1 - r), 2 * r, 2 * r); } - + /** + * Draws the specified point using its own drawing method. + * + * @param p the point to be drawn + * @param g2 the Graphics2D context for drawing + */ public void drawpoint(CPoint p, Graphics2D g2) { p.draw(g2); } + /** + * Adds the specified line to the list of lines if it is not already present. + * + * @param ln the line to be added + */ public void addLine(CLine ln) { if (!linelist.contains(ln)) { linelist.add(ln); } } + /** + * Adds the specified circle to the list of circles if it is not already present. + * + * @param c the circle to add + */ public void addCircle(Circle c) { if (!circlelist.contains(c)) { circlelist.add(c); } } + /** + * Searches for a point with the given name in the point list. + * + * @param name the name of the point to search for + * @return the point with the specified name, or null if not found + */ public CPoint findPoint(String name) { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -764,6 +960,16 @@ public CPoint findPoint(String name) { return null; } + /** + * Finds a circle defined by a center point and a point on its circumference. + * + * Searches the circle list for a circle where the first point is the center and + * the second point lies on the circle. + * + * @param p1 the potential center point of the circle + * @param p2 the potential point on the circumference + * @return the matching circle if found; otherwise, null + */ public Circle fd_circle(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return null; @@ -779,7 +985,11 @@ public Circle fd_circle(CPoint p1, CPoint p2) { } - + /** + * Returns the count of Cedmark objects present in otherlist. + * + * @return the number of Cedmark marks in otherlist. + */ int getEMarkNum() { int k = 0; for (int i = 0; i < otherlist.size(); i++) { @@ -790,6 +1000,11 @@ int getEMarkNum() { return k; } + /** + * Calculates and returns the bounding rectangle that encompasses all points, circles, and text elements. + * + * @return the bounding Rectangle of the drawing. + */ public Rectangle getBounds() { Rectangle rc = new Rectangle(0, 0, 0, 0); @@ -867,6 +1082,14 @@ public Rectangle getBounds() { return rc; } + /** + * Checks if three points are collinear. + * + * @param p1 the first point. + * @param p2 the second point. + * @param p3 the third point. + * @return true if the points are collinear, false otherwise. + */ static boolean check_Collinear(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -875,16 +1098,46 @@ static boolean check_Collinear(CPoint p1, CPoint p2, CPoint p3) { (p2.gety() - p1.gety()) * (p3.getx() - p2.getx())); } + /** + * Checks if the three points defined by their coordinates are collinear. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @return true if the points are collinear, false otherwise. + */ static boolean check_Collinear(double x1, double y1, double x2, double y2, double x3, double y3) { return isZero((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2)); } + /** + * Computes the signed area determined by three points. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @return the signed area value. + */ public static double signArea(double x1, double y1, double x2, double y2, double x3, double y3) { return (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2); } + /** + * Determines if a point lies between two other collinear points. + * + * @param p1 the first endpoint. + * @param p2 the second endpoint. + * @param p3 the point to check. + * @return true if p3 lies between p1 and p2, false otherwise. + */ static boolean check_between(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -898,12 +1151,28 @@ static boolean check_between(CPoint p1, CPoint p2, CPoint p3) { } + /** + * Checks if two lines are parallel. + * + * @param ln1 the first line. + * @param ln2 the second line. + * @return true if the lines are parallel, false otherwise. + */ static boolean check_para(CLine ln1, CLine ln2) { double k1 = ln1.getK(); double k2 = ln2.getK(); return isZero(k1 - k2); } + /** + * Checks if two pairs of points define parallel lines. + * + * @param p1 the first point of the first line. + * @param p2 the second point of the first line. + * @param p3 the first point of the second line. + * @param p4 the second point of the second line. + * @return true if the defined lines are parallel, false otherwise. + */ static boolean check_para(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -912,6 +1181,15 @@ static boolean check_para(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { (p2.gety() - p1.gety()) * (p4.getx() - p3.getx())); } + /** + * Checks if two lines, defined by two pairs of points, are perpendicular. + * + * @param p1 the first point of the first line. + * @param p2 the second point of the first line. + * @param p3 the first point of the second line. + * @param p4 the second point of the second line. + * @return true if the lines are perpendicular, false otherwise. + */ static boolean check_perp(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -920,6 +1198,14 @@ static boolean check_perp(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { (p2.gety() - p1.gety()) * (p4.gety() - p3.gety()))); } + /** + * Checks if a point is the midpoint of two other points. + * + * @param p the point to check. + * @param p1 the first endpoint. + * @param p2 the second endpoint. + * @return true if p is the midpoint of p1 and p2, false otherwise. + */ static boolean check_mid(CPoint p, CPoint p1, CPoint p2) { if (p == null || p1 == null || p2 == null) { return false; @@ -927,6 +1213,15 @@ static boolean check_mid(CPoint p, CPoint p1, CPoint p2) { return check_Collinear(p1, p2, p) && check_eqdistance(p, p1, p, p2); } + /** + * Determines if four points are concyclic, i.e., lie on the same circle. + * + * @param p1 the first point. + * @param p2 the second point. + * @param p3 the third point. + * @param p4 the fourth point. + * @return true if the four points are concyclic, false otherwise. + */ static boolean check_cyclic(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -949,6 +1244,15 @@ static boolean check_cyclic(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return isZero(t1 - t2) && isZero(t2 - t3) && isZero(t3 - t4); } + /** + * Checks if the distances between the first pair of points and the second pair of points are equal. + * + * @param p1 the first point of the first pair. + * @param p2 the second point of the first pair. + * @param p3 the first point of the second pair. + * @param p4 the second point of the second pair. + * @return true if the distances are equal, false otherwise. + */ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -956,11 +1260,35 @@ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return isZero(sdistance(p1, p2) - sdistance(p3, p4)); } + /** + * Checks if the distance between two points defined by coordinates is equal to the distance between another two points. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @param x4 the x-coordinate of the fourth point. + * @param y4 the y-coordinate of the fourth point. + * @return true if the computed distances are equal, false otherwise. + */ static boolean check_eqdistance(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { return isZero(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) - Math.pow(x3 - x4, 2) - Math.pow(y3 - y4, 2)); } + /** + * Checks if the distance between two pairs of points, scaled by given factors, are equal. + * + * @param p1 the first point of the first pair. + * @param p2 the second point of the first pair. + * @param p3 the first point of the second pair. + * @param p4 the second point of the second pair. + * @param t1 the scaling factor for the first pair. + * @param t2 the scaling factor for the second pair. + * @return true if the scaled distances are equal, false otherwise. + */ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4, int t1, int t2) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -968,6 +1296,17 @@ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4, int return isZero(sdistance(p1, p2) * t2 - sdistance(p3, p4) * t1); } + /** + * Checks if the angles formed by three points in two sets are equal. + * + * @param p1 the first point of the first angle. + * @param p2 the vertex of the first angle. + * @param p3 the third point of the first angle. + * @param p4 the first point of the second angle. + * @param p5 the vertex of the second angle. + * @param p6 the third point of the second angle. + * @return true if the angles are equal, false otherwise. + */ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -977,6 +1316,19 @@ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint return isZero(t1 - t2); } + /** + * Checks if the angles defined by four points in two sets are equal. + * + * @param p1 the first point of the first angle. + * @param p2 the second point of the first angle. + * @param p3 the third point of the first angle. + * @param p4 the fourth point used with the first angle calculation. + * @param p5 the first point of the second angle. + * @param p6 the second point of the second angle. + * @param p7 the third point of the second angle. + * @param p8 the fourth point used with the second angle calculation. + * @return true if the angles are equal, false otherwise. + */ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6, CPoint p7, CPoint p8) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || p6 == null || p7 == null || p8 == null) { return false; @@ -986,7 +1338,15 @@ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint return isZero(t1 - t2); } - + /** + * Checks if points p3 and p4 lie on the same side of the line defined by p1 and p2. + * + * @param p1 first point defining the line + * @param p2 second point defining the line + * @param p3 first point to test + * @param p4 second point to test + * @return true if p3 and p4 are on the same side of the line; false otherwise + */ public static boolean check_same_side(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p4 == null || p1 == null || p2 == null || p3 == null) { return false; @@ -994,12 +1354,29 @@ public static boolean check_same_side(CPoint p1, CPoint p2, CPoint p3, CPoint p4 return collv(p1, p2, p3) * collv(p1, p2, p4) > 0; } + /** + * Computes the cross product of vectors AB and AC. + * + * @param A the starting point + * @param B the end point of the first vector + * @param C the end point of the second vector + * @return the cross product value + */ public static double collv(CPoint A, CPoint B, CPoint C) { double d1 = (B.getx() - A.getx()) * (C.gety() - A.gety()) - (B.gety() - A.gety()) * (C.getx() - A.getx()); return d1; } + /** + * Determines if point p lies inside the triangle defined by p1, p2, and p3. + * + * @param p the point to test + * @param p1 first vertex of the triangle + * @param p2 second vertex of the triangle + * @param p3 third vertex of the triangle + * @return true if p is inside the triangle; false otherwise + */ public static boolean check_triangle_inside(CPoint p, CPoint p1, CPoint p2, CPoint p3) { if (p == null || p1 == null || p2 == null || p3 == null) { return false; @@ -1013,16 +1390,17 @@ public static boolean check_triangle_inside(CPoint p, CPoint p1, CPoint p2, CPoi } - public static double areaTriangle(CPoint p1, CPoint p2, CPoint p3) { - double a = DrawBase.sdistance(p1, p2); - double b = DrawBase.sdistance(p1, p3); - double c = DrawBase.sdistance(p3, p2); - - return Math.sqrt(a * a * c * c - Math.pow(a * a + c * c - b * b, 2) / 4); - - - } - + /** + * Compares two angles defined by sets of three points. + * + * @param p1 first angle's first point + * @param p2 vertex of the first angle + * @param p3 first angle's third point + * @param p4 second angle's first point + * @param p5 vertex of the second angle + * @param p6 second angle's third point + * @return true if the absolute value of the first angle is greater than that of the second; false otherwise + */ static boolean check_angle_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -1032,6 +1410,15 @@ static boolean check_angle_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoi return Math.abs(t1) > Math.abs(t2); } + /** + * Compares the distances between two pairs of points. + * + * @param p1 first point of the first pair + * @param p2 second point of the first pair + * @param p3 first point of the second pair + * @param p4 second point of the second pair + * @return true if the distance between p1 and p2 is less than the distance between p3 and p4; false otherwise + */ static boolean check_distance_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -1039,6 +1426,14 @@ static boolean check_distance_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return (sdistance(p1, p2) < sdistance(p3, p4)); } + /** + * Checks if point p1 is equidistant from points p2 and p3. + * + * @param p1 the point to test + * @param p2 first end of the segment + * @param p3 second end of the segment + * @return true if p1 is equidistant to p2 and p3; false otherwise + */ static boolean check_bisect(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -1046,6 +1441,17 @@ static boolean check_bisect(CPoint p1, CPoint p2, CPoint p3) { return isZero(sdistance(p1, p2) - sdistance(p1, p3)); } + /** + * Determines if two triangles are similar by comparing the ratios of their corresponding sides. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are similar; false otherwise + */ static boolean check_simtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || @@ -1064,6 +1470,17 @@ static boolean check_simtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, return isZero(t1 - t2) && isZero(t1 - t3) && isZero(t2 - t3); } + /** + * Determines if two triangles are congruent by comparing the lengths of their corresponding sides. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are congruent; false otherwise + */ static boolean check_congtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || @@ -1080,23 +1497,28 @@ static boolean check_congtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, return isZero(r1 - r4) && isZero(r2 - r5) && isZero(r3 - r6); } - static boolean check_lc_tangent(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return false; - } - - static boolean check_cc_tangent(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return isZero(sdistance(p1, p2) - sdistance(p3, p4)); - } - + /** + * Calculates the Euclidean distance between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the distance between p1 and p2 + */ static double sdistance(CPoint p1, CPoint p2) { return Math.sqrt(Math.pow(p1.getx() - p2.getx(), 2) + Math.pow(p1.gety() - p2.gety(), 2)); } - static boolean nearPt(double x, double y, CPoint pt) { - return Math.abs(x - pt.getx()) < CMisc.PIXEPS && Math.abs(y - pt.gety()) < CMisc.PIXEPS; - } - - + /** + * Computes an adjusted midpoint on the line defined by (x1, y1) and (x2, y2) based on the direction from the line's midpoint to (x, y). + * + * @param x1 the x-coordinate of the first point on the line + * @param y1 the y-coordinate of the first point on the line + * @param x2 the x-coordinate of the second point on the line + * @param y2 the y-coordinate of the second point on the line + * @param x the x-coordinate of the external reference point + * @param y the y-coordinate of the external reference point + * @return a two-element array containing the computed x and y coordinates + */ double[] get_pt_dmcr(double x1, double y1, double x2, double y2, double x, double y) { double dis = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); @@ -1129,6 +1551,13 @@ static boolean nearPt(double x, double y, CPoint pt) { return r; } + /** + * Computes the intersection points between a line and a circle. + * + * @param ln the line + * @param cr the circle + * @return an array containing intersection coordinates; an empty array if there is no intersection + */ double[] intersect_lc(CLine ln, Circle cr) { double r2 = cr.getRadius(); r2 *= r2; @@ -1178,6 +1607,13 @@ static boolean nearPt(double x, double y, CPoint pt) { } } + /** + * Computes the intersection point of two lines. + * + * @param ln1 the first line + * @param ln2 the second line + * @return a two-element array with the x and y coordinates of the intersection, or null if undefined + */ public double[] intersect_ll(CLine ln1, CLine ln2) { CPoint p1 = ln1.getfirstPoint(); double k1 = ln1.getK(); @@ -1205,6 +1641,13 @@ public double[] intersect_ll(CLine ln1, CLine ln2) { return r; } + /** + * Computes the intersection points of two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return an array containing the intersection coordinates; null if there is no intersection + */ public double[] intersect_cc(Circle c1, Circle c2) { double r1 = c1.getRadius(); CPoint o1 = c1.o; @@ -1249,7 +1692,13 @@ public double[] intersect_cc(Circle c1, Circle c2) { } - + /** + * Checks if two circles intersect based on their radii and center distance. + * + * @param c1 the first circle + * @param c2 the second circle + * @return true if the circles intersect within the defined tolerance + */ protected boolean check_cc_inter(Circle c1, Circle c2) { double r1 = c1.getRadius(); double r2 = c2.getRadius(); @@ -1263,24 +1712,48 @@ protected boolean check_cc_inter(Circle c1, Circle c2) { } + /** + * Checks if a line and a circle intersect. + * + * @param ln the line + * @param c2 the circle + * @return true if the line intersects the circle + */ protected boolean check_lc_inter(CLine ln, Circle c2) { double r1 = ln.distance(c2.getCenterOX(), c2.getCenterOY()); double r2 = c2.getRadius(); return (r2 - r1) > 0; } + /** + * Determines if a given value is effectively zero within a tolerance. + * + * @param r the value to check + * @return true if the value is considered zero + */ protected static boolean isZero(double r) { return Math.abs(r) < CMisc.ZERO; } + /** + * Checks whether two coordinates are nearly equal based on a tolerance. + * + * @param x the first x-coordinate + * @param y the first y-coordinate + * @param x1 the second x-coordinate + * @param y1 the second y-coordinate + * @return true if the points are near each other + */ protected static boolean near(double x, double y, double x1, double y1) { return Math.abs(Math.pow(x - x1, 2) + Math.pow(y - y1, 2)) < CMisc.PIXEPS * CMisc.PIXEPS; } - public static void set_eps(double r) { - } - - + /** + * Retrieves an array of points extracted from the given construct. + * + * @param c the construct containing point identifiers + * @return an array of points, or null if a point cannot be found + */ protected CPoint[] getPoints(Cons c) { CPoint[] pp = new CPoint[8]; @@ -1300,20 +1773,12 @@ protected CPoint[] getPoints(Cons c) { return pp; } -// public int dxindex(int n) -// { -// gt -// } -// -// public TMono getTMono(cndg d) -// { -// if(d == null) -// return null; -// -// - - // } - + /** + * Builds a TMono object that represents a geometric relation based on the construct. + * + * @param c the construct defining the relation + * @return the constructed TMono object, or null if it cannot be built + */ protected TMono getTMono(Cons c) { if (c == null) return null; @@ -1366,6 +1831,13 @@ protected TMono getTMono(Cons c) { return m; } + /** + * Determines whether two points are identical by comparing their Wu representations. + * + * @param p1 the first point + * @param p2 the second point + * @return true if both points are considered identical + */ public boolean decide_wu_identical(CPoint p1, CPoint p2) { TMono m1 = poly.ppdd(p1.x1.xindex, p2.x1.xindex); //poly.pdif(poly.pcopy(p1.x1.m), poly.pcopy(p2.x1.m)); @@ -1374,6 +1846,12 @@ public boolean decide_wu_identical(CPoint p1, CPoint p2) { } + /** + * Checks if the given TMono reduces to zero relative to the polynomial set. + * + * @param m1 the TMono expression to check + * @return true if the expression is effectively zero within the polynomial context + */ public boolean div_set(TMono m1) { if (m1 == null) return true; @@ -1413,6 +1891,11 @@ public boolean div_set(TMono m1) { return false; } + /** + * Prints the polynomial represented by the TPoly chain. + * + * @param p the TPoly instance containing the polynomial + */ public void printPoly(TPoly p) { while (p != null) { poly.printpoly(p.getPoly()); @@ -1420,18 +1903,15 @@ public void printPoly(TPoly p) { } } - - public boolean verify_ndg(TMono m) { - if (m == null) - return true; - TPoly p1 = polylist; - if (poly.pzerop(m)) - return false; - - - return true; - } - + /** + * Searches for a CTMark based on two pairs of points. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return the CTMark if found, otherwise null + */ public CTMark findCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < otherlist.size(); i++) { CClass c = (CClass) otherlist.get(i); @@ -1447,6 +1927,15 @@ public CTMark findCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return null; } + /** + * Determines if a tmark exists that contains the specified four points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if a matching tmark is found + */ public boolean find_tmark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -1459,6 +1948,11 @@ public boolean find_tmark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return false; } + /** + * Checks if there is at least one freezed point in the diagram. + * + * @return true if any point is freezed, otherwise false + */ public boolean containFreezedPoint() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1469,6 +1963,9 @@ public boolean containFreezedPoint() { return false; } + /** + * Unfreezes all points in the diagram. + */ public void unfreezeAllPoints() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1478,6 +1975,11 @@ public void unfreezeAllPoints() { } } + /** + * Determines if the diagram is in a frozen state. + * + * @return true if any point is freezed, indicating the diagram is frozen + */ public boolean isFrozen() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1489,6 +1991,13 @@ public boolean isFrozen() { return false; } + /** + * Zooms out the diagram from a specified center by adjusting the points. + * + * @param x the x-coordinate of the zoom center + * @param y the y-coordinate of the zoom center + * @param zz the zoom factor denominator + */ public void zoom_out(double x, double y, int zz) { if (isFrozen()) @@ -1503,6 +2012,13 @@ public void zoom_out(double x, double y, int zz) { } } + /** + * Zooms in the diagram from a specified center by adjusting the points. + * + * @param x the x-coordinate of the zoom center + * @param y the y-coordinate of the zoom center + * @param zz the zoom factor denominator + */ public void zoom_in(double x, double y, int zz) { if (isFrozen()) return; @@ -1515,6 +2031,9 @@ public void zoom_in(double x, double y, int zz) { } } + /** + * Adjusts the catch point type by examining proximity to other points. + */ public void hvCatchPoint() { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -1536,6 +2055,12 @@ public void hvCatchPoint() { } } + /** + * Retrieves a horizontal or vertical catch point based on the catch type. + * + * @param CatchType the catch type indicator (2 for vertical, 3 for horizontal) + * @return the catch point if found, otherwise null + */ public CPoint getCatchHVPoint(int CatchType) { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -1550,6 +2075,11 @@ public CPoint getCatchHVPoint(int CatchType) { return null; } + /** + * Adjusts the provided point to align with a nearby point based on the catch type. + * + * @param pv the point to be adjusted + */ public void setCatchHVPoint(CPoint pv) { if (CatchType != 2 && CatchType != 3 && CatchType != 4) return; @@ -1568,6 +2098,4 @@ public void setCatchHVPoint(CPoint pv) { } } } - - } diff --git a/src/main/java/wprover/DrawData.java b/src/main/java/wprover/DrawData.java index 057571cc..16de568a 100644 --- a/src/main/java/wprover/DrawData.java +++ b/src/main/java/wprover/DrawData.java @@ -8,11 +8,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-2 - * Time: 20:40:39 - * To change this template use File | Settings | File Templates. + * DrawData is a utility class that manages color, dash, and width configurations for drawing operations. + * It provides methods to add colors, retrieve color and dash values, and save/load configurations. */ public class DrawData { public static int RED = 3; @@ -20,6 +17,20 @@ public class DrawData { public static int WIDTH2 = 2; public static int LIGHTCOLOR = 18; + public static int cindex = 0; + public static int dindex = 0; + public static int windex = 2; + + final public static int pointcolor = 3; + final public static int pointcolor_half_decided = 5; + final public static int pointcolor_decided = 14; + + public static int polygoncolor = 17; + public static int anglecolor = 3; + public static int anglewidth = 2; + public static int angledash = 0; + public static int tractcolor = 3; + private static DrawData dd = new DrawData(); private static int cnum; @@ -29,7 +40,9 @@ public class DrawData { int default_color_num; - + /** + * Constructs a new DrawData instance and initializes default color, dash, and width lists. + */ private DrawData() { Color[] color = { Color.blue, @@ -85,14 +98,21 @@ private DrawData() { } } - public static int getDefaultColorCount() { - return dd.default_color_num; - } - + /** + * Returns the number of available widths. + * + * @return the total width count + */ public static int getWidthCounter() { return dd.widthlist.size(); } + /** + * Returns the width value at the specified index. + * + * @param index the index of the width value to retrieve + * @return the width value as a double + */ public static double getWidth(int index) { double d; try { @@ -103,10 +123,21 @@ public static double getWidth(int index) { return d; } + /** + * Returns the number of available dash configurations. + * + * @return the total dash count + */ public static int getDashCounter() { return dd.dashlist.size(); } + /** + * Returns the dash value at the specified index. + * + * @param index the index of the dash value to retrieve + * @return the dash value as a double + */ public static double getDash(int index) { double d; try { @@ -117,30 +148,43 @@ public static double getDash(int index) { return d; } - + /** + * Returns the number of available colors. + * + * @return the total color count + */ public static int getColorCounter() { return dd.colorlist.size(); } - public static int getNextColor(int n) { - return n % getColorCounter(); - } - + /** + * Returns a color offset from the default angle color. + * + * @param n the offset from the angle color index + * @return the calculated Color object + */ public static Color getColorSinceRed(int n) { return getColor(anglecolor + n); } + /** + * Returns the color corresponding to the given index. The index wraps around the color list. + * + * @param index the index of the color to retrieve + * @return the Color object, or null if index is negative + */ public static Color getColor(int index) { int n = dd.colorlist.size(); if (index < 0 ) return null; return (Color) (dd.colorlist.get(index % n)); } - public static Color getCtColor(int index) { - Color c = (Color) (dd.colorlist.get(index)); - return new Color(255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue()); - } - + /** + * Adds a new color to the color list if it is not already present. + * + * @param co the Color to add + * @return the new total count of colors, or the existing index plus one if already present + */ public static int addColor(Color co) { for (int i = 0; i < dd.colorlist.size(); i++) { Color c = (Color) dd.colorlist.get(i); @@ -152,30 +196,18 @@ public static int addColor(Color co) { return dd.colorlist.size(); } - //////////////////////////////////////////////////////////////////////// - - - - public static int cindex = 0; - public static int dindex = 0; - public static int windex = 2; - - final public static int pointcolor = 3; - final public static int pointcolor_half_decided = 5; - final public static int pointcolor_decided = 14; - - public static int polygoncolor = 17; - public static int anglecolor = 3; - public static int anglewidth = 2; - public static int angledash = 0; - public static int tractcolor = 3; - + /** + * Resets the color, dash, and width indices to the default status. + */ public static void setDefaultStatus() { cindex = 0; dindex = 0; windex = 2; } + /** + * Sets the color, dash, and width indices to the prove status. + */ public static void setProveStatus() { cindex = 3; dindex = 9; @@ -183,17 +215,21 @@ public static void setProveStatus() { } + /** + * Sets the color, dash, and width indices to the auxiliary status. + */ public static void setAuxStatus() { cindex = RED; dindex = DASH8; windex = 2; } - public static void setDefaultColor(int id) { - if (id < 0) return; - cindex = id; - } - + /** + * Returns the index of the specified color in the color list. + * + * @param color the Color to search for + * @return the index of the color, or -1 if not found + */ public static int getColorIndex(Color color) { for (int i = 0; i < dd.colorlist.size(); i++) { Color c = (Color) dd.colorlist.get(i); @@ -203,23 +239,32 @@ public static int getColorIndex(Color color) { return -1; } + /** + * Returns the current color based on the current color index. + * + * @return the current Color object + */ public static Color getCurrentColor() { return getColor(cindex); } - public static void setDefaultPolygonColor(int index) { - polygoncolor = index; - } - + /** + * Resets the DrawData instance by reinitializing it to default values. + */ public static void reset() { dd = new DrawData(); } - - - ///////////////////////////////////////////////////////////////////// - - + /** + * Saves the color, dash, and width configuration to the specified PostScript file. + * + * @param vc the vector containing color indices + * @param vd the vector containing dash indices + * @param vw the vector containing width indices + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs while writing + */ public static void SavePS(Vector vc, Vector vd, Vector vw, FileOutputStream fp, int stype) throws IOException { fp.write("%-----define color, dash and width\n".getBytes()); @@ -277,7 +322,12 @@ public static void SavePS(Vector vc, Vector vd, Vector vw, FileOutputStream fp, } } - + /** + * Saves additional color configurations to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs while writing + */ public static void Save(DataOutputStream out) throws IOException { int size = dd.colorlist.size(); out.writeInt(size); @@ -290,6 +340,13 @@ public static void Save(DataOutputStream out) throws IOException { } } + /** + * Loads color configurations from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the DrawProcess instance used for object mapping + * @throws IOException if an I/O error occurs while reading + */ public static void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { int size = in.readInt(); @@ -329,7 +386,6 @@ public static void Load(DataInputStream in, DrawProcess dp) throws IOException { } } } - } diff --git a/src/main/java/wprover/DrawProcess.java b/src/main/java/wprover/DrawProcess.java index 21e9c9eb..8878c71e 100644 --- a/src/main/java/wprover/DrawProcess.java +++ b/src/main/java/wprover/DrawProcess.java @@ -24,9 +24,11 @@ import maths.CharSet; import org.w3c.dom.*; - -public class -DrawProcess extends DrawBase implements Printable, ActionListener { +/** + * DrawProcess is a class that handles the drawing and processing of geometric objects. + * It extends the DrawBase class and implements the Printable and ActionListener interfaces. + */ +public class DrawProcess extends DrawBase implements Printable, ActionListener { final public static int SELECT = 0; @@ -109,62 +111,99 @@ private int save_id = CMisc.id_count; private int CAL_MODE = 0; // 0: MOVEMODE. 1. CAL - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - protected GTerm gt; protected int nd = 1; - //////////////// protected UndoStruct U_Obj = null; protected boolean status = true; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Toggles the status state. + */ public void stateChange() { status = !status; } + /** + * Sets the calculation mode to 1. + */ public void setCalMode1() { CAL_MODE = 1; } + /** + * Sets the calculation mode to 0. + */ public void setCalMode0() { CAL_MODE = 0; } + /** + * Retrieves the GTerm object. + * + * @return the GTerm object + */ public GTerm gterm() { if (gt == null) gt = gxInstance.getpprove().getConstructionTerm(); return gt; } + /** + * Clears the construction and resets the nd value. + */ public void clearConstruction() { gt = null; nd = 1; } + /** + * Resets the current undo structure's ID to the current ID count. + */ public void resetUndo() { this.currentUndo.id = CMisc.id_count; } + /** + * Retrieves the name of the current object. + * + * @return the name of the current object + */ public String getName() { return this.name; } + /** + * Sets the recalculation flag. + * + * @param r the recalculation flag to set + */ public void setRecal(boolean r) { isRecal = r; } + /** + * Sets the name of the current object. + * + * @param s the name to set + */ public void setName(String s) { this.name = s; } + /** + * Stops tracking the current point. + */ public void stopTrack() { CTrackPt = null; } + /** + * Starts tracking a given point. + * + * @param pt the point to start tracking + */ public void startTrackPt(CPoint pt) { - CTrackPt = pt; boolean r = false; @@ -173,7 +212,6 @@ public void startTrackPt(CPoint pt) { if (tr.isTracePt(CTrackPt)) { r = true; break; - } } if (!r) { @@ -181,10 +219,15 @@ public void startTrackPt(CPoint pt) { this.addObjectToList(t, tracelist); this.UndoAdded(t.toString()); } - } + /** + * Retrieves a parameter by its index. + * + * @param index the index of the parameter to retrieve + * @return the parameter with the specified index, or null if not found + */ public Param getParameterByindex(int index) { for (int i = 0; i < paraCounter - 1; i++) { if (parameter[i].xindex == index) { @@ -194,21 +237,42 @@ public Param getParameterByindex(int index) { return null; } + /** + * Retrieves the last constructed point. + * + * @return the last constructed point, or null if no points exist + */ public CPoint getLastConstructedPoint() { if (pointlist.size() <= 0) return null; return (CPoint) pointlist.get(pointlist.size() - 1); } + /** + * Retrieves a point by its ID. + * + * @param id the ID of the point to retrieve + * @return the point with the specified ID, or null if not found + */ public CPoint getPointById(int id) { return (CPoint) this.getObjectInListById(id, pointlist); } - + /** + * Retrieves all constraints. + * + * @return a vector containing all constraints + */ public Vector getAllConstraint() { return constraintlist; } + /** + * Retrieves a constraint by its ID. + * + * @param id the ID of the constraint to retrieve + * @return the constraint with the specified ID, or null if not found + */ public Constraint getConstraintByid(int id) { for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -219,24 +283,51 @@ public Constraint getConstraintByid(int id) { return null; } + /** + * Retrieves a line by its ID. + * + * @param id the ID of the line to retrieve + * @return the line with the specified ID, or null if not found + */ public CLine getLineByid(int id) { return (CLine) this.getObjectInListById(id, linelist); } + /** + * Retrieves a circle by its ID. + * + * @param id the ID of the circle to retrieve + * @return the circle with the specified ID, or null if not found + */ public Circle getCircleByid(int id) { return (Circle) this.getObjectInListById(id, circlelist); } - + /** + * Retrieves a trace by its ID. + * + * @param id the ID of the trace to retrieve + * @return the trace with the specified ID, or null if not found + */ public CTrace getTraceById(int id) { return (CTrace) this.getObjectInListById(id, tracelist); } - + /** + * Retrieves an angle by its ID. + * + * @param id the ID of the angle to retrieve + * @return the angle with the specified ID, or null if not found + */ public CAngle getAngleByid(int id) { return (CAngle) this.getObjectInListById(id, anglelist); } + /** + * Retrieves all solid objects. + * + * @return a vector containing all solid objects + */ public Vector getAllSolidObj() { Vector v = new Vector(); int n = CMisc.id_count + 1; @@ -253,6 +344,12 @@ public Vector getAllSolidObj() { return v; } + /** + * Retrieves an object by its ID. + * + * @param id the ID of the object to retrieve + * @return the object with the specified ID, or null if not found + */ public CClass getOjbectById(int id) { CClass cc = this.getObjectInListById(id, pointlist); if (cc != null) { @@ -290,6 +387,13 @@ public CClass getOjbectById(int id) { return cc; } + /** + * Retrieves an object from a list by its ID. + * + * @param id the ID of the object to retrieve + * @param v the list to search + * @return the object with the specified ID, or null if not found + */ public CClass getObjectInListById(int id, Vector v) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); @@ -298,9 +402,14 @@ public CClass getObjectInListById(int id, Vector v) { } } return null; - } + /** + * Retrieves an UndoStruct object by its ID. + * + * @param id the ID of the UndoStruct to retrieve + * @return the UndoStruct object with the specified ID, or null if not found + */ public UndoStruct getUndoById(int id) { for (int i = 0; i < undolist.size(); i++) { UndoStruct cc = (UndoStruct) undolist.get(i); @@ -314,27 +423,28 @@ public UndoStruct getUndoById(int id) { return null; } - public void SetProportionLineAction(int prop) { - - this.SetCurrentAction(DrawProcess.LRATIO); - this.proportion = prop; - - } - + /** + * Adds a DiagramUpdater listener to the list of updater listeners. + * + * @param d the DiagramUpdater listener to add + */ public void addDiagramUpdaterListener(DiagramUpdater d) { if (!updaterListeners.contains(d)) updaterListeners.add(d); } + /** + * Removes a DiagramUpdater listener from the list of updater listeners. + * + * @param d the DiagramUpdater listener to remove + */ public void RemoveDiagramUpdaterListener(DiagramUpdater d) { updaterListeners.remove(d); } - public void SetActionWithPropotion(int action, int prop) { - this.SetCurrentAction(action); - this.proportion = prop; - } - + /** + * Clears all geometric objects and resets the drawing state. + */ public void clearAll() { CurrentAction = SELECT; SelectList.clear(); @@ -362,7 +472,6 @@ public void clearAll() { pSolution = null; solutionlist.clear(); -// trackPoint = null; undolist.clear(); redolist.clear(); CMisc.id_count = 1; @@ -400,66 +509,120 @@ public void clearAll() { name = ""; CAL_MODE = 0; status = true; - } + /** + * Sets the saved tag to indicate that the current state is saved. + */ public void setSavedTag() { needSave = false; save_id = CMisc.id_count; } + /** + * Checks if the current state is saved. + * + * @return true if the current state is saved, false otherwise + */ public boolean isitSaved() { return needSave || save_id >= CMisc.id_count; } + /** + * Retrieves the AnimateC object. + * + * @return the AnimateC object + */ public AnimateC getAnimateC() { return animate; } + /** + * Retrieves the current file. + * + * @return the current file + */ public File getFile() { return file; } + /** + * Sets the current file. + * + * @param f the file to set + */ public void setFile(File f) { file = f; } - + /** + * Retrieves the list of selected objects. + * + * @return the list of selected objects + */ public Vector getSelectList() { return SelectList; } + /** + * Sets the snap mode. + * + * @param snap true to enable snap mode, false to disable + */ public void SetSnap(boolean snap) { this.SNAP = snap; - } + /** + * Retrieves the current status. + * + * @return the current status + */ public int getStatus() { return STATUS; } + /** + * Sets the current status. + * + * @param t the status to set + */ public void setStatus(int t) { STATUS = t; } + /** + * Checks if snap mode is enabled. + * + * @return true if snap mode is enabled, false otherwise + */ public boolean isSnap() { return this.SNAP; } + /** + * Sets the grid mode. + * + * @param grid true to enable grid mode, false to disable + */ public void SetGrid(boolean grid) { this.DRAWGRID = grid; - } + /** + * Checks if grid mode is enabled. + * + * @return true if grid mode is enabled, false otherwise + */ public boolean isDrawGrid() { return this.DRAWGRID; } - public void setGridXY(int n) { - if (n > 0) - GridX = GridY = n; - } - + /** + * Adjusts the mesh step size. + * + * @param add true to increase the mesh step size, false to decrease + */ public void setMeshStep(boolean add) { if (add) { this.GridX += 10; @@ -470,60 +633,32 @@ public void setMeshStep(boolean add) { } this.GridX -= 10; this.GridY -= 10; - - } - - } - - public TPoly getCopyPolylist() { - TPoly pl = polylist; - TPoly plist = null; - - while (pl != null) { - TPoly p = new TPoly(); - p.setPoly(poly.pcopy(pl.getPoly())); - p.setNext(plist); - plist = p; - - pl = pl.getNext(); - } - return plist; - } - - public TPoly getCopyPolyBacklist() { - TPoly pl = pblist; - TPoly plist = null; - - while (pl != null) { - TPoly p = new TPoly(); - p.setPoly(poly.pcopy(pl.getPoly())); - p.setNext(plist); - plist = p; - - pl = pl.getNext(); } - return plist; } + /** + * Retrieves the polynomial list. + * + * @return the polynomial list + */ public TPoly getPolyList() { return polylist; } - public Vector getPolyVector() { - Vector v = new Vector(); - TPoly p = polylist; - while (p != null) { - v.add(p.getPoly()); - p = p.next; - } - - return v; - } - + /** + * Retrieves the PB list. + * + * @return the PB list + */ public TPoly getPBList() { return pblist; } + /** + * Returns a vector containing copies of the TMono objects from the pblist. + * + * @return a vector of TMono objects. + */ public Vector getPBMono() { TPoly poly = pblist; GeoPoly basic = GeoPoly.getPoly(); //.getInstance(); @@ -548,6 +683,11 @@ public Vector getPBMono() { // Get the nondegenerate conditions from the polynomials. // This is the simplest nondegenerate conditions. + + /** + * Prints the nondegenerate conditions derived from the TPoly list. + * Simplifies each TMono condition, prints each condition and the final combined condition. + */ public void printNDGS() { GeoPoly basic = GeoPoly.getPoly(); CharSet set = CharSet.getinstance(); @@ -589,6 +729,13 @@ public void printNDGS() { } + /** + * Computes and returns the nondegenerate conditions for the current TPoly. + * Extracts TMono elements from the pblist, pairs them based on degree, + * computes and reduces the differences, and collects the resulting conditions. + * + * @return a vector of computed nondegenerate conditions. + */ public Vector getNDGS() { TPoly poly = pblist; GeoPoly basic = GeoPoly.getPoly(); //.getInstance(); @@ -636,39 +783,12 @@ public Vector getNDGS() { return vx; } - public String getPolyString(int id) { - int index = 0; - String s = new String(); - TPoly pl = null; - - if (id == 1) { - pl = polylist; - } else if (id == 0) { - pl = pblist; - } - - while (pl != null) { - TMono m = pl.getPoly(); - String s1 = poly.printSPoly(m); - if (id == 1) { - s += "f_" + index + ": "; - } else if (id == 0) { - s += "h_" + index + ": "; - } - - if (s1.length() > 70) { - s += (s1.substring(0, 60) + " + ......\n"); - } else { - s += s1 + "\n"; - } - pl = pl.getNext(); - index++; - } - - return s; - } - - + /** + * Recalculates the diagram by transforming all points and updating parameters. + * Restores previous values if the recalculation fails, triggers diagram updates, and recalculates traces and texts. + * + * @return true if recalculation is successful, false otherwise. + */ public boolean reCalculate() { boolean success = true; @@ -760,6 +880,10 @@ public boolean reCalculate() { return success; } + /** + * Calculates the text values for all CText objects in the text list. + * If the text type is VALUE_TEXT, it calculates the value and updates the text value. + */ public void calculate_text() { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); @@ -778,29 +902,14 @@ public void calculate_text() { } } - public void backup_parameter(boolean success, double x, double y, double sin, double cos) { - if (success == false) { - for (int i = 0; i < paraCounter; i++) { - if (parameter[i] != null) - parameter[i].value = paraBackup[i]; - } - x = pptrans[0]; - y = pptrans[1]; - sin = pptrans[2]; - cos = pptrans[3]; - } else { - for (int i = 0; i < paraCounter; i++) { - if (parameter[i] != null) - paraBackup[i] = parameter[i].value; - } - pptrans[0] = x; - pptrans[1] = y; - pptrans[2] = sin; - pptrans[3] = cos; - } - - } - + /** + * Translates all points back to their original positions after transformation. + * + * @param x1 the x-coordinate translation + * @param y1 the y-coordinate translation + * @param sin the sine of the rotation angle + * @param cos the cosine of the rotation angle + */ public void translate_back(double x1, double y1, double sin, double cos) { if (CMisc.POINT_TRANS) { double t1, t2; @@ -818,9 +927,11 @@ public void translate_back(double x1, double y1, double sin, double cos) { p.y1.value += y1; } } - } + /** + * Recalculates all flash animations in the flash list. + */ public void recal_allFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -828,15 +939,16 @@ public void recal_allFlash() { } } + /** + * Calculates the trace points for all CTrace objects in the trace list. + */ public void calculate_trace() { - int nt = tracelist.size(); if (nt == 0) return; CAL_MODE = 1; - for (int i = 0; i < nt; i++) { CTrace t = (CTrace) tracelist.get(i); CPoint p = t.getPoint(); @@ -851,15 +963,11 @@ public void calculate_trace() { if (c instanceof CLine) { CLine ln = (CLine) c; -// double w = this.Width; -// double h = this.Height; -// double k = ln.getK(); CPoint[] lpt = ln.getMaxMinPoint(false); double x0 = lpt[0].getx(); double y0 = lpt[0].gety(); double x, y, dx, dy; -// double k1 = Math.abs(w / h); x = x0; y = y0; dx = (lpt[1].getx() - lpt[0].getx()) / n; @@ -896,7 +1004,11 @@ public void calculate_trace() { CAL_MODE = 0; } - + /** + * Retrieves the current parameter values. + * + * @return an array of parameter values + */ public double[] getParameter() { double[] r = new double[parameter.length]; for (int i = 0; i < paraCounter; i++) { @@ -906,6 +1018,11 @@ public double[] getParameter() { return r; } + /** + * Sets the parameter values. + * + * @param r an array of parameter values to set + */ public void setParameter(double[] r) { for (int i = 0; i < paraCounter; i++) { if (parameter[i] != null) @@ -913,6 +1030,12 @@ public void setParameter(double[] r) { } } + /** + * Backs up or restores the parameter values. + * + * @param rr an array to store or restore parameter values + * @param b a boolean indicating whether to back up (true) or restore (false) the values + */ public void BackupParameter(double[] rr, boolean b) { if (b) for (int i = 0; i < paraCounter; i++) { @@ -924,10 +1047,13 @@ public void BackupParameter(double[] rr, boolean b) { if (parameter[i] != null) parameter[i].value = rr[i]; } - } - + /** + * Sets the parameter values and translates points back if necessary. + * + * @param dd an array of parameter values to set + */ public void setParameterValue(double[] dd) { for (int i = 0; i < dd.length; i++) { if (parameter[i] != null) @@ -943,7 +1069,11 @@ public void setParameterValue(double[] dd) { } } - + /** + * Calculates all results from the polygons. + * + * @return a Vector containing result arrays for each parameter configuration. + */ public Vector calculate_allResults() { // calculate all results from the polygons. double x1, y1, sin, cos; x1 = y1 = 0; @@ -1061,6 +1191,12 @@ public Vector calculate_allResults() { // calculate all results from the pol return vlist; } + /** + * Calculates all points based on current parameter values. + * + * @param d a flag indicating whether to perform dynamic recalculations + * @return true if all points are calculated successfully; false otherwise. + */ public boolean calculate_allpt(boolean d) { double x1, y1, sin, cos; x1 = y1 = 0; @@ -1105,12 +1241,18 @@ public boolean calculate_allpt(boolean d) { return s; } + /** + * Opens the dialog for selecting the leading variable. + */ public void popLeadingVariableDialog() { LeadVariableDialog dlg = new LeadVariableDialog(gxInstance); dlg.loadVariable(this.getPointList(), false); dlg.setVisible(true); } + /** + * Calculates and updates parameter values based on specific angle constraints. + */ public void calv_parameter() { int n = 0; for (int i = 0; i < constraintlist.size(); i++) { @@ -1136,6 +1278,12 @@ public void calv_parameter() { } + /** + * Finds and returns the circle on which the specified point lies. + * + * @param pt the point to check + * @return the Circle if the point is on a circle; null otherwise. + */ public Circle fd_pt_on_which_circle(CPoint pt) { for (int i = 0; i < circlelist.size(); i++) { Circle cr = (Circle) circlelist.get(i); @@ -1150,7 +1298,12 @@ public Circle fd_pt_on_which_circle(CPoint pt) { return null; } - + /** + * Finds and returns the line on which the specified point lies. + * + * @param pt the point to check + * @return the CLine if the point is on a line; null otherwise. + */ public CLine fd_pt_on_which_line(CPoint pt) { for (int i = 0; i < linelist.size(); i++) { CLine ln = (CLine) linelist.get(i); @@ -1165,18 +1318,12 @@ public CLine fd_pt_on_which_line(CPoint pt) { return null; } - public void setOnLine(CPoint pt, double[] r) { - CLine ln = this.fd_pt_on_which_line(pt); - if (ln != null) { - CPoint p1 = ln.getfirstPoint(); - CPoint p2 = ln.getSecondPoint(p1); - double x1 = paraBackup[pt.x1.xindex - 1]; - double y1 = paraBackup[pt.y1.xindex - 1]; - if (ln.pointOnLineN(pt)) { - } - } - } - + /** + * Calculates the corresponding point on a circle. + * + * @param pt the point used for the calculation + * @return an array containing x and y coordinates of the calculated point, or null if not applicable. + */ public double[] calculate_ocir(CPoint pt) { if (this.CurrentAction == MOVE && this.SelectList.contains(pt) || CAL_MODE == 1) return null; @@ -1211,7 +1358,12 @@ public double[] calculate_ocir(CPoint pt) { return null; } - + /** + * Calculates the intersection point on a line based on the given point. + * + * @param pt the point used for the calculation + * @return an array containing x and y coordinates of the calculated intersection point, or null if not applicable. + */ public double[] calculate_oline(CPoint pt) { if (this.CurrentAction == MOVE && this.SelectList.contains(pt) || CAL_MODE == 1) return null; @@ -1247,6 +1399,13 @@ public double[] calculate_oline(CPoint pt) { return null; } + /** + * Calculates and adjusts the given point based on a line-circle or circle-circle constraint. + * + * @param cp the point to adjust + * @param r an array containing candidate coordinates + * @return true if the point is set successfully according to constraints; false otherwise. + */ public boolean calculate_lccc(CPoint cp, double[] r) { Param pm1 = cp.x1; Param pm2 = cp.y1; @@ -1383,7 +1542,13 @@ else if (area < 0) return false; } - + /** + * Calculates the coordinates for a given point using its defining parameters and constraints. + * + * @param p the point to calculate + * @param d a flag that, if true, forces dynamic recalculation using constraint equations + * @return true if the point is calculated successfully; false otherwise. + */ public boolean calculate_a_point(CPoint p, boolean d) { if (p == null || p.isAFreePoint()) return true; @@ -1569,6 +1734,15 @@ public boolean calculate_a_point(CPoint p, boolean d) { return success; } + /** + * Calculates the values of a polynomial. + *+ * This method calculates the values of a given polynomial using the provided parameters. + * If the result is null, it attempts to find the polynomial in the polynomial list and calculate its values. + * + * @param m the polynomial to calculate + * @return an array of calculated values, or null if the calculation fails + */ public double[] calcu_m1(TMono m) { double[] result = poly.calculv(m, parameter); @@ -1590,7 +1764,6 @@ public double[] calcu_m1(TMono m) { TMono m2 = null; int d = poly.deg(m, lva); - while (plist != null) { if (poly.lv(plist.getPoly()) == lva) { if (m1 == null) { @@ -1603,7 +1776,7 @@ public double[] calcu_m1(TMono m) { } if (m1 == null && m2 == null) { - + return null; } if (m1 != null && m2 != null) { result = poly.calculv2poly(m1, m2, parameter); @@ -1622,6 +1795,11 @@ public double[] calcu_m1(TMono m) { return result; } + /** + * Backs up the current parameter values. + *
+ * This method saves the current values of the parameters into the backup array. + */ public void pushbackup() { for (int i = 0; i < paraCounter; i++) { if (parameter[i] != null) { @@ -1630,6 +1808,15 @@ public void pushbackup() { } } + /** + * Calculates the values of two polynomials. + *
+ * This method calculates the values of two polynomials with the same leading variable. + * + * @param lv the leading variable + * @param p the array of parameters + * @return an array of calculated values, or null if the calculation fails + */ public double[] calform(int lv, Param p[]) { TPoly plist = pblist; TMono m1, m2; @@ -1646,17 +1833,23 @@ public double[] calform(int lv, Param p[]) { n++; } plist = plist.getNext(); - } if (m1 == null || m2 == null) { return null; } - double[] result; //= new double[1]; + double[] result; result = poly.calculv2poly(m1, m2, p); return result; } + /** + * Adds polynomials to the list and optimizes them. + *
+ * This method adds polynomials to the list, optimizes them, and recalculates the values if necessary. + * + * @param calcu a boolean indicating whether to recalculate the values + */ public void charsetAndAddPoly(boolean calcu) { TPoly plist = Constraint.getPolyListAndSetNull(); TPoly plist2 = plist; @@ -1701,12 +1894,7 @@ public void charsetAndAddPoly(boolean calcu) { } try { -// CMisc.print("----------------------"); -// this.printPoly(polylist); -// polylist = optmizePolygonOnLine(polylist); polylist = charset.charset(polylist); -// CMisc.print("======================"); -// this.printPoly(polylist); } catch (OutOfMemoryError ee) { JOptionPane.showMessageDialog(gxInstance, ee.getMessage(), ee.toString(), JOptionPane.ERROR_MESSAGE); } @@ -1720,6 +1908,11 @@ public void charsetAndAddPoly(boolean calcu) { } } + /** + * Optimizes the polynomial list. + *
+ * This method optimizes the polynomial list by adding zero constraints for certain points. + */ public void optmizePolynomial() { if (!CMisc.POINT_TRANS) return; @@ -1756,6 +1949,14 @@ public void optmizePolynomial() { } } + /** + * Adds a zero constraint for a given variable. + *
+ * This method adds a zero constraint for a given variable to the zero constraints array. + * + * @param x the variable index + * @param zeron the array of zero constraints + */ public void addZeron(int x, int[] zeron) { for (int i = 0; true; i++) { if (zeron[i] == x) @@ -1767,6 +1968,15 @@ public void addZeron(int x, int[] zeron) { } } + /** + * Selects multiple solutions for a given point. + *
+ * This method selects multiple solutions for a given point by calculating the possible values + * and adding them to the solution list. + * + * @param p the point for which to select multiple solutions + * @return true if the selection is successful, false otherwise + */ public boolean mulSolutionSelect(CPoint p) { pSolution = p; TMono m1 = p.x1.m; @@ -1777,7 +1987,6 @@ public boolean mulSolutionSelect(CPoint p) { if (m1.deg == 1 && m2.deg == 1) return true; - double x1, y1, sin, cos; x1 = y1 = 0; sin = 0; @@ -1827,7 +2036,6 @@ public boolean mulSolutionSelect(CPoint p) { if (r == null) r = this.calform(lva, parameter); - for (int j = 0; j < r.length; j++) { CPoint pt = this.CreateATempPoint(result[i], r[j]); solutionlist.add(pt); @@ -1872,6 +2080,14 @@ public boolean mulSolutionSelect(CPoint p) { return true; } + /** + * Erases a decided point from the polynomial list. + *
+ * This method removes a point from the polynomial list and adjusts the list accordingly. + * It also updates the parameter counter. + * + * @param p the point to be erased + */ public void ErasedADecidedPoint(CPoint p) { //there are some problems in this function. int x1 = p.x1.xindex; int y1 = p.y1.xindex; @@ -1918,25 +2134,42 @@ public void ErasedADecidedPoint(CPoint p) { //there are some problems in this fu return; } - + /** + * Sets the dimensions of the drawing area. + * + * @param x the width of the drawing area + * @param y the height of the drawing area + */ public void SetDimension(double x, double y) { this.Width = x; this.Height = y; } + /** + * Retrieves the current action type. + * + * @return the current action type + */ public int GetCurrentAction() { return this.CurrentAction; } + /** + * Sets the parameters for the drawing process. + * + * @param v1 the first parameter + * @param v2 the second parameter + */ public void setParameter(int v1, int v2) { this.v1 = v1; this.v2 = v2; } - public void setCurrentDrawStartOver() { - SetCurrentAction(CurrentAction); - } - + /** + * Sets the current action type and updates the UI accordingly. + * + * @param type the action type to set + */ public void SetCurrentAction(int type) { if (type != MOVE && CurrentAction == CONSTRUCT_FROM_TEXT) { this.clearFlash(); @@ -1965,9 +2198,15 @@ else if (gxInstance != null) if (dlg != null && dlg.isVisible()) dlg.setAction(this.getActionType(type)); } - } + /** + * Finds an edmark object between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the found edmark object, or null if not found + */ public Cedmark fd_edmark(CPoint p1, CPoint p2) { for (int i = 0; i < otherlist.size(); i++) { Object obj = otherlist.get(i); @@ -1981,90 +2220,40 @@ public Cedmark fd_edmark(CPoint p1, CPoint p2) { return null; } - + /** + * Sets the current status. + * + * @param status the status to set + */ public void setcurrentStatus(int status) { STATUS = status; } - - public boolean saveProveText(String path) throws IOException { - if (cpfield == null) { - return false; - } - - FileOutputStream fp; - File f = new File(path); - - if (f.exists()) { - f.delete(); - fp = new FileOutputStream(f, true); - - } else { - f.createNewFile(); - fp = new FileOutputStream(f, false); - } - if (fp == null) { - return false; - } - DataOutputStream out = new DataOutputStream(fp); - return cpfield.saveText(out, 0); - - } - - public void createProveHead() { - } - - public boolean undoProveToHead() { - if (cpfield == null) { - return false; - } - return cpfield.undo_to_head(this); - } - - public boolean prove_run_to_prove() { - if (cpfield != null) { - cpfield.run_to_end(this); - return cpfield.undo_default(this); - } else { - gxInstance.getpprove().m_runtobegin(); - } - return true; - } - - public boolean nextProveStep() { - if (cpfield != null) { - clearSelection(); - UndoStruct u = this.redo_step(); + /** + * Proceeds to the next step in the proof process. + * + * @return true if the next step is successfully executed, false otherwise + */ + public boolean nextProveStep() { + if (cpfield != null) { + clearSelection(); + UndoStruct u = this.redo_step(); if (u == null) this.Undo(); else cpfield.setSelectedUndo(u, this); return true; - -// boolean r = cpfield.next_prove_step(this); - -// if (!) { -// cpfield.undo_to_head(this); //.undo_default(this); -// } } else { -// if (gxInstance != null && gxInstance.getpprove() != null) -// gxInstance.getpprove().mstep(); - } - return false; - } - - - public CLine fd_line(Vector v) { - for (int i = 0; i < linelist.size(); i++) { - CLine ln = (CLine) linelist.get(i); - if (ln.points.containsAll(v)) { - return ln; - } + return false; } - return null; } + /** + * Starts the proof play with a specified timer interval. + * + * @param num the timer interval in milliseconds + */ public void provePlay(int num) { if (timer_type == 0) { timer = new Timer(num, this); @@ -2077,6 +2266,9 @@ public void provePlay(int num) { } } + /** + * Stops the proof play. + */ public void proveStop() { if (timer_type != 2) { return; @@ -2086,6 +2278,13 @@ public void proveStop() { cpfield.run_to_end(this); } + /** + * Runs the proof process to a specific step. + * + * @param u the current undo structure + * @param u1 the target undo structure + * @return true if the process is successfully executed, false otherwise + */ public boolean run_to_prove(UndoStruct u, UndoStruct u1) { this.doFlash(); @@ -2105,6 +2304,9 @@ public boolean run_to_prove(UndoStruct u, UndoStruct u1) { return true; } + /** + * Runs the proof process to the current undo structure. + */ public void runto() { UndoStruct u = U_Obj; if (u == null) return; @@ -2121,6 +2323,11 @@ public void runto() { U_Obj = null; } + /** + * Runs the proof process to a specific undo structure. + * + * @param u the target undo structure + */ public void runto1(UndoStruct u) { if (u == null) return; UndoStruct ux; @@ -2139,6 +2346,11 @@ public void runto1(UndoStruct u) { } } + /** + * Checks if all flash animations are finished. + * + * @return true if all flash animations are finished, false otherwise + */ public boolean all_flash_finished() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -2148,10 +2360,18 @@ public boolean all_flash_finished() { return true; } + /** + * Checks if the construction proof field exists. + * + * @return true if the construction proof field exists, false otherwise + */ public boolean checkCPfieldExists() { return cpfield != null; } + /** + * Runs the proof process to the end. + */ public void prove_run_to_end() { if (cpfield != null) { cpfield.run_to_end(this); @@ -2159,37 +2379,15 @@ public void prove_run_to_end() { if (gxInstance != null && gxInstance.getpprove() != null) gxInstance.getpprove().m_runtoend(); } - - } - - public void prove_run_to_begin() { - if (cpfield != null) { - cpfield.run_to_end(this); - cpfield.run_to_begin(this); - } else { - gxInstance.getpprove().m_runtobegin(); - } - } - - public void Regenerate_Prove_Text() { - if (cpfield != null) { - cpfield.reGenerateAll(); - } - } - - public boolean removeLastProveNode() { - if (cpfield != null) { - boolean r = cpfield.removeLast(); - if (r == false) { - cpfield = null; - } - return r; - - } else { - return false; - } } + /** + * Retrieves the snap coordinates based on the grid settings. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return an array containing the snapped x and y coordinates + */ public double[] getSnap(double x, double y) { double[] r = new double[2]; if (!this.SNAP) { @@ -2204,6 +2402,14 @@ public double[] getSnap(double x, double y) { return r; } + /** + * Handles the mouse wheel event for zooming in and out. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param n the number of notches the mouse wheel was rotated + * @param rt the rotation direction (positive for zoom in, negative for zoom out) + */ public void DWMouseWheel(double x, double y, int n, int rt) { switch (this.CurrentAction) { case MOVE: @@ -2218,15 +2424,19 @@ public void DWMouseWheel(double x, double y, int n, int rt) { if (k > 0) this.reCalculate(); break; - } } + /** + * Handles the double-click event on the drawing window. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseDbClick(double x, double y) { CatchPoint.setXY(x, y); switch (this.CurrentAction) { - // case SELECT: case MOVE: { if (!viewElementFromXY(x, y)) { } @@ -2234,6 +2444,9 @@ public void DWMouseDbClick(double x, double y) { } } + /** + * Defines a specific angle constraint. + */ public void defineSpecificAngle() { if (paraCounter != 1) { Vector v = this.getSpecificAngleList(); @@ -2266,9 +2479,6 @@ public void defineSpecificAngle() { this.charsetAndAddPoly(false); } if (paraCounter % 2 != 0) { -// paraCounter += 2; -// parameter[paraCounter-1] = new param(0,0); -// parameter[paraCounter-2] = new param(0,0); parameter[paraCounter - 1] = new Param(0, 0); paraCounter += 1; parameter[paraCounter - 1] = new Param(0, 0); @@ -2277,9 +2487,14 @@ public void defineSpecificAngle() { parameter[paraCounter - 1] = new Param(0, 0); paraCounter += 1; } - } + /** + * Retrieves the parameter associated with a specific angle constraint. + * + * @param ang the specific angle value + * @return the parameter associated with the specific angle constraint, or null if not found + */ public Param getParaForSpecificAngle(int ang) { for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -2293,6 +2508,11 @@ public Param getParaForSpecificAngle(int ang) { return null; } + /** + * Retrieves a list of specific angle constraints. + * + * @return a vector containing the specific angle constraints + */ public Vector getSpecificAngleList() { Vector v = new Vector(); @@ -2303,9 +2523,15 @@ public Vector getSpecificAngleList() { } } return v; - } + /** + * Views an element from the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if an element is viewed, false otherwise + */ public boolean viewElementFromXY(double x, double y) { Vector v = new Vector(); this.SelectAllFromXY(v, x, y, 0); @@ -2327,10 +2553,17 @@ public boolean viewElementFromXY(double x, double y) { v.add(c); this.setObjectListForFlash(v); this.onDBClick(c); -// this.viewElement(c); return true; } + /** + * Displays a selection dialog if multiple objects are selected. + * + * @param v the vector of selected objects + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected object, or null if no object is selected + */ public Object popSelect(Vector v, int x, int y) { if (v.size() == 1) { this.viewElement((CClass) v.get(0)); @@ -2350,21 +2583,31 @@ public Object popSelect(Vector v, int x, int y) { return null; } + /** + * Handles the right mouse button down event. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseRightDown(double x, double y) { if (CurrentAction != DEFINEPOLY && CurrentAction != TRANSFORM && CurrentAction != FREE_TRANSFORM) { CatchPoint.setXY(x, y); clearSelection(); STATUS = 0; this.RightMenuPopup(x, y); - } } + /** + * Handles the right mouse button click event. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseRightClick(double x, double y) { CatchPoint.setXY(x, y); switch (CurrentAction) { case DEFINEPOLY: { - if (SelectList.size() == 1 && STATUS != 0) { CPolygon cp = (CPolygon) SelectList.get(0); if (cp.pointlist.size() >= 3) { @@ -2381,7 +2624,6 @@ public void DWMouseRightClick(double x, double y) { STATUS = 0; this.RightMenuPopup(x, y); } - } break; case TRANSFORM: { @@ -2416,12 +2658,16 @@ public void actionPerformed(ActionEvent e) { } } break; - } - } + /** + * Displays a right-click context menu at the specified coordinates. + * + * @param x the x-coordinate where the menu should be displayed + * @param y the y-coordinate where the menu should be displayed + */ public void RightMenuPopup(double x, double y) { if (gxInstance == null) return; @@ -2450,7 +2696,15 @@ public void RightMenuPopup(double x, double y) { } - public void SelectFromAList(Vector v1, Vector v2, double x, double y) { // from v1 to v2 + /** + * Selects objects from one list and adds them to another based on coordinates. + * + * @param v1 the list to which selected objects are added + * @param v2 the list from which objects are selected + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + */ + public void SelectFromAList(Vector v1, Vector v2, double x, double y) { for (int i = 0; i < v2.size(); i++) { CClass cc = (CClass) v2.get(i); if (cc.select(x, y)) { @@ -2459,6 +2713,14 @@ public void SelectFromAList(Vector v1, Vector v2, double x, double y) { // from } } + /** + * Selects all objects from various lists based on coordinates and type. + * + * @param v the list to which selected objects are added + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @param type the type of objects to select (0: point preferential, 1: geometry object only, 2: all, etc.) + */ public void SelectAllFromXY(Vector v, double x, double y, int type) { // 2: all; 1: geometry object only 0: point preferential //3: only point, 4:only line, 5: only circle @@ -2523,6 +2785,13 @@ public void SelectAllFromXY(Vector v, double x, double y, int type) { } + /** + * Selects text objects based on coordinates. + * + * @param v the list to which selected text objects are added + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + */ public void SelectNameText(Vector v, double x, double y) { for (int i = 0; i < textlist.size(); i++) { CText text = (CText) textlist.get(i); @@ -2537,6 +2806,14 @@ public void SelectNameText(Vector v, double x, double y) { } } + /** + * Selects a single object from various lists based on coordinates and type. + * + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @param type the type of objects to select (0: point preferential, 1: geometry object only, 2: all, etc.) + * @return the selected object, or null if no object is selected + */ public CClass SelectOneFromXY(double x, double y, int type) { Vector v = new Vector(); this.SelectAllFromXY(v, x, y, type); @@ -2550,40 +2827,12 @@ public CClass SelectOneFromXY(double x, double y, int type) { } - public Vector OnSelect(double x, double y) { - - Vector v = new Vector(); - SelectAllFromXY(v, x, y, 0); - - if (v.size() == 0) { - clearSelection(); - } else { - if (v.size() == 1) { - if (SelectList.containsAll(v)) { - removeAllSelection(v); - return SelectList; - } else { - CClass cc = (CClass) v.get(0); - SelectList.addAll(v); - v.clear(); - if (cc.m_type == CClass.ANGLE) { - CAngle ag = (CAngle) cc; - v.add(ag.lstart); - v.add(ag.lend); - this.flashStep(v); - } - } - } else { - Object obj = this.popSelect(v, (int) x, (int) y); - if (obj != null) { - this.addObjectToList(obj, SelectList); - } - } - - } - return v; - } - + /** + * Adjusts the coordinates of the second point to align with the first point if they are close enough. + * + * @param p1 the first point + * @param p2 the second point + */ public void getSmartPV(CPoint p1, CPoint p2) { int x, y; x = y = 0; @@ -2611,19 +2860,20 @@ public void getSmartPV(CPoint p1, CPoint p2) { } } - public CProveText SelectProveText(double x, double y) { - if (cpfield == null) { - return null; - } - return cpfield.select(x, y, false); - } - + /** + * Clears the selection list. + */ public void clearSelection() { SelectList.clear(); if (gxInstance != null) gxInstance.updateActionPool(this.CurrentAction); } + /** + * Adds an object to the selection list. + * + * @param c the object to add + */ public void addToSelectList(Object c) { if (c != null) { SelectList.add(c); @@ -2633,19 +2883,26 @@ public void addToSelectList(Object c) { } - public void removeAllSelection(Vector v) { - SelectList.removeAll(v); - if (gxInstance != null) - gxInstance.updateActionPool(this.CurrentAction); - } - - + /** + * Selects objects based on coordinates and adds them to the catch list. + * + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @return the list of selected objects + */ public Vector OnCatch(double x, double y) { CatchList.clear(); SelectAllFromXY(CatchList, x, y, 0); return CatchList; } + /** + * Checks if a point can be animated along a line. + * + * @param p the point to check + * @param ln the line to check + * @return true if the point can be animated along the line, false otherwise + */ public boolean check_animation(CPoint p, CLine ln) { if (p == null || ln == null) return false; @@ -2657,6 +2914,28 @@ public boolean check_animation(CPoint p, CLine ln) { return true; } + // FIXME: 2500 lines is too large - extract handlers + + /** + * Handles the "mouse down" (button press) event within the drawing canvas. + * + *
This method interprets user input based on the current action mode + * (such as SELECT, MOVE, D_POINT, etc.) and performs corresponding + * geometry-related operations. These may include selecting or modifying + * points, creating lines, circles, constraints, or initiating transformations.
+ * + *Behavior depends on {@code CurrentAction}, which is evaluated in a large + * switch-case structure that includes many interactive drawing modes.
+ * + * @param x The x-coordinate of the mouse click, in screen or canvas coordinates + * @param y The y-coordinate of the mouse click, in screen or canvas coordinates + * @note This method contains a large switch statement and is a candidate + * for major refactoring to improve maintainability and testability. + * @see #CurrentAction + * @see #SelectList + * @see #CatchPoint + * @see #STATUS + */ public void DWButtonDown(double x, double y) { CPoint p = null; CatchList.clear(); @@ -3020,7 +3299,7 @@ public void DWButtonDown(double x, double y) { // pt.getname()); line.getDescription() + " " + GExpert.getTranslationViaGettext("passing {0}", pt.getname())); - u.addObject(line1); + u.addObject(line1); u.addObject(line); u.addObject(pt); STATUS = 0; @@ -3419,9 +3698,9 @@ public void DWButtonDown(double x, double y) { p3.m_name + pt.m_name); */ this.UndoAdded(GExpert.getTranslationViaGettext( - "Take a point {0} on line {1} such that {2}",pt.m_name, + "Take a point {0} on line {1} such that {2}", pt.m_name, ln.getSimpleName(), p1.m_name + p2.m_name + " = " + - p3.m_name + pt.m_name)); + p3.m_name + pt.m_name)); } else { this.ErasedADecidedPoint(pt); @@ -3458,7 +3737,7 @@ public void DWButtonDown(double x, double y) { this.UndoAdded(GExpert.getTranslationViaGettext( "Take a point {0} on circle {1} such that {2}", pt.m_name, c.getname(), p1.m_name + p2.m_name + " = " + - p3.m_name + pt.m_name)); + p3.m_name + pt.m_name)); } else { this.ErasedADecidedPoint(pt); gxInstance.setTipText("Failed: can not find a point(P) on Circle " + @@ -3576,7 +3855,7 @@ public void DWButtonDown(double x, double y) { // p1.TypeString() + " wrt " + // p2.TypeString()); this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", pp.TypeString(), - p1.TypeString(),p2.TypeString())); + p1.TypeString(), p2.TypeString())); } else { pp = pu; @@ -3658,7 +3937,7 @@ public void DWButtonDown(double x, double y) { // line.getDiscription() + " wrt " + // p1.TypeString()); this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.TypeString(), - line.getDiscription(),p1.TypeString())); + line.getDiscription(), p1.TypeString())); } @@ -3689,7 +3968,7 @@ public void DWButtonDown(double x, double y) { // line.getDiscription() + " wrt " + // p1.TypeString()); this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.getDiscription(), - line.getDescription(),p1.TypeString())); + line.getDescription(), p1.TypeString())); } else @@ -3758,7 +4037,7 @@ public void DWButtonDown(double x, double y) { // line.getDiscription() + " wrt " + // line2.getDiscription()); this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line3.getDiscription(), - line.getDiscription(),line2.getDiscription())); + line.getDiscription(), line2.getDiscription())); } } @@ -3814,7 +4093,7 @@ public void DWButtonDown(double x, double y) { // " is reflection of " + c1.getDescription() + // " wrt " + p1.TypeString()); this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", c.getDescription(), - c1.getDescription(),p1.TypeString())); + c1.getDescription(), p1.TypeString())); } @@ -4246,7 +4525,7 @@ public void DWButtonDown(double x, double y) { line.addconstraint(cs); clearSelection(); this.UndoAdded(line.TypeString() + ": " + GExpert.getTranslationViaGettext( - "Radical of {0} and {1}",c0.getDescription(), c.getDescription())); + "Radical of {0} and {1}", c0.getDescription(), c.getDescription())); } } @@ -5265,6 +5544,13 @@ else if (m == t2) } + /** + * Adds a free transform to the selected polygon. + *+ * This method creates a transformed copy of the selected polygon, adds a constraint + * for the transformation, and updates the polygon list. It also clears the selection + * and resets the status. + */ public void add_free_transform() { CPolygon p = (CPolygon) SelectList.get(0); Vector v = p.getTransformedPoints(); @@ -5281,6 +5567,16 @@ public void add_free_transform() { this.UndoAdded(p.getDescription() + " transformed to " + p1.getDescription()); } + /** + * Finds the intersection point of two geometric objects. + * + * @param obj1 the first geometric object (CLine or Circle) + * @param obj2 the second geometric object (CLine or Circle) + * @param d a boolean flag indicating some condition (not specified) + * @param x the x-coordinate for the intersection calculation + * @param y the y-coordinate for the intersection calculation + * @return the intersection point, or null if no intersection is found + */ public CPoint meetTwoObject(Object obj1, Object obj2, boolean d, double x, double y) { if (obj1 instanceof CLine && obj2 instanceof CLine) { return MeetDefineAPoint((CLine) obj1, (CLine) obj2); @@ -5296,11 +5592,12 @@ public CPoint meetTwoObject(Object obj1, Object obj2, boolean d, double x, doubl return null; } -// public void addToSelectList(Object p) { -// if (p != null && !SelectList.contains(p)) -// addToSelectList(p); -// } - + /** + * Adds a point to the selection list based on the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void addSelectPoint(double x, double y) { CPoint p = this.SelectAPoint(x, y); if (p != null && !SelectList.contains(p)) { @@ -5308,6 +5605,14 @@ public void addSelectPoint(double x, double y) { } } + /** + * Adds a line between two points to the line list. + * + * @param t the type of the line + * @param p1 the first point + * @param p2 the second point + * @return the added line, or the existing line if it already exists + */ public CLine addALine(int t, CPoint p1, CPoint p2) { CLine ln1 = this.fd_line(p1, p2); if (ln1 != null) { @@ -5318,21 +5623,12 @@ public CLine addALine(int t, CPoint p1, CPoint p2) { return ln; } - public Vector printStep(String cc) { - CMisc.print("***************************"); - - Vector v = this.getConstructionFromDraw(); - v.add(cc); - - for (int i = 0; i < v.size(); i++) { - String st = (String) v.get(i); - CMisc.print(st); - } - return v; - } - + /** + * Retrieves the construction steps from the drawing. + * + * @return a vector containing the construction steps + */ public Vector getConstructionFromDraw() { - Vector alist = new Vector(); for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -5348,6 +5644,12 @@ public Vector getConstructionFromDraw() { return alist; } + /** + * Finds a polygon in the polygon list that matches the given vector of points. + * + * @param v the vector of points + * @return the matching polygon, or null if no match is found + */ public CPolygon findPolygon(Vector v) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon p = (CPolygon) polygonlist.get(i); @@ -5357,6 +5659,13 @@ public CPolygon findPolygon(Vector v) { return null; } + /** + * Finds a polygon in the polygon list that matches the given vector of points, + * considering rotational and directional equivalence. + * + * @param v the vector of points + * @return the matching polygon, or null if no match is found + */ public CPolygon findPolygon1(Vector v) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon p = (CPolygon) polygonlist.get(i); @@ -5366,6 +5675,11 @@ public CPolygon findPolygon1(Vector v) { return null; } + /** + * Checks if auto animation is possible. + * + * @return true if auto animation is possible, false otherwise + */ public boolean canAutoAnimate() { if (animate != null) { return true; @@ -5373,6 +5687,11 @@ public boolean canAutoAnimate() { return false; } + /** + * Toggles auto animation on or off. + * + * @return true if auto animation is started, false if it is stopped + */ public boolean autoAnimate() { if (canAutoAnimate()) { AnimatePanel af = gxInstance.getAnimateDialog(); @@ -5393,10 +5712,16 @@ public boolean autoAnimate() { return false; } + /** + * Automatically shows the next step in the construction. + */ public void autoShowstep() { this.autoUndoRedo(); } + /** + * Toggles automatic undo and redo actions. + */ public void autoUndoRedo() { if (timer_type == 1) { timer.stop(); @@ -5419,6 +5744,11 @@ public void autoUndoRedo() { } + /** + * Handles action events triggered by the timer or other sources. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); @@ -5452,6 +5782,9 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Updates the delay for all flash objects in the flash list. + */ public void updateFlashDelay() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -5459,6 +5792,11 @@ public void updateFlashDelay() { } } + /** + * Sets the delay for the timer. + * + * @param delay the delay in milliseconds + */ public void setTimerDelay(int delay) { if (timer == null) { return; @@ -5466,6 +5804,11 @@ public void setTimerDelay(int delay) { timer.setDelay(delay); } + /** + * Displays the properties of the specified object in the dialog. + * + * @param obj the object to view + */ public void viewElement(CClass obj) { if (obj == null) { return; @@ -5478,11 +5821,16 @@ public void viewElement(CClass obj) { } } - + /** + * Starts the animation. + */ public void animationStart() { animate.startAnimate(); } + /** + * Stops the animation and recalculates the drawing. + */ public void animationStop() { if (animate != null) { animate.stopAnimate(); @@ -5490,12 +5838,22 @@ public void animationStop() { this.reCalculate(); } + /** + * Updates the animation on each timer tick and recalculates the drawing. + */ public void animationOntime() { animate.onTimer(); this.reCalculate(); - } + /** + * Selects an object from the list based on the given coordinates. + * + * @param v the list of objects + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected object, or null if no object is selected + */ public CClass CatchList(Vector v, double x, double y) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); @@ -5504,9 +5862,15 @@ public CClass CatchList(Vector v, double x, double y) { } } return null; - } + /** + * Selects an angle from the list based on the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected angle, or null if no angle is selected + */ public CAngle CatchAngle(double x, double y) { for (int i = 0; i < anglelist.size(); i++) { CAngle ag = (CAngle) anglelist.get(i); @@ -5517,6 +5881,13 @@ public CAngle CatchAngle(double x, double y) { return null; } + /** + * Displays a dialog to add or edit text at the specified coordinates. + * + * @param tc the text object + * @param x the x-coordinate + * @param y the y-coordinate + */ public void dialog_addText(CText tc, int x, int y) { TextFrame tf = new TextFrame(gxInstance, x, y); tf.setText(tc); @@ -5524,16 +5895,36 @@ public void dialog_addText(CText tc, int x, int y) { tf.setVisible(true); } + /** + * Adds a point at the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the added point + */ public CPoint SmartgetApointFromXY(double x, double y) { CPoint pt = SmartAddPoint(x, y); return pt; } + /** + * Adds a point with the specified name at the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param name the name of the point + * @return the added point + */ public CPoint SmartgetApointFromXY(double x, double y, String name) { CPoint pt = SmartAddPoint(x, y, name); return pt; } + /** + * Adds a point to the point list and assigns a name if not already set. + * + * @param p the point to add + */ public void addPointToList(CPoint p) { if (p == null) return; @@ -5559,6 +5950,12 @@ public void addPointToList(CPoint p) { this.reCalculate(); } + /** + * Generates a point name based on the given count. + * + * @param n the count used to generate the point name + * @return the generated point name + */ public String getPointNameByCount(int n) { int in = (n) / 26; int number = n - in * 26; @@ -5576,6 +5973,11 @@ public String getPointNameByCount(int n) { return s; } + /** + * Adds an angle to the angle list if it is not already present. + * + * @param ag the angle to add + */ public void addAngleToList(CAngle ag) { if (anglelist.contains(ag)) { return; @@ -5584,32 +5986,27 @@ public void addAngleToList(CAngle ag) { textlist.add(ag.getText()); } + /** + * Adds a line to the line list if it is not already present. + * + * @param line the line to add + */ public void addLineToList(CLine line) { if (linelist.contains(line)) { return; } - -// int in = (this.plineCounter) / 26; -// int number = this.plineCounter - in * 26; -// if (in == 0) { -// char[] c = new char[1]; -// c[0] = (char) (number + 'a'); -// line.m_name = new String(c); -// } else { -// char[] c = new char[2]; -// c[0] = (char) (number + 'a'); -// c[1] = (char) ('0' + in); -// line.m_name = new String(c); -// } String str = new String("l"); str += this.plineCounter; -// plineCounter++; line.m_name = str; this.plineCounter++; linelist.add(line); } - + /** + * Adds a polygon to the polygon list if it is not already present. + * + * @param p the polygon to add + */ public void addPolygonToList(CPolygon p) { if (p == null || polygonlist.contains(p)) return; @@ -5637,6 +6034,12 @@ public void addPolygonToList(CPolygon p) { this.polygonlist.add(p); } + /** + * Draws a line between two points and adds it to the line list if it does not already exist. + * + * @param p1 the first point + * @param p2 the second point + */ public void drawLineAndAdd(CPoint p1, CPoint p2) { if (p1 == null || p2 == null || p1 == p2) return; @@ -5646,6 +6049,11 @@ public void drawLineAndAdd(CPoint p1, CPoint p2) { } } + /** + * Adds a circle to the circle list if it is not already present. + * + * @param c the circle to add + */ public void addCircleToList(Circle c) { if (circlelist.contains(c)) { return; @@ -5657,6 +6065,13 @@ public void addCircleToList(Circle c) { circlelist.add(c); } + /** + * Adds an object to the specified list if it is not already present. + * + * @param obj the object to add + * @param list the list to which the object is added + * @return true if the object was added, false otherwise + */ public boolean addObjectToList(Object obj, Vector list) { if (obj == null) { return false; @@ -5671,20 +6086,40 @@ public boolean addObjectToList(Object obj, Vector list) { return true; } + /** + * Adds a constraint to the constraint list if it is not already present. + * + * @param cs the constraint to add + */ public void addConstraintToList(Constraint cs) { if (cs != null && !constraintlist.contains(cs)) { constraintlist.add(cs); } } - public void removeConstraintFromList(Constraint cs) { + /** + * Removes a constraint from the constraint list. + * + * @param cs the constraint to remove + */ + public void removeConstraintFromList(Constraint cs) { constraintlist.remove(cs); } + /** + * Clears all constraints from the constraint list. + */ public void clearAllConstraint() { constraintlist.clear(); } + /** + * Checks if a line exists between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line exists, false otherwise + */ private boolean isLineExists(CPoint p1, CPoint p2) { for (int i = 0; i < linelist.size(); i++) { CLine ln = (CLine) linelist.get(i); @@ -5695,6 +6130,14 @@ private boolean isLineExists(CPoint p1, CPoint p2) { return false; } + /** + * Checks if a circle exists that passes through three points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the circle exists, false otherwise + */ private boolean isCircleExists(CPoint p1, CPoint p2, CPoint p3) { for (int i = 0; i < circlelist.size(); i++) { Circle ln = (Circle) circlelist.get(i); @@ -5706,6 +6149,15 @@ private boolean isCircleExists(CPoint p1, CPoint p2, CPoint p3) { return false; } + /** + * Selects and adds objects (points, lines, circles, and texts) that lie within the rectangular region + * defined by the two diagonal points (x1, y1) and (x2, y2). + * + * @param x1 the x-coordinate of the first corner of the rectangle + * @param y1 the y-coordinate of the first corner of the rectangle + * @param x2 the x-coordinate of the opposite corner of the rectangle + * @param y2 the y-coordinate of the opposite corner of the rectangle + */ public void SelectByRect(double x1, double y1, double x2, double y2) { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -5734,6 +6186,13 @@ public void SelectByRect(double x1, double y1, double x2, double y2) { } + /** + * Handles the mouse button release (up) event by applying snap adjustments and executing actions + * based on the current drawing mode (e.g., line creation, point selection, or transformation). + * + * @param x the x-coordinate where the mouse button was released + * @param y the y-coordinate where the mouse button was released + */ public void DWButtonUp(double x, double y) { this.IsButtonDown = false; @@ -5873,6 +6332,11 @@ public void DWButtonUp(double x, double y) { IsButtonDown = false; } + /** + * Adjusts the position of a free-moving point along its connecting line segments to ensure proper alignment. + * The method checks nearby points on the connected line and snaps the point to the corresponding x or y value + * if within a defined pixel threshold. + */ public void smartPVDragLine() { if (SelectList.size() != 1) return; @@ -5916,6 +6380,13 @@ public void smartPVDragLine() { } + /** + * Processes mouse drag events and updates the position of objects accordingly based on the current drawing action. + * Applies snapping if enabled, and updates positions of points and transformations for the active drawing mode. + * + * @param x the current x-coordinate during the drag + * @param y the current y-coordinate during the drag + */ public void DWMouseDrag(double x, double y) { if (SNAP && CurrentAction != SELECT) { @@ -6003,48 +6474,15 @@ public void DWMouseDrag(double x, double y) { } } - private int SmartLineType(double x1, double y1, CPoint p2) { - double x2 = p2.getx(); - double y2 = p2.gety(); - - if (Math.abs(x2 - x1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - return 1; //vertical - } else if (Math.abs(y2 - y1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - return 2; //horizonal - } else { - return 0; - } - - } - - private int setSmartPVPointLocation(double x1, double y1, CPoint p2) { - double x2 = p2.getx(); - double y2 = p2.gety(); - - if (Math.abs(x2 - x1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - p2.setXY(x1, y2); - return 1; //vertical - } else if (Math.abs(y2 - y1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - p2.setXY(x2, y1); - return 2; //horizonal - } else { - return 0; - } - - } - + /** + * Adds a perpendicular foot from a point to a line. + * + * @param line the line to which the perpendicular foot is added + * @param p1 the point from which the perpendicular foot is drawn + * @param p the perpendicular foot point + */ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { CLine line1 = new CLine(p1, p); -// constraint c1 = new constraint(constraint.PONLINE, p, line, false); -// constraint c2 = new constraint(constraint.PONLINE, p, line1, false); CPoint[] pl = line.getTowSideOfLine(); Constraint cs = null; if (pl != null) { @@ -6053,17 +6491,12 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { if (pu == null) { this.addPointToList(p); addLineToList(line1); -// this.addConstraintToList(c1); -// this.addConstraintToList(c2); this.addConstraintToList(cs); this.AddPointToLineX(p, line); -// line.addApoint(p); addCTMark(line, line1); - // this.addObjectToList(m, otherlist); line1.addconstraint(cs); this.UndoAdded(line1.getSimpleName() + " perp " + line.getSimpleName() + - // " with foot " + p.m_name); " " + GExpert.getTranslationViaGettext("with foot {0}", p.m_name)); } else { @@ -6076,10 +6509,7 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { if (pu == null) { this.addPointToList(p); addLineToList(line1); -// this.addConstraintToList(c1); -// this.addConstraintToList(c2); addCTMark(line, line1); - // this.addObjectToList(m, otherlist); this.AddPointToLineX(p, line); this.addConstraintToList(cs); line1.addconstraint(cs); @@ -6087,11 +6517,15 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { line.getSimpleName() + " with footy " + p.m_name); } } - } + /** + * Translates all points and text objects by the given delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ private void translate(double dx, double dy) { - if (isFrozen()) return; @@ -6102,16 +6536,18 @@ private void translate(double dx, double dy) { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); t.move(dx, dy); - } this.reCalculate(); - - } - - private void smartFreePointMoved(CPoint pt) { - } + /** + * Updates the location of objects in the list based on the new coordinates. + * + * @param list the list of objects to update + * @param old the old point + * @param x the new x-coordinate + * @param y the new y-coordinate + */ private void ObjectLocationChanged(Vector list, CPoint old, double x, double y) { double x0 = FirstPnt.getx(); double y0 = FirstPnt.gety(); @@ -6181,13 +6617,19 @@ private void ObjectLocationChanged(Vector list, CPoint old, double x, double y) if (isFrozen()) return; - for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); p.setXY(p.getx() + dx, p.gety() + dy); } } + /** + * Updates the location of a circle and its points based on the given delta values. + * + * @param c the circle to update + * @param dx the delta x value + * @param dy the delta y value + */ private void circleLocationChanged(Circle c, double dx, double dy) { Circle c1 = (Circle) c; CPoint p1 = c1.o; @@ -6197,6 +6639,13 @@ private void circleLocationChanged(Circle c, double dx, double dy) { return; } + /** + * Moves all objects in the list by the given delta values. + * + * @param list the list of objects to move + * @param dx the delta x value + * @param dy the delta y value + */ public void objectsListMoved(Vector list, double dx, double dy) { for (int i = 0; i < list.size(); i++) { CClass c = (CClass) list.get(i); @@ -6209,10 +6658,15 @@ public void objectsListMoved(Vector list, double dx, double dy) { break; } } - - } + /** + * This method is used to move the catch point to the nearest point on the + * object. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseMove(double x, double y) { if (SNAP && CurrentAction != SELECT) { double[] r = getSnap(x, y); @@ -6398,6 +6852,12 @@ public void DWMouseMove(double x, double y) { } + /** + * Moves the catch point to the specified coordinates if a point is found at those coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatchPt(double x, double y) { CPoint pt = this.SelectAPoint(x, y); CatchList.clear(); @@ -6408,6 +6868,12 @@ public void SmartmoveCatchPt(double x, double y) { } } + /** + * Moves the catch point to the specified coordinates if a line is found at those coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatchLine(double x, double y) { CLine pt = this.SelectALine(x, y); CatchList.clear(); @@ -6418,12 +6884,24 @@ public void SmartmoveCatchLine(double x, double y) { } } + /** + * Moves the catch point to the specified coordinates, considering all types of objects. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatch(double x, double y) { SmartmoveCatch(x, y, 0); } - public void SmartmoveCatch(double x, double y, int type) { // 0. All. 1. Point Only. - // 2. Line Only . 3. Circle Only. 4. P and L 5. P and C . 6. L and C. + /** + * Moves the catch point to the specified coordinates, considering specific types of objects. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param type the type of objects to consider (0: All, 1: Point Only, 2: Line Only, 3: Circle Only, 4: Point and Line, 5: Point and Circle, 6: Line and Circle) + */ + public void SmartmoveCatch(double x, double y, int type) { CatchList.clear(); CatchType = 0; SelectAllFromXY(CatchList, x, y, 1); @@ -6462,7 +6940,12 @@ public void SmartmoveCatch(double x, double y, int type) { // 0. All. 1. Point mouseCatchY = (int) CatchPoint.gety(); } - + /** + * Moves the catch point to the specified coordinates, considering points, lines, and circles. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void moveCatch(double x, double y) { int n = CatchList.size(); CatchList.clear(); @@ -6480,6 +6963,12 @@ public void moveCatch(double x, double y) { panel.repaint(); } + /** + * Finds the intersection point of two objects (lines or circles) in the catch list. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void get_Catch_Intersection(double x, double y) { int k = 0; CLine ln = null; @@ -6534,7 +7023,15 @@ else if (o2 == null) } } - public boolean Smart(CPoint p, double x, double y) { // set p to a point on obj and near x,y + /** + * Sets the given point to the specified coordinates and checks if it is on any geometric object. + * + * @param p the point to set + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the point is on an object, false otherwise + */ + public boolean Smart(CPoint p, double x, double y) { p.setXY(x, y); CPoint pt = SmartPoint(p); if (pt != null) { @@ -6551,12 +7048,18 @@ public boolean Smart(CPoint p, double x, double y) { // set p to a point on obj return false; } - public CPoint SmartAddPoint(double x, double y) { // add a new point to drawing with x,y + /** + * Adds a new point to the drawing at the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the created point, or an existing point if one is found at the coordinates + */ + public CPoint SmartAddPoint(double x, double y) { CPoint pt = SelectAPoint(x, y); if (pt != null) return pt; - Vector v = new Vector(); SelectFromAList(v, linelist, x, y); SelectFromAList(v, circlelist, x, y); @@ -6584,12 +7087,19 @@ public CPoint SmartAddPoint(double x, double y) { // add a new point to drawing return p; } - public CPoint SmartAddPoint(double x, double y, String name) { // add a new point to drawing with x,y + /** + * Adds a new point to the drawing at the specified coordinates with a given name. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param name the name of the new point + * @return the created point, or an existing point if one is found at the coordinates + */ + public CPoint SmartAddPoint(double x, double y, String name) { CPoint pt = SelectAPoint(x, y); if (pt != null) return pt; - Vector v = new Vector(); SelectFromAList(v, linelist, x, y); SelectFromAList(v, circlelist, x, y); @@ -6617,27 +7127,24 @@ public CPoint SmartAddPoint(double x, double y, String name) { // add a new poin return p; } - public Object SmartPointOnWhich(CPoint p) { - CPoint pt = SmartPoint(p); - if (pt != null) { - return pt; - } - CLine line = SmartPLine(p); - if (line != null) { - return line; - } - Circle c = SmartPCircle(p); - if (c != null) { - return c; - } - return null; - } - - + /** + * Selects a line from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected line, or null if no line is found + */ public CLine SelectALine(double x, double y) { return SmartPointOnLine(x, y); } + /** + * Selects a circle from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected circle, or null if no circle is found + */ public Circle SelectACircle(double x, double y) { for (int i = 0; i < circlelist.size(); i++) { Circle c = (Circle) circlelist.get(i); @@ -6648,6 +7155,13 @@ public Circle SelectACircle(double x, double y) { return null; } + /** + * Selects a point from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected point, or null if no point is found + */ public CPoint SelectAPoint(double x, double y) { CPoint pt = null; for (int i = 0; i < pointlist.size(); i++) { @@ -6660,24 +7174,9 @@ public CPoint SelectAPoint(double x, double y) { return pt; } - - public void clearFlashAndAdd(Vector v) { - clearFlash(); - flashlist.addAll(v); - } - - public void clear_but_angle() { - for (int i = 0; i < flashlist.size(); i++) { - JFlash ff = (JFlash) flashlist.get(i); - if (ff instanceof JAngleFlash) { - continue; - } - ff.stop(); - flashlist.remove(i); - i--; - } - } - + /** + * Starts and stops the flashing process for flash items in the flash list. + */ public void doFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash ff = (JFlash) flashlist.get(i); @@ -6692,6 +7191,9 @@ public void doFlash() { } } + /** + * Clears all flash items from the flash list. + */ public void clearFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash ff = (JFlash) flashlist.get(i); @@ -6700,6 +7202,11 @@ public void clearFlash() { flashlist.clear(); } + /** + * Adds a flash item to the flash list and starts it. + * + * @param f the flash item to add + */ public void addFlash(JFlash f) { if (f == null) return; @@ -6709,6 +7216,15 @@ public void addFlash(JFlash f) { f.start(); } + /** + * Finds the common point between two lines or a line and a point. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the common point if found, otherwise null + */ public CPoint getCommonPoint(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { CLine ln1 = this.fd_line(p1, p2); CLine ln2 = this.fd_line(p3, p4); @@ -6749,9 +7265,15 @@ public CPoint getCommonPoint(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { } } return null; - } + /** + * Adds two JCgFlash items and a JFlash item to the flash list. + * + * @param f1 the first JCgFlash item + * @param f2 the second JCgFlash item + * @param f the JFlash item + */ public void addCgFlash(JCgFlash f1, JCgFlash f2, JFlash f) { int size = flashlist.size(); int n = 0; @@ -6789,10 +7311,9 @@ public void addCgFlash(JCgFlash f1, JCgFlash f2, JFlash f) { addFlashx(f2); } - public boolean isInAction() { - return STATUS != 0 || SelectList.size() != 0; - } - + /** + * Starts the flashing process for flash items in the flash list. + */ public void startFlash() { for (int j = 0; j < flashlist.size(); j++) { JFlash fx = (JFlash) flashlist.get(j); @@ -6805,6 +7326,11 @@ public void startFlash() { } } + /** + * Adds the specified flash object before any existing JRedoStepFlash in the flash list. + * + * @param f the flash object to add + */ public void addFlash2(JFlash f) { for (int i = 0; i < flashlist.size(); i++) { if (flashlist.get(i) instanceof JRedoStepFlash) { @@ -6815,6 +7341,11 @@ public void addFlash2(JFlash f) { addFlash1(f); } + /** + * Adds the specified flash object and starts it immediately if it is the only flash item. + * + * @param f the flash object to add + */ public void addFlash1(JFlash f) { addFlashx(f); @@ -6822,6 +7353,12 @@ public void addFlash1(JFlash f) { f.start(); } + /** + * Adds the specified flash object to the flash list if not already present. + * For JAngleFlash instances, adjusts the flash radius based on the number of similar flash objects. + * + * @param f the flash object to add + */ public void addFlashx(JFlash f) { if (f == null) return; @@ -6850,6 +7387,11 @@ public void addFlashx(JFlash f) { flashlist.add(f); } + /** + * Checks whether the flash process is finished. + * + * @return {@code true} if there are no flash items or the sole flash item has finished; {@code false} otherwise + */ public boolean isFlashFinished() { int n = flashlist.size(); if (n == 0) return true; @@ -6859,6 +7401,12 @@ public boolean isFlashFinished() { } + /** + * Draws all flash items to the provided Graphics2D object, starts flash processes if necessary, + * and triggers a proof run when all flashes are finished. + * + * @param g2 the graphics context used for drawing + */ public void drawFlash(Graphics2D g2) { if (flashlist.size() == 0) return; @@ -6891,6 +7439,12 @@ public void drawFlash(Graphics2D g2) { } } + /** + * Paints the current drawing scene including grid, undo objects, various shape lists, flashes, + * points, texts, and catch objects. Also draws additional components such as the track point. + * + * @param g the graphics context used for painting + */ public void paintPoint(Graphics g) { Graphics2D g2 = (Graphics2D) g; @@ -6927,6 +7481,11 @@ public void paintPoint(Graphics g) { drawTrackpt(g2); } + /** + * Draws the tracking point on the given Graphics2D context and adds it to the corresponding trace list. + * + * @param g2 the graphics context used for drawing + */ public void drawTrackpt(Graphics2D g2) { if (CTrackPt == null) return; @@ -6941,6 +7500,12 @@ public void drawTrackpt(Graphics2D g2) { } } + /** + * Returns the trace object that contains the current tracking point. + * + * @param pt the point used to identify the corresponding trace + * @return the matching CTrace if found; otherwise, {@code null} + */ public CTrace getTraceByPt(CPoint pt) { for (int i = 0; i < tracelist.size(); i++) { CTrace tr = (CTrace) tracelist.get(i); @@ -6950,6 +7515,12 @@ public CTrace getTraceByPt(CPoint pt) { return null; } + /** + * Adjusts the position of point p2 relative to point p1 to enforce a smart horizontal or vertical alignment. + * + * @param p1 the reference point + * @param p2 the point to be adjusted + */ public void setSmartPVLine(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return; @@ -6972,6 +7543,14 @@ public void setSmartPVLine(CPoint p1, CPoint p2) { } + /** + * Draws a smart PV (parallel or vertical/horizontal) line between p1 and p2. + * If the line is nearly horizontal or vertical and sufficiently long, the line is extended accordingly. + * + * @param p1 the starting point of the line + * @param p2 the target point for alignment and extension + * @param g2 the graphics context used for drawing + */ public void drawSmartPVLine(CPoint p1, CPoint p2, Graphics2D g2) { int x, y; x = y = 0; @@ -7017,6 +7596,12 @@ public void drawSmartPVLine(CPoint p1, CPoint p2, Graphics2D g2) { g2.drawLine((int) p1.getx(), (int) p1.gety(), x, y); } + /** + * Draws the current action environment including auxiliary lines, selection outlines, + * and other drawing components based on the current action state. + * + * @param g2 the graphics context used for drawing + */ public void drawCurrentAct(Graphics2D g2) { // if (trackPoint != null) { @@ -7717,7 +8302,12 @@ public void drawCurrentAct(Graphics2D g2) { drawCatchObjName(g2); } - + /** + * Sets the first point for transformation and updates the translation offsets. + * + * @param x the new x-coordinate + * @param y the new y-coordinate + */ public void setFirstPnt(double x, double y) { if (FirstPnt != null) { vtrx = x - FirstPnt.getx(); @@ -7725,6 +8315,15 @@ public void setFirstPnt(double x, double y) { } } + /** + * Sets the transformation status and updates related points and selections. + * + *
When t is 0, the selection is cleared.
+ * When t is 2, the first point's coordinates are updated based on current catch values
+ * and a repaint is requested.
+ * This method generates a name starting with "O", and appends a number + * if necessary to ensure uniqueness among the existing points. + * + * @return the generated circle center name + */ String get_cir_center_name() { int k = 0; while (true) { @@ -10277,27 +11244,14 @@ String get_cir_center_name() { else return "O" + k; } - - public void add_to_undolist(UndoStruct u) { - if (!undolist.contains(u)) - undolist.add(u); - - } - - public void remove_from_undolist(UndoStruct u) { - undolist.remove(u); - } - - public void add_to_redolist(UndoStruct u) { - if (!redolist.contains(u)) - redolist.add(u); - - } - - public void remove_from_redolist(UndoStruct u) { - redolist.remove(u); - } - + /** + * Checks if the current state needs to be saved. + *
+ * The state is considered modified if there are points, text objects, + * other elements, or more than one parameter. + * + * @return true if there are unsaved changes, false otherwise + */ public boolean need_save() { return pointlist.size() > 0 || textlist.size() > 0 @@ -10305,8 +11259,15 @@ public boolean need_save() { || paraCounter > 1; } -////////////////////////////////////////////////////////////////////////////////// - + /** + * Finds a polygon associated with the given circle. + *
+ * The method searches through the polygon list for a polygon of a specific type + * that matches the circle's properties. + * + * @param c the circle to search for the corresponding polygon + * @return the found polygon or null if none match + */ public CPolygon fd_polygon(Circle c) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon cp = (CPolygon) polygonlist.get(i); @@ -10324,13 +11285,28 @@ public CPolygon fd_polygon(Circle c) { return null; } -///////////////////////////////////////////////////////////////////// - + /** + * Reduces a given TMono object using the current parameters. + *
+ * This method creates a copy of the input TMono and applies reduction + * based on the available parameters. + * + * @param m the TMono object to reduce + * @return the reduced TMono object + */ public TMono reduce(TMono m) { PolyBasic basic = GeoPoly.getInstance(); return basic.reduce(basic.p_copy(m), parameter); } + /** + * Handles double-click events on a CClass object. + *
+ * Depending on the type of the object, this method either opens an editor + * or performs a view action. + * + * @param c the CClass object that was double-clicked + */ public void onDBClick(CClass c) { if (c == null) return; @@ -10356,6 +11332,13 @@ public void onDBClick(CClass c) { } + /** + * Rounds a double value to a specified number of decimal places. + * + * @param r the value to round + * @param n the number of decimal places + * @return the rounded value + */ public double roundn(double r, int n) { if (n <= 0) return r; @@ -10369,6 +11352,15 @@ public double roundn(double r, int n) { return (int) (r * k) / k; } + /** + * Calculates the numerical value of a given CTextValue expression. + *
+ * This method evaluates the expression represented by the CTextValue object + * using basic arithmetic operations and mathematical functions. + * + * @param ct the CTextValue object representing the expression + * @return the calculated numerical value + */ public double calculate(CTextValue ct) { if (ct == null) return 0.0; @@ -10411,6 +11403,14 @@ public double calculate(CTextValue ct) { } + /** + * Retrieves a CTextValue parameter by its name. + *
+ * Searches the text list for a text element with a value type that matches the given name. + * + * @param s the name of the parameter to find + * @return the corresponding CTextValue if found; otherwise, null + */ CTextValue fd_para(String s) { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); @@ -10420,7 +11420,14 @@ CTextValue fd_para(String s) { return null; } - + /** + * Adds a calculation for the X-coordinate of a point. + *
+ * This method creates a text representation of the X-coordinate + * calculation for the provided point. + * + * @param p the point for which the X-coordinate calculation is added + */ final public void addCalculationPX(CPoint p) { if (p == null) return; @@ -10437,6 +11444,14 @@ final public void addCalculationPX(CPoint p) { } + /** + * Adds a calculation for the Y-coordinate of a point. + *
+ * This method creates a text representation of the Y-coordinate + * calculation for the provided point. + * + * @param p the point for which the Y-coordinate calculation is added + */ final public void addCalculationPY(CPoint p) { if (p == null) return; @@ -10452,6 +11467,13 @@ final public void addCalculationPY(CPoint p) { addText(tx); } + /** + * Adds a polygon calculation displaying its area. + *
+ * Constructs a text object representing the area calculation for the provided polygon. + * + * @param poly the polygon for which the area calculation is added + */ final public void addCalculationPolygon(CPolygon poly) { if (poly == null) return; @@ -10473,6 +11495,14 @@ final public void addCalculationPolygon(CPolygon poly) { addText(tx); } + /** + * Adds a calculation for the slope of a line. + *
+ * This method creates a text representation of the slope calculation + * for the given line based on its two supporting points. + * + * @param ln the line for which the slope calculation is added + */ final public void addLineSlope(CLine ln) { if (ln == null) return; @@ -10496,6 +11526,15 @@ final public void addLineSlope(CLine ln) { addText(tx); } + /** + * Adds a calculation for a circle based on the specified type. + *
+ * Depending on the type parameter, the method adds a text representation for
+ * the area, girth, or radius calculation of the circle.
+ *
+ * @param c the circle for which the calculation is added
+ * @param t the type of calculation (0 for area, 1 for girth, other for radius)
+ */
final public void addCalculationCircle(Circle c, int t) {
if (c == null)
return;
@@ -10531,6 +11570,12 @@ final public void addCalculationCircle(Circle c, int t) {
addText(tx);
}
+ /**
+ * Determines the location for a text object.
+ * Calculates an appropriate position for the text object based on existing text objects.
+ *
+ * @param t1 the text object for which the location is determined
+ */
public void getTextLocation(CText t1) {
int n = 0;
int n1 = 5;
@@ -10544,9 +11589,11 @@ public void getTextLocation(CText t1) {
t1.setXY(n1, n);
}
- public void flashAllNonVisibleObjects() {
- }
-
+ /**
+ * Cancels the current action and resets relevant states.
+ * This method clears selections, resets action-related variables,
+ * repaints the panel, and performs undo operations if necessary.
+ */
public void cancelCurrentAction() {
int type = CurrentAction;
@@ -10574,21 +11621,12 @@ public void cancelCurrentAction() {
this.Undo_stepPure();
}
-
- public void hightlightAllInvisibleObject() {
- Vector v = this.getAllSolidObj();
- for (int i = 0; i < v.size(); i++) {
- CClass c = (CClass) v.get(i);
- if (c == null || c.visible()) {
- v.remove(i);
- i--;
- }
- }
- SelectList.clear();
- SelectList.addAll(v);
- }
-
-
+ /**
+ * Returns the action type based on the given action code.
+ *
+ * @param ac the action code
+ * @return an integer representing the action type, or -1 if not recognized
+ */
public int getActionType(int ac) //-1. ByPass Action; 0. defalut;
// 1. Draw Action + point; 2: draw action line + circle
// 3: fill action 4: angle 5: move/select/intersect
@@ -10701,6 +11739,12 @@ public void hightlightAllInvisibleObject() {
return -1;
}
+ /**
+ * Adds a perpendicularity mark between two given lines if they are perpendicular.
+ *
+ * @param ln1 the first line
+ * @param ln2 the second line
+ */
public void addCTMark(CLine ln1, CLine ln2) {
if (ln1 == null || ln2 == null)
return;
@@ -10713,11 +11757,23 @@ public void addCTMark(CLine ln1, CLine ln2) {
this.otherlist.add(m);
}
+ /**
+ * Adds a perpendicularity mark by deriving lines from two pairs of points.
+ *
+ * @param p1 the first point of the first line
+ * @param p2 the second point of the first line
+ * @param p3 the first point of the second line
+ * @param p4 the second point of the second line
+ */
public void addCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) {
addCTMark(fd_line(p1, p2), fd_line(p3, p4));
}
-
+ /**
+ * Translates the polygon's points and creates corresponding oriented segments.
+ *
+ * @param poly the polygon whose points are to be transformed
+ */
public void PolygonTransPointsCreated(CPolygon poly) {
CPoint pt0, pt1;
pt0 = pt1 = null;
@@ -10767,6 +11823,15 @@ public void PolygonTransPointsCreated(CPolygon poly) {
}
}
+ /**
+ * Creates a new oriented segment for a given point and its transformed coordinates.
+ *
+ * @param p1 the first reference point
+ * @param p2 the second reference point
+ * @param px the original point for segment generation
+ * @param x the transformed x-coordinate
+ * @param y the transformed y-coordinate
+ */
public void addOrientedSegment(CPoint p1, CPoint p2, CPoint px, double x, double y) {
CPoint p = this.CreateANewPoint(x, y);
@@ -10778,522 +11843,16 @@ public void addOrientedSegment(CPoint p1, CPoint p2, CPoint px, double x, double
}
}
- public void setTextPositionAutomatically(CText tex) {
- if (tex.getType() != CText.NAME_TEXT)
- return;
-
- Point o = tex.getLocation();
- double w = tex.w;
- double h = tex.height;
- double r = 15;
-
- CClass c = tex.father;
- if (c != null && c.get_type() == CClass.POINT) {
- CPoint px = (CPoint) c;
- double x = tex.getX();
- double y = tex.getY();
- double dx = x;//- px.getx();
- double dy = y;//- px.gety();
- double dpi = Math.PI / 16;
- boolean bfound = false;
- double sx, sy;
- sx = sy = 0;
- for (int i = 0; i < 16; i++) {
- if (bfound)
- break;
- double sta = i * dpi;
- for (int j = 0; j < 2; j++) {
- sx = dx * Math.cos(sta) - dy * Math.sin(sta);
- sy = dx * Math.sin(sta) + dy * Math.cos(sta);
- if (!intsWithCircle(sx + px.getx(), sy + px.gety(), r)) {
- bfound = true;
- break;
- }
- if (bfound)
- break;
- sta *= -1;
- }
- }
- if (bfound) {
- tex.setXY((int) (sx), (int) (sy));
- }
- }
-
- }
-
- public boolean intsWithCircle(double ptx, double pty, double r) {
-
- boolean bat = false;
- int size = pointlist.size();
- for (int i = 0; i < size - 1; i++) {
- CPoint p = (CPoint) pointlist.get(i);
- double ds = Math.pow(p.getx() - ptx, 2) + Math.pow(p.gety() - pty, 2);
- ds = Math.sqrt(ds);
- if (ds < r) {
- return true;
- }
- }
-
- size = linelist.size();
- for (int i = 0; i < size; i++) {
- CLine ln = (CLine) linelist.get(i);
- double d = ln.distance(ptx, pty);
- if (d < r) {
- if (ln.isOnMiddle(ptx, pty))
- return true;
- }
- }
- size = circlelist.size();
- for (int i = 0; i < size; i++) {
- Circle c = (Circle) circlelist.get(i);
- double d = Math.sqrt(Math.pow(c.o.getx() - ptx, 2) + Math.pow(c.o.gety() - pty, 2));
- if (Math.abs(d - c.getRadius()) < r)
- return true;
- }
- return false;
- }
-
- public boolean LoadGGB(DataInputStream in, String path) throws IOException {
- // Reset everything in the current construction
- clearAll();
- double version = 0.053; // Current gex file version for JGEX 0.8 is 0.053
- CMisc.version_load_now = version;
-
- // Need to make type ArrayList because JGEX uses java.awt.List as well
- ArrayList This method examines the type of the provided construction object and executes the corresponding
+ * logic to update the constraint and geometric element lists. Depending on the provided parameters,
+ * it adds points, lines, circles, angles, or other entities and registers constraints related to them.
+ * This method examines the type of the provided MAssertion and
+ * displays the corresponding flash pattern based on the assertion type.
+ * It supports various assertion types such as collinearity, parallelism,
+ * equality of distances, perpendicularity, cyclic configurations, angle equality,
+ * midpoint conditions, congruency, triangle properties, and several others.
+ *