All files / web/src/components/toys/euclid/propositions prop1.ts

100% Statements 301/301
90% Branches 18/20
100% Functions 2/2
100% Lines 301/301

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 3021x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import type {
  PropositionDef,
  ConstructionElement,
  TutorialSubStep,
  EuclidNarrationOptions,
} from '../types'
import type { KidLanguageStyle } from '@/db/schema/player-session-preferences'
import { BYRNE } from '../types'
import { deriveSteps } from '../engine/recipe/deriveSteps'
import { RECIPE_PROP_1, PROP_1_ANNOTATIONS } from '../engine/recipe/definitions/prop1'
 
const DEFAULT_LANGUAGE_STYLE: KidLanguageStyle = 'standard'
 
const PROP_1_STEP_INSTRUCTIONS: Record<KidLanguageStyle, string[]> = {
  simple: [
    'Draw a circle with center {pt:A} through {pt:B}',
    'Draw a circle with center {pt:B} through {pt:A}',
    'Mark where the circles cross',
    'Draw a line from {pt:C} to {pt:A}',
    'Draw a line from {pt:C} to {pt:B}',
  ],
  standard: [
    'Draw a circle centered at {pt:A} through {pt:B}',
    'Draw a circle centered at {pt:B} through {pt:A}',
    'Mark the point where the circles meet',
    'Draw a line from {pt:C} to {pt:A}',
    'Draw a line from {pt:C} to {pt:B}',
  ],
  classical: [
    'Describe a circle with center {pt:A} and radius {seg:AB}',
    'Describe a circle with center {pt:B} and radius {seg:BA}',
    'Mark where the circles cut one another',
    'Join {pt:C} to {pt:A}',
    'Join {pt:C} to {pt:B}',
  ],
}
 
function getProp1Tutorial(isTouch: boolean, options?: EuclidNarrationOptions): TutorialSubStep[][] {
  const style = options?.languageStyle ?? DEFAULT_LANGUAGE_STYLE
  const tapHold = isTouch ? 'Tap and hold' : 'Click and hold'
  const drag = isTouch ? 'Drag' : 'Drag'
  const sweep = isTouch ? 'Sweep your finger' : 'Move your mouse'
  const tap = isTouch ? 'Tap' : 'Click'
  const byStyle = (copy: Record<KidLanguageStyle, string>) => copy[style] ?? copy.standard
 
  return [
    // ── Step 0: Circle centered at A through B ──
    [
      {
        instruction: `${tapHold} point {pt:A}`,
        speech: isTouch
          ? byStyle({
              simple:
                'Postulate 3 lets us draw a circle from any center with any radius. Press and hold on A to choose the center.',
              standard:
                'Postulate 3 says we may describe a circle with any center and radius. Press and hold on A to set the center.',
              classical:
                'By Postulate 3, describe a circle with any center and radius. Take A as the center.',
            })
          : byStyle({
              simple:
                'Postulate 3 lets us draw a circle from any center with any radius. Click and hold on A to choose the center.',
              standard:
                'Postulate 3 says we may describe a circle with any center and radius. Click and hold on A to set the center.',
              classical:
                'By Postulate 3, describe a circle with any center and radius. Take A as the center.',
            }),
        hint: { type: 'point', pointId: 'pt-A' },
        advanceOn: { kind: 'compass-phase', phase: 'center-set' },
      },
      {
        instruction: `${drag} to point {pt:B}`,
        speech: byStyle({
          simple: 'Drag to B to set the radius. Every point on this circle is AB away from A.',
          standard:
            'Drag to B to set the radius. Every point on this circle will be exactly AB away from A.',
          classical:
            'Drag to B to set the radius AB. Every point on the circle is at a distance AB from A.',
        }),
        hint: { type: 'arrow', fromId: 'pt-A', toId: 'pt-B' },
        advanceOn: { kind: 'compass-phase', phase: 'radius-set' },
      },
      {
        instruction: `${sweep} all the way around`,
        speech: isTouch
          ? byStyle({
              simple: 'Sweep around to draw the circle centered at A.',
              standard: 'Sweep all the way around to draw the circle centered at A with radius AB.',
              classical: 'Carry the circle around until it is complete.',
            })
          : byStyle({
              simple: 'Move around to draw the circle centered at A.',
              standard: 'Move all the way around to draw the circle centered at A with radius AB.',
              classical: 'Carry the circle around until it is complete.',
            }),
        hint: { type: 'sweep', centerId: 'pt-A', radiusPointId: 'pt-B' },
        advanceOn: null,
      },
    ],
    // ── Step 1: Circle centered at B through A ──
    [
      {
        instruction: `${tapHold} point {pt:B}`,
        speech: isTouch
          ? byStyle({
              simple: 'Now do the same with center B. Press and hold on B.',
              standard: 'Now do the same with center B. Press and hold on B.',
              classical: 'Again, take B as the center.',
            })
          : byStyle({
              simple: 'Now do the same with center B. Click and hold on B.',
              standard: 'Now do the same with center B. Click and hold on B.',
              classical: 'Again, take B as the center.',
            }),
        hint: { type: 'point', pointId: 'pt-B' },
        advanceOn: { kind: 'compass-phase', phase: 'center-set' },
      },
      {
        instruction: `${drag} to point {pt:A}`,
        speech: byStyle({
          simple: 'Drag to A to set the radius BA. Every point on this circle is BA away from B.',
          standard:
            'Drag to A to make the radius BA. Every point on this circle is BA away from B.',
          classical:
            'Drag to A so the radius is BA. Every point on this circle is at distance BA from B.',
        }),
        hint: { type: 'arrow', fromId: 'pt-B', toId: 'pt-A' },
        advanceOn: { kind: 'compass-phase', phase: 'radius-set' },
      },
      {
        instruction: `${sweep} around again`,
        speech: isTouch
          ? byStyle({
              simple: 'Sweep around to draw the second circle.',
              standard: 'Sweep all the way around to draw the second circle.',
              classical: 'Carry the circle around again.',
            })
          : byStyle({
              simple: 'Move around to draw the second circle.',
              standard: 'Move all the way around to draw the second circle.',
              classical: 'Carry the circle around again.',
            }),
        hint: { type: 'sweep', centerId: 'pt-B', radiusPointId: 'pt-A' },
        advanceOn: null,
      },
    ],
    // ── Step 2: Mark intersection ──
    [
      {
        instruction: `${tap} where the circles cross`,
        speech: byStyle({
          simple: 'Tap where the circles cross. That point is the same distance from A and from B.',
          standard:
            'Mark a point where the circles meet. That point is on both circles, so it is the same distance from A as from B.',
          classical:
            'Mark one of the points where the circles cut one another; it lies on both circles and is equidistant from A and B.',
        }),
        hint: { type: 'candidates' },
        advanceOn: null,
      },
    ],
    // ── Step 3: Segment C → A ──
    [
      {
        instruction: `${drag} from {pt:C} to {pt:A}`,
        speech: byStyle({
          simple:
            'Postulate 1 lets us draw a straight line from any point to any point. Draw the line from C to A.',
          standard:
            'Postulate 1 lets us draw a straight line from any point to any point. Draw the line from C to A.',
          classical: 'By Postulate 1, join C to A.',
        }),
        hint: { type: 'arrow', fromId: 'pt-C', toId: 'pt-A' },
        advanceOn: null,
      },
    ],
    // ── Step 4: Segment C → B ──
    [
      {
        instruction: `${drag} from {pt:C} to {pt:B}`,
        speech: byStyle({
          simple:
            'Draw the line from C to B. Now CA = AB and CB = AB, so all three sides are equal.',
          standard:
            'Draw the line from C to B. Now CA = AB and CB = AB, so the triangle is equilateral.',
          classical:
            'Join C to B. Since CA equals AB and CB equals AB, the triangle is equilateral.',
        }),
        hint: { type: 'arrow', fromId: 'pt-C', toId: 'pt-B' },
        advanceOn: null,
      },
    ],
  ]
}
 
/**
 * Proposition I.1: On a given finite straight line to construct
 * an equilateral triangle.
 */
export const PROP_1: PropositionDef = {
  id: 1,
  title: 'Construct an equilateral triangle on a given line',
  draggablePointIds: ['pt-A', 'pt-B'],
  givenElements: [
    {
      kind: 'point',
      id: 'pt-A',
      x: -2,
      y: 0,
      label: 'A',
      color: BYRNE.given,
      origin: 'given',
    },
    {
      kind: 'point',
      id: 'pt-B',
      x: 2,
      y: 0,
      label: 'B',
      color: BYRNE.given,
      origin: 'given',
    },
    {
      kind: 'segment',
      id: 'seg-AB',
      fromId: 'pt-A',
      toId: 'pt-B',
      color: BYRNE.given,
      origin: 'given',
    },
  ] as ConstructionElement[],
  steps: deriveSteps(RECIPE_PROP_1, PROP_1_ANNOTATIONS),
  stepInstructionsByStyle: PROP_1_STEP_INSTRUCTIONS,
  // completionMessage derived from proof engine at runtime
  resultSegments: [
    { fromId: 'pt-A', toId: 'pt-C' },
    { fromId: 'pt-C', toId: 'pt-B' },
    { fromId: 'pt-A', toId: 'pt-B' },
  ],
  getTutorial: getProp1Tutorial,
  explorationNarration: {
    introSpeech:
      'You built an equilateral triangle by definition: C lies on both circles, so CA = AB and CB = AB. Drag A or B to see the logic still forces those equalities.',
    pointTips: [
      {
        pointId: 'pt-A',
        speech: 'No matter where A moves, C stays on both circles, so CA and AB remain equal.',
      },
      {
        pointId: 'pt-B',
        speech:
          'C stays the same distance from B as A is from B, so the triangle stays equilateral.',
      },
    ],
  },
  explorationNarrationByStyle: {
    simple: {
      introSpeech:
        'C is on both circles, so CA = AB and CB = AB. Drag A or B and watch the equal sides stay equal.',
      pointTips: [
        {
          pointId: 'pt-A',
          speech: 'C stays on both circles, so CA always matches AB.',
        },
        {
          pointId: 'pt-B',
          speech: 'C stays the same distance from B as A does, so the triangle stays equal.',
        },
      ],
    },
    standard: {
      introSpeech:
        'You built an equilateral triangle by definition: C lies on both circles, so CA = AB and CB = AB. Drag A or B to see the logic still forces those equalities.',
      pointTips: [
        {
          pointId: 'pt-A',
          speech: 'No matter where A moves, C stays on both circles, so CA and AB remain equal.',
        },
        {
          pointId: 'pt-B',
          speech:
            'C stays the same distance from B as A is from B, so the triangle stays equilateral.',
        },
      ],
    },
    classical: {
      introSpeech:
        'C lies on both circles, so CA = AB and CB = AB. Hence the triangle is equilateral. Drag A or B to see the equalities persist.',
      pointTips: [
        {
          pointId: 'pt-A',
          speech: 'Because C remains on the circle with center A, CA is always equal to AB.',
        },
        {
          pointId: 'pt-B',
          speech: 'Because C remains on the circle with center B, CB is always equal to AB.',
        },
      ],
    },
  },
}